X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=main.py;h=50eb24454154b216287563e1ad5c773d27bb24b9;hb=b7a524ccb662c9ed3ebd786da0f45f459929ef45;hp=2629ea283be046610565d7f02970a57fd9e18e3e;hpb=2bb6304e880b2743376bc9269af0818af9cc0f28;p=bup.git diff --git a/main.py b/main.py index 2629ea2..50eb244 100755 --- a/main.py +++ b/main.py @@ -10,6 +10,7 @@ libpath = os.path.join(exepath, 'lib') cmdpath = os.path.join(exepath, 'cmd') sys.path[:0] = [libpath] os.environ['PYTHONPATH'] = libpath + ':' + os.environ.get('PYTHONPATH', '') +os.environ['BUP_MAIN_EXE'] = os.path.abspath(exe) from bup.helpers import * @@ -92,29 +93,34 @@ def force_tty(): if fix_stdout or fix_stderr: amt = (fix_stdout and 1 or 0) + (fix_stderr and 2 or 0) os.environ['BUP_FORCE_TTY'] = str(amt) + os.setsid() # make sure ctrl-c is sent just to us, not to child too if fix_stdout or fix_stderr: realf = fix_stderr and 2 or 1 n = subprocess.Popen([subpath('newliner')], stdin=subprocess.PIPE, stdout=os.dup(realf), close_fds=True, preexec_fn=force_tty) - outf = fix_stdout and n.stdin.fileno() or 1 - errf = fix_stderr and n.stdin.fileno() or 2 + outf = fix_stdout and n.stdin.fileno() or None + errf = fix_stderr and n.stdin.fileno() or None else: n = None - outf = 1 - errf = 2 + outf = None + errf = None class SigException(Exception): - pass + def __init__(self, signum): + self.signum = signum + Exception.__init__(self, 'signal %d received' % signum) def handler(signum, frame): - raise SigException('signal %d received' % signum) + raise SigException(signum) signal.signal(signal.SIGTERM, handler) signal.signal(signal.SIGINT, handler) ret = 95 +p = None +killsig = signal.SIGTERM try: try: p = subprocess.Popen([subpath(subcmd)] + argv[2:], @@ -124,10 +130,12 @@ try: log('%s: %s\n' % (subpath(subcmd), e)) ret = 98 except SigException, e: + log('\nbup: %s\n' % e) + killsig = e.signum ret = 94 finally: if p and p.poll() == None: - os.kill(p.pid, signal.SIGTERM) + os.kill(p.pid, killsig) p.wait() if n: n.stdin.close()