Make sure waitpid is always called
authorMikko Rasa <tdb@tdb.fi>
Sun, 16 Nov 2014 16:36:32 +0000 (18:36 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sun, 16 Nov 2014 16:36:32 +0000 (18:36 +0200)
main.c

diff --git a/main.c b/main.c
index 63921300b2bf373105ae557e773295b0d74489c4..ee51767f7a81db07984d50e37cd0be650a9b1377 100644 (file)
--- a/main.c
+++ b/main.c
@@ -570,7 +570,7 @@ void row_activated(GtkTreeView *list, GtkTreePath *path, GtkTreeViewColumn *colu
                {
                        char buf[1024];
                        int pos = 0;
-                       int status;
+                       int status = 0;
                        fd_set fds;
                        struct timeval timeout;
 
@@ -592,11 +592,32 @@ void row_activated(GtkTreeView *list, GtkTreePath *path, GtkTreeViewColumn *colu
                                        pos += len;
                                }
                                else if(waitpid(pid, &status, 0))
+                               {
+                                       pid = 0;
                                        break;
+                               }
                        }
 
+                       if(pid)
+                               waitpid(pid, &status, 0);
+
                        buf[pos] = 0;
 
+                       if(verbosity>=1)
+                       {
+                               if(WIFEXITED(status))
+                               {
+                                       if(WEXITSTATUS(status))
+                                               printf("Command exited successfully\n");
+                                       else
+                                               printf("Command exited with status %d\n", WEXITSTATUS(status));
+                               }
+                               else if(WIFSIGNALED(status))
+                                       printf("Command terminated with signal %d\n", WTERMSIG(status));
+                               else
+                                       printf("Command exited with unknown result %04X\n", status);
+                       }
+
                        if(!WIFEXITED(status) || WEXITSTATUS(status))
                        {
                                GtkWidget *dialog;