diff options
author | hut <hut@lavabit.com> | 2012-08-11 05:27:56 +0200 |
---|---|---|
committer | hut <hut@lavabit.com> | 2012-08-11 05:27:56 +0200 |
commit | 969d5d290fdd0ad04d64bbbb610bf4be7a5ec73b (patch) | |
tree | 63c316401800180aeff8bd7be5c7d0d50eac760d | |
parent | 289ef51a8c104fca9dd53513957f4d909c8123c0 (diff) | |
download | ranger-969d5d290fdd0ad04d64bbbb610bf4be7a5ec73b.tar.gz |
ext.rifle: BSD-friendly setsid usage
-rwxr-xr-x | ranger/ext/rifle.py | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/ranger/ext/rifle.py b/ranger/ext/rifle.py index 1ad699bc..d5c40a0e 100755 --- a/ranger/ext/rifle.py +++ b/ranger/ext/rifle.py @@ -300,6 +300,8 @@ class Rifle(object): prefix = ['sudo', '-E', 'su', '-mc'] else: prefix = ['/bin/sh', '-c'] + + cmd = prefix + [command] if 't' in flags: if 'TERMCMD' not in os.environ: term = os.environ['TERM'] @@ -309,17 +311,22 @@ class Rifle(object): self.hook_logger("Can not determine terminal command. " "Please set $TERMCMD manually.") os.environ['TERMCMD'] = term - cmd = [os.environ['TERMCMD'], '-e'] + prefix + [command] - elif 'f' in flags: - exe = 'setsid' if 'setsid' in get_executables() else 'nohup' - cmd = [exe] + prefix + [command] - else: - cmd = prefix + [command] + cmd = [os.environ['TERMCMD'], '-e'] + cmd if 'f' in flags or 't' in flags: devnull_r = open(os.devnull, 'r') devnull_w = open(os.devnull, 'w') - p = Popen(cmd, env=self.hook_environment(os.environ), - stdin=devnull_r, stdout=devnull_w, stderr=devnull_w) + try: + pid = os.fork() + except: + # fall back to not detaching if fork() is not supported + p = Popen(cmd, env=self.hook_environment(os.environ)) + p.wait() + else: + if pid == 0: + os.setsid() + p = Popen(cmd, env=self.hook_environment(os.environ), + stdin=devnull_r, stdout=devnull_w, stderr=devnull_w) + os._exit(0) else: p = Popen(cmd, env=self.hook_environment(os.environ)) p.wait() |