Changeset 2160 for trunk


Ignore:
Timestamp:
Mar 26, 2012, 2:38:54 PM (10 years ago)
Author:
ezyang
Message:
Avoid races if /proc directory goes away
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/server/common/oursrc/fuse-better-mousetrapfs/better-mousetrapfs

    r2159 r2160  
    6464        except KeyError:
    6565            group = '%d' % gid
    66         cmdline = open('/proc/%d/cmdline' % pid).read().split('\0')[:-1]
    67         exe = os.readlink('/proc/%d/exe' % pid)
    68         status = dict(tuple(v.strip() for v in l.split(':', 1))
    69                       for l in open('/proc/%d/status' % pid).readlines())
    70         cwd = os.readlink('/proc/%d/cwd' % pid)
     66
     67        # avoid races if process goes away (not 100% sure if this is
     68        # possible; may be possible for multithreaded/async IO)
     69        olddir = os.getcwd()
     70        os.chdir("/proc/%d" % pid)
     71
     72        try:
     73            cmdline = open('cmdline').read().split('\0')[:-1]
     74            exe = os.readlink('exe')
     75            status = dict(tuple(v.strip() for v in l.split(':', 1))
     76                          for l in open('status').readlines())
     77            cwd = os.readlink('cwd')
     78        finally:
     79            os.chdir(olddir)
    7180
    7281        syslog.syslog(
Note: See TracChangeset for help on using the changeset viewer.