]> git.tdb.fi Git - pmount-gui.git/blobdiff - main.c
Enable strict standards conformance and fix resulting errors
[pmount-gui.git] / main.c
diff --git a/main.c b/main.c
index 2609341f6c870eef728bd6e08f966958fa460baa..63921300b2bf373105ae557e773295b0d74489c4 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>
 
@@ -313,12 +316,15 @@ int can_mount(Property *props, char **allowed)
        static char *removable_buses[] = { "usb", "firewire", 0 };
        char *devname;
        char *devpath;
-       int i;
+       char *bus;
 
        devname = get_property_value(props, "DEVNAME");
        if(is_in_array(allowed, devname))
                return 1;
 
+       if(match_property_value(props, "ID_TYPE", "cd") && match_property_value(props, "ID_CDROM_MEDIA", "1"))
+               return 1;
+
        if(!match_property_value(props, "DEVTYPE", "partition"))
                return 0;
 
@@ -326,9 +332,9 @@ int can_mount(Property *props, char **allowed)
        if(is_removable(devpath))
                return 1;
 
-       for(i=0; removable_buses[i]; ++i)
-               if(match_property_value(props, "ID_BUS", removable_buses[i]))
-                       return 1;
+       bus = get_property_value(props, "ID_BUS");
+       if(is_in_array(removable_buses, bus))
+               return 1;
 
        return check_buses(devpath, removable_buses);
 }
@@ -424,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)
@@ -563,22 +571,32 @@ void row_activated(GtkTreeView *list, GtkTreePath *path, GtkTreeViewColumn *colu
                        char buf[1024];
                        int pos = 0;
                        int status;
+                       fd_set fds;
+                       struct timeval timeout;
 
                        close(pipe_fd[1]);
+                       FD_ZERO(&fds);
+                       FD_SET(pipe_fd[0], &fds);
+                       timeout.tv_sec = 0;
+                       timeout.tv_usec = 200000;
 
                        while(1)
                        {
-                               int len;
+                               if(select(pipe_fd[0]+1, &fds, NULL, NULL, &timeout))
+                               {
+                                       int len;
 
-                               len = read(pipe_fd[0], buf+pos, sizeof(buf)-pos-1);
-                               if(len<=0)
+                                       len = read(pipe_fd[0], buf+pos, sizeof(buf)-pos-1);
+                                       if(len<=0)
+                                               break;
+                                       pos += len;
+                               }
+                               else if(waitpid(pid, &status, 0))
                                        break;
-                               pos += len;
                        }
 
                        buf[pos] = 0;
 
-                       waitpid(pid, &status, 0);
                        if(!WIFEXITED(status) || WEXITSTATUS(status))
                        {
                                GtkWidget *dialog;