_daemon.c revision 5afbe712db5cc68213a24c45396ffb43fab05e3e
/*-*- 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 <stdbool.h>
#include <assert.h>
#include <systemd/sd-daemon.h>
#include "pyutil.h"
"Python interface to the libsystemd-daemon library.\n\n"
"Provides _listen_fds, notify, booted, and is_* functions\n"
"which wrap sd_listen_fds, sd_notify, sd_booted, sd_is_* and\n"
"useful for socket activation and checking if the system is\n"
"running under systemd."
);
assert (r < 0);
if (r == -EINVAL && invalid_message)
else if (r == -ENOMEM)
else {
errno = -r;
}
return NULL;
}
if (!obj)
/* cleanup: we don't return Py_CLEANUP_SUPPORTED, so
* we can assume that it was PyUnicode_FSConverter. */
return 1;
}
}
#endif
"booted() -> bool\n\n"
"Return True iff this system is running under systemd.\n"
"Wraps sd_daemon_booted(3)."
);
int r;
r = sd_booted();
if (r < 0)
return PyBool_FromLong(r);
}
"_listen_fds(unset_environment=True) -> int\n\n"
"Return the number of descriptors passed to this process by the init system\n"
"as part of the socket-based activation logic.\n"
"Wraps sd_listen_fds(3)."
);
int r;
int unset = true;
return NULL;
#else
return NULL;
if (unset < 0)
return NULL;
#endif
r = sd_listen_fds(unset);
if (r < 0)
return long_FromLong(r);
}
"_is_fifo(fd, path) -> bool\n\n"
"Returns True iff the descriptor refers to a FIFO or a pipe.\n"
"Wraps sd_is_fifo(3)."
);
int r;
int fd;
return NULL;
#else
return NULL;
#endif
if (r < 0)
return PyBool_FromLong(r);
}
"_is_mq(fd, path) -> bool\n\n"
"Returns True iff the descriptor refers to a POSIX message queue.\n"
"Wraps sd_is_mq(3)."
);
int r;
int fd;
return NULL;
#else
return NULL;
#endif
if (r < 0)
return PyBool_FromLong(r);
}
"_is_socket(fd, family=AF_UNSPEC, type=0, listening=-1) -> bool\n\n"
"Returns True iff the descriptor refers to a socket.\n"
"Wraps sd_is_socket(3).\n\n"
"Constants for `family` are defined in the socket module."
);
int r;
return NULL;
if (r < 0)
return PyBool_FromLong(r);
}
"_is_socket_inet(fd, family=AF_UNSPEC, type=0, listening=-1, port=0) -> bool\n\n"
"Wraps sd_is_socket_inet(3).\n\n"
"Constants for `family` are defined in the socket module."
);
int r;
return NULL;
if (r < 0)
return PyBool_FromLong(r);
}
"_is_socket_unix(fd, type, listening, path) -> bool\n\n"
"Wraps sd_is_socket_unix(3)."
);
int r;
Py_ssize_t length = 0;
return NULL;
if (_path) {
return NULL;
}
#else
return NULL;
#endif
if (r < 0)
return PyBool_FromLong(r);
}
static PyMethodDef methods[] = {
};
#if PY_MAJOR_VERSION < 3
PyMODINIT_FUNC init_daemon(void) {
PyObject *m;
if (m == NULL)
return;
}
#else
static struct PyModuleDef module = {
"_daemon", /* name of module */
module__doc__, /* module documentation, may be NULL */
0, /* size of per-interpreter state of the module */
};
PyMODINIT_FUNC PyInit__daemon(void) {
PyObject *m;
m = PyModule_Create(&module);
if (m == NULL)
return NULL;
Py_DECREF(m);
return NULL;
}
return m;
}
#endif