X-Git-Url: http://git.tdb.fi/?p=pmount-gui.git;a=blobdiff_plain;f=main.c;h=ae08cbb7cda87de794b03d673e40a6de691e721e;hp=49239cf9af722127c3355b57f42c87ef2667173c;hb=f0685a14d4ffdb807c697900a2d222907fa291d3;hpb=562379b75157fd8908a86fb4620e5f906150691e diff --git a/main.c b/main.c index 49239cf..ae08cbb 100644 --- a/main.c +++ b/main.c @@ -29,6 +29,7 @@ typedef struct sDevice } Device; int verbosity = 0; +char *post_mount_command = NULL; /** Parses a string of the form name=value and places the components in a Property @@ -692,6 +693,7 @@ void row_activated(GtkTreeView *list, GtkTreePath *path, GtkTreeViewColumn *colu } } + close(pipe_fd[0]); if(pid) waitpid(pid, &status, 0); @@ -726,6 +728,26 @@ void row_activated(GtkTreeView *list, GtkTreePath *path, GtkTreeViewColumn *colu gtk_main_quit(); + if(post_mount_command && !umount) + { + char workdir[256]; + int len; + len = snprintf(workdir, sizeof(workdir), "/media/%s", device->label); + if(len<(int)sizeof(workdir)) + { + if(verbosity>=1) + printf("Running %s in %s\n", post_mount_command, workdir); + + pid = fork(); + if(pid==0) + { + chdir(workdir); + execlp(post_mount_command, post_mount_command, NULL); + _exit(1); + } + } + } + (void)column; } @@ -767,6 +789,18 @@ gboolean key_press(GtkWidget *widget, GdkEvent *event, gpointer user_data) return FALSE; } +void show_help(void) +{ + printf("pmount-gui\n" + "Copyright (c) 2011-2015 Mikko Rasa, Mikkosoft Productions\n\n" + "Usage: pmount-gui [-v] [-u] [-r ] [-h]\n\n" + "Options:\n" + " -v Increase verbosity\n" + " -u Unmount a device (default is mount)\n" + " -r Run a command after mounting\n" + " -h Display this help\n"); +} + int main(int argc, char **argv) { GtkWidget *window; @@ -786,7 +820,7 @@ int main(int argc, char **argv) gtk_init(&argc, &argv); - while((opt = getopt(argc, argv, "vu"))!=-1) switch(opt) + while((opt = getopt(argc, argv, "vur:h"))!=-1) switch(opt) { case 'v': ++verbosity; @@ -794,6 +828,12 @@ int main(int argc, char **argv) case 'u': umount = 1; break; + case 'r': + post_mount_command = optarg; + break; + case 'h': + show_help(); + return 0; } window = gtk_window_new(GTK_WINDOW_TOPLEVEL);