Consume all arguments after arv-mount --exec, and fork subprocess
authorTom Clegg <tom@curoverse.com>
Mon, 24 Feb 2014 21:49:13 +0000 (13:49 -0800)
committerTom Clegg <tom@curoverse.com>
Mon, 24 Feb 2014 21:52:34 +0000 (13:52 -0800)
without a shell to avoid double shell expansion.

sdk/python/bin/arv-mount

index e619b5cda8f2c51886a07c456bce19b734ea1af7..2424979646b111443bbc536393fcef7adb230d56 100755 (executable)
@@ -9,11 +9,18 @@ if __name__ == '__main__':
 
     # Handle command line parameters
     parser = argparse.ArgumentParser(
-        description='Mount Keep data under the local filesystem.')
+        description='Mount Keep data under the local filesystem.',
+        epilog="""
+Note: When using the --exec feature, you must either specify the
+mountpoint before --exec, or mark the end of your --exec arguments
+with "--".
+""")
     parser.add_argument('mountpoint', type=str, help="""Mount point.""")
     parser.add_argument('--collection', type=str, help="""Collection locator""")
     parser.add_argument('--debug', action='store_true', help="""Debug mode""")
-    parser.add_argument('--exec', type=str, help="""Mount, run a command, then unmount and exit""", dest="ex")
+    parser.add_argument('--exec', type=str, nargs=argparse.REMAINDER,
+                        dest="exec_args", metavar=('command', 'args', '...', '--'),
+                        help="""Mount, run a command, then unmount and exit""")
 
     args = parser.parse_args()
 
@@ -38,7 +45,7 @@ if __name__ == '__main__':
     # Initialize the fuse connection
     llfuse.init(operations, args.mountpoint, opts)
 
-    if args.ex:
+    if args.exec_args:
         t = threading.Thread(None, lambda: llfuse.main())
         t.start()
 
@@ -46,7 +53,7 @@ if __name__ == '__main__':
         operations.initlock.wait()
 
         try:
-            rc = subprocess.call(args.ex, shell=True)
+            rc = subprocess.call(args.exec_args, shell=False)
         except:
             rc = 255
         finally: