diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2015-11-12 12:43:07 +0100 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2015-11-12 12:43:07 +0100 |
commit | 2888dd347d87cfc952294b5287000fed71b5355b (patch) | |
tree | f9e93be83fbf15e4c99ecaed93bd547bc5aea070 | |
parent | bfd4ef9c0c12037bb6ab00551338004bb20b7d46 (diff) | |
download | psutil-2888dd347d87cfc952294b5287000fed71b5355b.tar.gz |
move proc cwd
-rw-r--r-- | psutil/_psutil_bsd.c | 53 | ||||
-rw-r--r-- | psutil/arch/bsd/freebsd.c | 52 | ||||
-rw-r--r-- | psutil/arch/bsd/freebsd.h | 1 |
3 files changed, 52 insertions, 54 deletions
diff --git a/psutil/_psutil_bsd.c b/psutil/_psutil_bsd.c index c4da2865..e58f32c8 100644 --- a/psutil/_psutil_bsd.c +++ b/psutil/_psutil_bsd.c @@ -586,59 +586,6 @@ psutil_proc_num_fds(PyObject *self, PyObject *args) { #endif -#if defined(__FreeBSD_version) && __FreeBSD_version >= 800000 -/* - * Return process current working directory. - */ -static PyObject * -psutil_proc_cwd(PyObject *self, PyObject *args) { - long pid; - struct kinfo_file *freep = NULL; - struct kinfo_file *kif; - struct kinfo_proc kipp; - PyObject *py_path = NULL; - - int i, cnt; - - if (! PyArg_ParseTuple(args, "l", &pid)) - goto error; - if (psutil_kinfo_proc(pid, &kipp) == -1) - goto error; - - freep = kinfo_getfile(pid, &cnt); - if (freep == NULL) { - psutil_raise_ad_or_nsp(pid); - goto error; - } - - for (i = 0; i < cnt; i++) { - kif = &freep[i]; - if (kif->kf_fd == KF_FD_TYPE_CWD) { - py_path = Py_BuildValue("s", kif->kf_path); - if (!py_path) - goto error; - break; - } - } - /* - * For lower pids it seems we can't retrieve any information - * (lsof can't do that it either). Since this happens even - * as root we return an empty string instead of AccessDenied. - */ - if (py_path == NULL) - py_path = Py_BuildValue("s", ""); - free(freep); - return py_path; - -error: - Py_XDECREF(py_path); - if (freep != NULL) - free(freep); - return NULL; -} -#endif - - #ifdef __FreeBSD__ // The tcplist fetching and walking is borrowed from netstat/inet.c. static char * diff --git a/psutil/arch/bsd/freebsd.c b/psutil/arch/bsd/freebsd.c index d40acbc1..f209223a 100644 --- a/psutil/arch/bsd/freebsd.c +++ b/psutil/arch/bsd/freebsd.c @@ -7,7 +7,6 @@ * Used by _psutil_bsd module methods. */ - #include <Python.h> #include <assert.h> #include <errno.h> @@ -23,6 +22,7 @@ #include <fcntl.h> #include <sys/vmmeter.h> // needed for vmtotal struct #include <devstat.h> // for swap mem +#include <libutil.h> // process open files, shared libs (kinfo_getvmmap), cwd #include "freebsd.h" @@ -550,3 +550,53 @@ sbn_error: PyErr_SetFromErrno(PyExc_OSError); return NULL; } + + +#if defined(__FreeBSD_version) && __FreeBSD_version >= 800000 +PyObject * +psutil_proc_cwd(PyObject *self, PyObject *args) { + long pid; + struct kinfo_file *freep = NULL; + struct kinfo_file *kif; + struct kinfo_proc kipp; + PyObject *py_path = NULL; + + int i, cnt; + + if (! PyArg_ParseTuple(args, "l", &pid)) + goto error; + if (psutil_kinfo_proc(pid, &kipp) == -1) + goto error; + + freep = kinfo_getfile(pid, &cnt); + if (freep == NULL) { + psutil_raise_ad_or_nsp(pid); + goto error; + } + + for (i = 0; i < cnt; i++) { + kif = &freep[i]; + if (kif->kf_fd == KF_FD_TYPE_CWD) { + py_path = Py_BuildValue("s", kif->kf_path); + if (!py_path) + goto error; + break; + } + } + /* + * For lower pids it seems we can't retrieve any information + * (lsof can't do that it either). Since this happens even + * as root we return an empty string instead of AccessDenied. + */ + if (py_path == NULL) + py_path = Py_BuildValue("s", ""); + free(freep); + return py_path; + +error: + Py_XDECREF(py_path); + if (freep != NULL) + free(freep); + return NULL; +} +#endif diff --git a/psutil/arch/bsd/freebsd.h b/psutil/arch/bsd/freebsd.h index d74d0ddb..c1f97325 100644 --- a/psutil/arch/bsd/freebsd.h +++ b/psutil/arch/bsd/freebsd.h @@ -16,6 +16,7 @@ int psutil_pid_exists(long pid); // PyObject* psutil_get_cmdline(long pid); PyObject* psutil_proc_exe(PyObject* self, PyObject* args); +PyObject* psutil_proc_cwd(PyObject* self, PyObject* args); PyObject* psutil_proc_num_threads(PyObject* self, PyObject* args); PyObject* psutil_proc_threads(PyObject* self, PyObject* args); PyObject* psutil_cpu_count_phys(PyObject* self, PyObject* args); |