static PyObject * strcaps_get_process(PyObject *self, PyObject *args) { // (int) pid or None int pid = 0; if (!PyArg_ParseTuple(args, "|i", &pid)) return NULL; cap_t caps; if (!pid) caps = cap_get_proc(); else caps = cap_get_pid(pid); size_t strcaps_len; char *strcaps; if (caps == NULL) { if (errno == ENODATA) { strcaps = "\0"; strcaps_len = 0; } else { PyErr_SetFromErrno(PyExc_OSError); return NULL; } } else strcaps = cap_to_text(caps, &strcaps_len); cap_free(caps); return Py_BuildValue("s#", strcaps, strcaps_len); }; // (str) caps
VALUE cap2_process_getcaps(VALUE self) { cap_t cap_d; int pid; VALUE result; pid = cap2_process_pid(self); cap_d = cap_get_pid(pid); if (cap_d == NULL) { rb_raise( rb_eRuntimeError, "Failed to get capabilities for proccess %d: (%s)\n", pid, strerror(errno) ); } else { result = cap2_caps_to_hash(cap_d); cap_free(cap_d); return result; } }