Skip to content
Browse files

add proc_env Python binding

  • Loading branch information...
1 parent de81b90 commit cb1e4f491d6c7a11e923c3a32f948a6984952074 @dougm dougm committed Jun 15, 2011
Showing with 37 additions and 0 deletions.
  1. +37 −0 bindings/python/_sigar.c
View
37 bindings/python/_sigar.c
@@ -524,6 +524,42 @@ static PyObject *pysigar_proc_args(PyObject *self, PyObject *args)
return RETVAL;
}
+static int pysigar_env_getall(void *data,
+ const char *key, int klen,
+ char *val, int vlen)
+{
+ PyDict_SetItem((PyObject *)data,
+ PyString_FromStringAndSize(key, klen),
+ PyString_FromStringAndSize(val, vlen));
+
+ return SIGAR_OK;
+}
+
+static PyObject *pysigar_proc_env(PyObject *self, PyObject *args)
+{
+ int status;
+ sigar_t *sigar = PySIGAR;
+ sigar_proc_env_t procenv;
+ long pid;
+
+ PyObject *RETVAL;
+
+ PySigar_ParsePID;
+
+ RETVAL = PyDict_New();
+
+ procenv.type = SIGAR_PROC_ENV_ALL;
+ procenv.env_getter = pysigar_env_getall;
+ procenv.data = RETVAL;
+
+ status = sigar_proc_env_get(sigar, pid, &procenv);
+ if (status != SIGAR_OK) {
+ PySigar_Croak();
+ }
+
+ return RETVAL;
+}
+
static PyObject *pysigar_format_size(PyObject *self, PyObject *args)
{
char buffer[56];
@@ -549,6 +585,7 @@ static PyMethodDef pysigar_methods[] = {
{ "who_list", pysigar_who_list, METH_NOARGS, NULL },
{ "proc_list", pysigar_proc_list, METH_VARARGS, NULL },
{ "proc_args", pysigar_proc_args, METH_VARARGS, NULL },
+ { "proc_env", pysigar_proc_env, METH_VARARGS, NULL },
PY_SIGAR_METHODS
{NULL}
};

0 comments on commit cb1e4f4

Please sign in to comment.
Something went wrong with that request. Please try again.