X-Git-Url: http://git.tdb.fi/?p=pmount-gui.git;a=blobdiff_plain;f=main.c;h=ee51767f7a81db07984d50e37cd0be650a9b1377;hp=d1a2853c48dcb4d512cd78623893e3e449c06dd7;hb=1f257c6ced9b6eab932a4801899c3aa7a92e219f;hpb=15d082a3f5e39f363829d39c053c3115144e2b43 diff --git a/main.c b/main.c index d1a2853..ee51767 100644 --- a/main.c +++ b/main.c @@ -1,3 +1,5 @@ +/* Required for strdup, snprintf, getopt */ +#define _XOPEN_SOURCE 500 #include #include #include @@ -7,6 +9,7 @@ #include #include #include +#include #include #include @@ -319,6 +322,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; @@ -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) @@ -562,23 +570,54 @@ 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; 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)) + { + pid = 0; break; - pos += len; + } } + if(pid) + waitpid(pid, &status, 0); + buf[pos] = 0; - waitpid(pid, &status, 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;