~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/osutils.py

  • Committer: Max Bowsher
  • Date: 2011-01-01 18:52:19 UTC
  • mto: (5594.1.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 5595.
  • Revision ID: maxb@f2s.com-20110101185219-dco685yloqzzkys8
Fix socketpair-based SSH transport leaking socket into other child processes.

This could cause bzr to hang on exit.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2376
2376
        counter += 1
2377
2377
        name = "%s.~%d~" % (base, counter)
2378
2378
    return name
 
2379
 
 
2380
 
 
2381
def set_fd_cloexec(fd):
 
2382
    """Set a Unix file descriptor's FD_CLOEXEC flag.  Do nothing if platform
 
2383
    support for this is not available.
 
2384
    """
 
2385
    try:
 
2386
        import fcntl
 
2387
        old = fcntl.fcntl(fd, fcntl.F_GETFD)
 
2388
        fcntl.fcntl(fd, fcntl.F_SETFD, old | fcntl.FD_CLOEXEC)
 
2389
    except (ImportError, AttributeError):
 
2390
        # Either the fcntl module or specific constants are not present
 
2391
        pass