]> git.tdb.fi Git - pmount-gui.git/commitdiff
Add an option to run a command after mounting
authorMikko Rasa <tdb@tdb.fi>
Sun, 9 Aug 2015 12:59:39 +0000 (15:59 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 9 Aug 2015 12:59:39 +0000 (15:59 +0300)
This can be used to e.g. open a shell or file manager in the newly-mounted
filesystem.  No arguments are currently supported.

main.c

diff --git a/main.c b/main.c
index 49239cf9af722127c3355b57f42c87ef2667173c..40b4483a87fb87810c332f4dd5228a554b737b5e 100644 (file)
--- 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;
 }
 
@@ -786,7 +808,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:"))!=-1) switch(opt)
        {
        case 'v':
                ++verbosity;
@@ -794,6 +816,9 @@ int main(int argc, char **argv)
        case 'u':
                umount = 1;
                break;
+       case 'r':
+               post_mount_command = optarg;
+               break;
        }
 
        window = gtk_window_new(GTK_WINDOW_TOPLEVEL);