]> git.tdb.fi Git - pmount-gui.git/blobdiff - main.c
Use select when reading mount command output
[pmount-gui.git] / main.c
diff --git a/main.c b/main.c
index d1a2853c48dcb4d512cd78623893e3e449c06dd7..916c2e214fce6c636c6eaf5889a012231af990eb 100644 (file)
--- a/main.c
+++ b/main.c
@@ -319,6 +319,9 @@ int can_mount(Property *props, char **allowed)
        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;
 
@@ -563,22 +566,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;