~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/sftp.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-04-26 06:45:44 UTC
  • mfrom: (1684.2.2 bzr.mbp.40508)
  • Revision ID: pqm@pqm.ubuntu.com-20060426064544-35faa2d143c893a7
(mbp) #40508 ignore interrupts in ssh child

Show diffs side-by-side

added added

removed removed

Lines of Context:
65
65
register_urlparse_netloc_protocol('sftp')
66
66
 
67
67
 
 
68
def _ignore_sigint():
 
69
    # TODO: This should possibly ignore SIGHUP as well, but bzr currently
 
70
    # doesn't handle it itself.
 
71
    # <https://launchpad.net/products/bzr/+bug/41433/+index>
 
72
    import signal
 
73
    signal.signal(signal.SIGINT, signal.SIG_IGN)
 
74
    
 
75
 
68
76
def os_specific_subprocess_params():
69
77
    """Get O/S specific subprocess parameters."""
70
78
    if sys.platform == 'win32':
72
80
        # win32
73
81
        return {}
74
82
    else:
75
 
        # we close fds as the child process does not need them to be open.
76
 
        # we set the process group so that signals from the keyboard like
77
 
        # 'SIGINT' - KeyboardInterrupt - are not recieved in the child procecss
78
 
        # if we do not do this, then the sftp/ssh subprocesses will terminate 
79
 
        # when a user hits CTRL-C, and we are unable to use them to unlock the
80
 
        # remote branch/repository etc.
81
 
        return {'preexec_fn': os.setpgrp,
 
83
        # We close fds other than the pipes as the child process does not need 
 
84
        # them to be open.
 
85
        #
 
86
        # We also set the child process to ignore SIGINT.  Normally the signal
 
87
        # would be sent to every process in the foreground process group, but
 
88
        # this causes it to be seen only by bzr and not by ssh.  Python will
 
89
        # generate a KeyboardInterrupt in bzr, and we will then have a chance
 
90
        # to release locks or do other cleanup over ssh before the connection
 
91
        # goes away.  
 
92
        # <https://launchpad.net/products/bzr/+bug/5987>
 
93
        #
 
94
        # Running it in a separate process group is not good because then it
 
95
        # can't get non-echoed input of a password or passphrase.
 
96
        # <https://launchpad.net/products/bzr/+bug/40508>
 
97
        return {'preexec_fn': _ignore_sigint,
82
98
                'close_fds': True,
83
99
                }
84
100