login.c revision 7ecec4705c0cacb1446af0eb7a4aee66c00d058f
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2013 Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include "systemd/sd-login.h"
#include "pyutil.h"
#include "util.h"
#include "strv.h"
"Python interface to the libsystemd-login library."
);
int r; \
\
\
if (r < 0) { \
errno = -r; \
return PyErr_SetFromErrno(PyExc_IOError); \
} \
\
ans = PyList_New(r); \
if (!ans) \
return NULL; \
\
for (r--; r >= 0; r--) { \
if (!s) { \
return NULL; \
} \
\
PyList_SetItem(ans, r, s); \
} \
\
return ans; \
}
int r;
r = sd_get_uids(&list);
if (r < 0) {
errno = -r;
return PyErr_SetFromErrno(PyExc_IOError);
}
ans = PyList_New(r);
if (!ans)
return NULL;
for (r--; r >= 0; r--) {
if (!s) {
return NULL;
}
PyList_SetItem(ans, r, s);
}
return ans;
}
"seats() -> list\n\n"
"Returns a list of currently available local seats.\n"
"Wraps sd_get_seats(3)."
);
"sessions() -> list\n\n"
"Returns a list of current login sessions.\n"
"Wraps sd_get_sessions(3)."
);
"machine_names() -> list\n\n"
"Returns a list of currently running virtual machines\n"
"and containers on the system.\n"
"Wraps sd_get_machine_names(3)."
);
"uids() -> list\n\n"
"Returns a list of uids of users who currently have login sessions.\n"
"Wraps sd_get_uids(3)."
);
static PyMethodDef methods[] = {
{} /* Sentinel */
};
typedef struct {
} Monitor;
static PyTypeObject MonitorType;
{
}
"Monitor([category]) -> ...\n\n"
"Monitor may be used to monitor login sessions, users, seats,\n"
"and virtual machines/containers. Monitor provides a file\n"
"descriptor which can be integrated in an external event loop.\n"
"See man:sd_login_monitor_new(3) for the details about what\n"
"can be monitored.");
{
int r;
&category))
return -1;
}
"fileno() -> int\n\n"
"Get a file descriptor to poll for events.\n"
"This method wraps sd_login_monitor_get_fd(3).");
{
if (fd < 0)
return NULL;
return long_FromLong(fd);
}
"get_events() -> int\n\n"
"Returns a mask of poll() events to wait for on the file\n"
"descriptor returned by .fileno().\n\n"
"See man:sd_login_monitor_get_events(3) for further discussion.");
{
if (r < 0)
return NULL;
return long_FromLong(r);
}
"get_timeout() -> int or None\n\n"
"Returns a timeout value for usage in poll(), the time since the\n"
"epoch of clock_gettime(2) in microseconds, or None if no timeout\n"
"is necessary.\n\n"
"The return value must be converted to a relative timeout in\n"
"milliseconds if it is to be used as an argument for poll().\n"
"See man:sd_login_monitor_get_timeout(3) for further discussion.");
{
int r;
uint64_t t;
if (r < 0)
return NULL;
if (t == (uint64_t) -1)
assert_cc(sizeof(unsigned long long) == sizeof(t));
return PyLong_FromUnsignedLongLong(t);
}
"get_timeout_ms() -> int\n\n"
"Returns a timeout value suitable for usage in poll(), the value\n"
"returned by .get_timeout() converted to relative ms, or -1 if\n"
"no timeout is necessary.");
{
int r;
uint64_t t;
if (r < 0)
return NULL;
return absolute_timeout(t);
}
"close() -> None\n\n"
"Free resources allocated by this Monitor object.\n"
"This method invokes sd_login_monitor_unref().\n"
"See man:sd_login_monitor_unref(3).");
{
}
"flush() -> None\n\n"
"Reset the wakeup state of the monitor object.\n"
"This method invokes sd_login_monitor_flush().\n"
"See man:sd_login_monitor_flush(3).");
{
}
"__enter__() -> self\n\n"
"Part of the context manager protocol.\n"
"Returns self.\n");
{
return self;
}
"__exit__(type, value, traceback) -> None\n\n"
"Part of the context manager protocol.\n"
"Closes the monitor..\n");
{
}
static PyMethodDef Monitor_methods[] = {
{"get_timeout_ms", (PyCFunction) Monitor_get_timeout_ms, METH_NOARGS, Monitor_get_timeout_ms__doc__},
{} /* Sentinel */
};
static PyTypeObject MonitorType = {
.tp_name = "login.Monitor",
.tp_basicsize = sizeof(Monitor),
.tp_doc = Monitor__doc__,
};
#if PY_MAJOR_VERSION < 3
PyMODINIT_FUNC initlogin(void) {
PyObject *m;
if (PyType_Ready(&MonitorType) < 0)
return;
if (m == NULL)
return;
}
#else
static struct PyModuleDef module = {
"login", /* name of module */
module__doc__, /* module documentation, may be NULL */
-1, /* size of per-interpreter state of the module */
};
PyMODINIT_FUNC PyInit_login(void) {
PyObject *m;
if (PyType_Ready(&MonitorType) < 0)
return NULL;
m = PyModule_Create(&module);
if (m == NULL)
return NULL;
Py_DECREF(m);
return NULL;
}
Py_DECREF(m);
return NULL;
}
return m;
}
#endif