Closed
Description
From bsdkn...@gmail.com on April 18, 2013 23:02:37
What steps will reproduce the problem?
1. Try to use process.get_connections() to examine a process as non-root and
get AccessDenied when kvm_openfiles() fails.
What version of psutil are you using? What Python version?
0.6.1 on Python 2.7. Examining 0.7.0's source shows it to have the same issue.
On what operating system? Is it 32bit or 64bit version?
FreeBSD. I have tested on 64-bit, but it is true of all platforms supported by FreeBSD.
Please provide any additional information below.
The current implementation of get_connections() uses direct KVM access to read
in-kernel structures based on the code in fstat. This requires root access so
that it can open /dev/mem. I have written an alternate implementation that
uses unprivileged sysctls to fetch the data. kinfo_getfile() gets most of the
needed data except for the TCP state. To handle TCP state I use a sysctl to
fetch information about all the TCP connections in the system borrowing from
the implementation of the netstat command. I then walk this list of TCP
connections each time the main loop encounters a TCP socket to fetch the TCP
state. Using sysctl's also avoids races that can occur with sockets coming and
going and KVM access failing because a socket has been freed while
get_connections() was running.
Attachment: psutil_sysctl.patch
Original issue: http://code.google.com/p/psutil/issues/detail?id=370