]> git.tdb.fi Git - pmount-gui.git/blobdiff - main.c
Cosmetic fixes
[pmount-gui.git] / main.c
diff --git a/main.c b/main.c
index 916c2e214fce6c636c6eaf5889a012231af990eb..bed5e1bf0dd0964c69e6fa161816e6d05a9ec075 100644 (file)
--- a/main.c
+++ b/main.c
@@ -1,3 +1,5 @@
+/* Required for strdup, snprintf, getopt */
+#define _XOPEN_SOURCE 500
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
@@ -7,6 +9,7 @@
 #include <mntent.h>
 #include <sys/stat.h>
 #include <sys/wait.h>
+#include <sys/select.h>
 #include <gtk/gtk.h>
 #include <gdk/gdkkeysyms.h>
 
@@ -427,10 +430,12 @@ Device *get_devices(void)
 
        for(i=0; nodes[i]; ++i)
        {
+               Property *props;
+
                if(verbosity>=1)
                        printf("Examining device %s\n", nodes[i]);
 
-               Property *props = get_device_properties(nodes[i]);
+               props = get_device_properties(nodes[i]);
                if(!props)
                {
                        if(verbosity>=2)
@@ -565,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;
 
@@ -587,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;
@@ -603,9 +629,6 @@ void row_activated(GtkTreeView *list, GtkTreePath *path, GtkTreeViewColumn *colu
                        else
                                gtk_main_quit();
                }
-               else
-               {
-               }
        }
 
        (void)column;