From d62a74ae29040e350c282a98b609155c46a490f8 Mon Sep 17 00:00:00 2001 From: mdw Date: Sun, 20 Dec 1998 17:19:16 +0000 Subject: [PATCH] Return exit status of child process, rather than always returning success. --- xcatch.c | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/xcatch.c b/xcatch.c index a56112e..9a69aa1 100644 --- a/xcatch.c +++ b/xcatch.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: xcatch.c,v 1.2 1998/12/16 00:10:58 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 * @@ -29,6 +29,10 @@ /*----- 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. * @@ -70,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 ---------------------------------------------------------*/ @@ -172,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 --- */ @@ -263,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 --- */ @@ -305,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 -------------------------------------------------*/ -- 2.11.0