Return exit status of child process, rather than always returning
[xtoys] / xcatch.c
index cf9608b..9a69aa1 100644 (file)
--- a/xcatch.c
+++ b/xcatch.c
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: xcatch.c,v 1.1 1998/12/15 23:46:50 mdw Exp $
+ * $Id: xcatch.c,v 1.3 1998/12/20 17:19:16 mdw Exp $
  *
  * Catch input and trap it in an X window
  *
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: xcatch.c,v $
+ * Revision 1.3  1998/12/20 17:19:16  mdw
+ * Return exit status of child process, rather than always returning
+ * success.
+ *
+ * Revision 1.2  1998/12/16 00:10:58  mdw
+ * Fix tabbing in help text.
+ *
  * Revision 1.1  1998/12/15 23:46:50  mdw
  * New program: captures input and puts it in a window.
  *
@@ -67,8 +74,11 @@ enum {
   f_bogus = 2
 };
 
-GtkWidget *textbox = 0;
-GdkFont *font;
+static GtkWidget *textbox = 0;
+static GdkFont *font;
+
+static pid_t kid = -1;
+static int status;
 
 /*----- Main code ---------------------------------------------------------*/
 
@@ -169,8 +179,20 @@ static void ready(gpointer data, gint fd, GdkInputCondition c)
 
 static void reap(int sig)
 {
-  while (waitpid(-1, 0, WNOHANG) > 0)
-    ;
+  pid_t k;
+  int s;
+
+  for (;;) {
+    k = waitpid(-1, &s, WNOHANG);
+    if (k <= 0)
+      break;
+    if (k == kid) {
+      if (WIFEXITED(s))
+       status = WEXITSTATUS(s);
+      else
+       status = 127;
+    }
+  }
 }
 
 /* --- Main program --- */
@@ -222,8 +244,8 @@ int main(int argc, char *argv[])
 "-h, --help            Display this help text\n"
 "-u, --usage           Display a quick usage summary\n"
 "-v, --version         Display the version number\n"
-"-f, --file=FILE       Read input from the named file\n"
-"-F, --font=FONT       Display output in the named font\n",
+"-f, --file=FILE\t     Read input from the named file\n"
+"-F, --font=FONT\t     Display output in the named font\n",
           stdout);
        exit(0);
        break;
@@ -260,7 +282,6 @@ int main(int argc, char *argv[])
       fd = STDIN_FILENO;
     else {
       int pfd[2];
-      pid_t kid;
       struct sigaction sa;
 
       /* --- Set up a signal handler --- */
@@ -302,7 +323,7 @@ int main(int argc, char *argv[])
 
   gdk_input_add(fd, GDK_INPUT_READ, ready, 0);
   gtk_main();
-  return (0);
+  return (status);
 }
 
 /*----- That's all, folks -------------------------------------------------*/