commit:     0a37bd13ec85373a5a58cecaba11badf4ff6ba16
Author:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Sun Dec 13 00:47:20 2015 +0000
Commit:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Sun Dec 13 00:47:20 2015 +0000
URL:        https://gitweb.gentoo.org/proj/gentoo-keys.git/commit/?id=0a37bd13

gkeysgpg/actions.py: Recode the sign() to replace this process with the gpg call

 gkeys/gkeysgpg/actions.py | 31 ++++++++++++++++++++++++-------
 1 file changed, 24 insertions(+), 7 deletions(-)

diff --git a/gkeys/gkeysgpg/actions.py b/gkeys/gkeysgpg/actions.py
index a25e1e4..f83ce86 100644
--- a/gkeys/gkeysgpg/actions.py
+++ b/gkeys/gkeysgpg/actions.py
@@ -77,6 +77,7 @@ class Actions(ActionBase):
 
         '''
         @param args: argparse.parse_args instance
+        @params argv: original command line args
         '''
         key = None
         if args.dash: # stdin arg
@@ -155,13 +156,29 @@ class Actions(ActionBase):
         return (results.returncode, results)
 
 
-    def sign(self, args):
-        '''Sign a file'''
-        print("Made it to the --sign option :)")
-        gkeyargs = Args()
-        gkeyargs.filename = args.sign
-        gkeys = gkeyActions(self.config, self.output, self.logger)
-        return gkeys.sign(gkeyargs)
+    def sign(self, args, argv):
+        '''Sign a file using gnupg's gpg command, replacing the current 
process'''
+        cmd = ['usr/bin/gpg']
+        cmd.extend(argv)
+        for stream in (sys.__stdout__, sys.__stderr__):
+            stream.flush()
+
+        try:
+            pid = os.fork()
+            if pid == 0:
+                # A second fork is required in order to create an
+                # "orphan" process that will be reaped by init.
+                pid = os.fork()
+                if pid == 0:
+                    os.setsid()
+                os._exit(0)
+
+            os.waitpid(pid, 0)
+            os.execv(cmd[0], cmd)
+        except Exception:
+            traceback.print_exc()
+        finally:
+            os._exit(1)
 
 
     def _committer_search(self, data):

Reply via email to