Skip to content

Commit

Permalink
implement process cwd
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed Nov 7, 2015
1 parent 1374b42 commit 0410205
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions psutil/_psutil_openbsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -688,14 +688,33 @@ psutil_proc_num_fds(PyObject *self, PyObject *args) {
return Py_BuildValue("i", cnt);
}


/*
* No way to get cwd on OpenBSD
* Process current working directory.
* Reference:
* http://anoncvs.spacehopper.org/openbsd-src/tree/bin/ps/print.c#n179
*/
static PyObject *
psutil_proc_cwd(PyObject *self, PyObject *args) {
return Py_BuildValue("s", "");
long pid;
struct kinfo_proc kp;
char path[MAXPATHLEN];
size_t pathlen = sizeof path;

if (! PyArg_ParseTuple(args, "l", &pid))
return NULL;
if (psutil_kinfo_proc(pid, &kp) == -1)
return NULL;

int name[] = { CTL_KERN, KERN_PROC_CWD, pid };
if (sysctl(name, 3, path, &pathlen, NULL, 0) != 0) {
PyErr_SetFromErrno(PyExc_OSError);
return NULL;
}
return Py_BuildValue("s", path);
}


#if 0
// The tcplist fetching and walking is borrowed from netstat/inet.c.
static char *
Expand Down

0 comments on commit 0410205

Please sign in to comment.