Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linux Process.get_open_files(): race condition + possible incorrect results #272

Closed
giampaolo opened this issue May 23, 2014 · 3 comments
Closed

Comments

@giampaolo
Copy link
Owner

From g.rodola on June 01, 2012 22:41:08

I realized there are two potential bugs in Process.get_connections() code on 
Linux: 
https://code.google.com/p/psutil/source/browse/tags/release-0.4.1/psutil/_pslinux.py#582
 @wrap_exceptions
    def get_open_files(self):
        retlist = []
        files = os.listdir("/proc/%s/fd" % self.pid)
        for fd in files:
            file = "/proc/%s/fd/%s" % (self.pid, fd)
            if os.path.islink(file):
                file = os.readlink(file)
                if file.startswith("socket:["):
                    continue
                if file.startswith("pipe:["):
                    continue
                if file == "[]":
                    continue
                if os.path.isfile(file) and not file in retlist:
                    ntuple = ntuple_openfile(file, int(fd))
                    retlist.append(ntuple)
        return retlist


At line 589 we have a race condition in case "file" disappears (os.readlink() 
fails with ENOENT which gets translated to NoSuchProcess).
At line 596, before os.path.isfile(file), we should check that "file" is an 
absolute path.
If not we cannot tell whether "file" is valid or not because the check gets 
made against process's current working directory.

Original issue: http://code.google.com/p/psutil/issues/detail?id=272

@giampaolo giampaolo self-assigned this May 23, 2014
@giampaolo
Copy link
Owner Author

From g.rodola on June 01, 2012 14:11:09

Fixed in r1328 .

Status: FixedInSVN

@giampaolo
Copy link
Owner Author

From g.rodola on June 27, 2012 11:54:03

0.5.0 is finally out. Closing out as fixed.

Status: Fixed

@giampaolo
Copy link
Owner Author

From g.rodola on March 02, 2013 04:08:24

Updated csets after the SVN -> Mercurial migration: r1328 == revision ???

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant