Esempio n. 1
0
// returns the command line as a python list object
PyObject *
psutil_get_cmdline(long pid) {
    static char **argv;
    char **p;
    PyObject *py_arg = NULL;
    PyObject *py_retlist = Py_BuildValue("[]");

    if (!py_retlist)
        return NULL;
    if (pid < 0)
        return py_retlist;

    if ((argv = _psutil_get_argv(pid)) == NULL)
        goto error;

    for (p = argv; *p != NULL; p++) {
        py_arg = Py_BuildValue("s", *p);
        if (!py_arg)
            goto error;
        if (PyList_Append(py_retlist, py_arg))
            goto error;
        Py_DECREF(py_arg);
    }
    return py_retlist;

error:
    Py_XDECREF(py_arg);
    Py_DECREF(py_retlist);
    return NULL;
}
Esempio n. 2
0
// returns the command line as a python list object
PyObject *
psutil_get_cmdline(long pid) {
    static char **argv;
    char **p;
    PyObject *py_arg = NULL;
    PyObject *py_retlist = Py_BuildValue("[]");

    if (!py_retlist)
        return NULL;
    if (pid < 0)
        return py_retlist;

    if ((argv = _psutil_get_argv(pid)) == NULL)
        goto error;

    for (p = argv; *p != NULL; p++) {
#if PY_MAJOR_VERSION >= 3
        py_arg = PyUnicode_DecodeFSDefault(*p);
#else
        py_arg = Py_BuildValue("s", *p);
#endif
        if (!py_arg)
            goto error;
        if (PyList_Append(py_retlist, py_arg))
            goto error;
        Py_DECREF(py_arg);
    }
    return py_retlist;

error:
    Py_XDECREF(py_arg);
    Py_DECREF(py_retlist);
    return NULL;
}