~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/osutils.py

  • Committer: Vincent Ladeuil
  • Date: 2011-01-11 20:20:13 UTC
  • mfrom: (5582.6.1 bzr.dev)
  • mto: This revision was merged to the branch mainline in revision 5595.
  • Revision ID: v.ladeuil+lp@free.fr-20110111202013-s40m74cdl8vcd6re
Fix socketpair-based SSH transport leaking socket into other child processes

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2005-2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
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