/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/transport/ssh.py

  • Committer: Michael Hudson
  • Date: 2009-11-24 02:25:23 UTC
  • mto: This revision was merged to the branch mainline in revision 4822.
  • Revision ID: michael.hudson@canonical.com-20091124022523-0pism3bgkg0ip73t
final tweak

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Robey Pointer <robey@lag.net>
 
1
# Copyright (C) 2005 Robey Pointer <robey@lag.net>
2
2
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
3
3
#
4
4
# This program is free software; you can redistribute it and/or modify
173
173
register_ssh_vendor = _ssh_vendor_manager.register_vendor
174
174
 
175
175
 
176
 
def _ignore_signals():
 
176
def _ignore_sigint():
177
177
    # TODO: This should possibly ignore SIGHUP as well, but bzr currently
178
178
    # doesn't handle it itself.
179
179
    # <https://launchpad.net/products/bzr/+bug/41433/+index>
180
180
    import signal
181
181
    signal.signal(signal.SIGINT, signal.SIG_IGN)
182
 
    # GZ 2010-02-19: Perhaps make this check if breakin is installed instead
183
 
    if signal.getsignal(signal.SIGQUIT) != signal.SIG_DFL:
184
 
        signal.signal(signal.SIGQUIT, signal.SIG_IGN)
185
182
 
186
183
 
187
184
class SocketAsChannelAdapter(object):
637
634
        # Running it in a separate process group is not good because then it
638
635
        # can't get non-echoed input of a password or passphrase.
639
636
        # <https://launchpad.net/products/bzr/+bug/40508>
640
 
        return {'preexec_fn': _ignore_signals,
 
637
        return {'preexec_fn': _ignore_sigint,
641
638
                'close_fds': True,
642
639
                }
643
640
 
644
 
import weakref
645
 
_subproc_weakrefs = set()
646
 
 
647
 
def _close_ssh_proc(proc):
648
 
    for func in [proc.stdin.close, proc.stdout.close, proc.wait]:
649
 
        try:
650
 
            func()
651
 
        except OSError:
652
 
            pass
653
 
 
654
641
 
655
642
class SSHSubprocess(object):
656
643
    """A socket-like object that talks to an ssh subprocess via pipes."""
657
644
 
658
645
    def __init__(self, proc):
659
646
        self.proc = proc
660
 
        # Add a weakref to proc that will attempt to do the same as self.close
661
 
        # to avoid leaving processes lingering indefinitely.
662
 
        def terminate(ref):
663
 
            _subproc_weakrefs.remove(ref)
664
 
            _close_ssh_proc(proc)
665
 
        _subproc_weakrefs.add(weakref.ref(self, terminate))
666
647
 
667
648
    def send(self, data):
668
649
        return os.write(self.proc.stdin.fileno(), data)
671
652
        return os.read(self.proc.stdout.fileno(), count)
672
653
 
673
654
    def close(self):
674
 
        _close_ssh_proc(self.proc)
 
655
        self.proc.stdin.close()
 
656
        self.proc.stdout.close()
 
657
        self.proc.wait()
675
658
 
676
659
    def get_filelike_channels(self):
677
660
        return (self.proc.stdout, self.proc.stdin)