commit c41c1db303786f56f407ec87c550ab3c002498b7
parent 4c35073232d91ae0e09f1e4f04de3b48bb7d89e4
Author: Joris Vink <joris@coders.se>
Date: Tue, 23 Oct 2018 19:49:42 +0200
Add kore_shutdown().
Allows workers to cleanly initiate a shutdown of the
entire server process.
Diffstat:
4 files changed, 22 insertions(+), 0 deletions(-)
diff --git a/include/kore/kore.h b/include/kore/kore.h
@@ -540,6 +540,7 @@ extern struct kore_domain *primary_dom;
extern struct kore_pool nb_pool;
void kore_signal(int);
+void kore_shutdown(void);
void kore_signal_setup(void);
void kore_worker_wait(int);
void kore_worker_init(void);
diff --git a/include/kore/python_methods.h b/include/kore/python_methods.h
@@ -33,6 +33,7 @@ static PyObject *python_kore_bind(PyObject *, PyObject *);
static PyObject *python_kore_fatal(PyObject *, PyObject *);
static PyObject *python_kore_queue(PyObject *, PyObject *);
static PyObject *python_kore_fatalx(PyObject *, PyObject *);
+static PyObject *python_kore_shutdown(PyObject *, PyObject *);
static PyObject *python_kore_bind_unix(PyObject *, PyObject *);
static PyObject *python_kore_task_create(PyObject *, PyObject *);
static PyObject *python_kore_socket_wrap(PyObject *, PyObject *);
@@ -55,6 +56,7 @@ static struct PyMethodDef pykore_methods[] = {
METHOD("queue", python_kore_queue, METH_VARARGS),
METHOD("fatal", python_kore_fatal, METH_VARARGS),
METHOD("fatalx", python_kore_fatalx, METH_VARARGS),
+ METHOD("shutdown", python_kore_shutdown, METH_NOARGS),
METHOD("bind_unix", python_kore_bind_unix, METH_VARARGS),
METHOD("task_create", python_kore_task_create, METH_VARARGS),
METHOD("socket_wrap", python_kore_socket_wrap, METH_VARARGS),
diff --git a/src/kore.c b/src/kore.c
@@ -541,6 +541,17 @@ kore_signal(int sig)
sig_recv = sig;
}
+void
+kore_shutdown(void)
+{
+ if (worker != NULL) {
+ kore_msg_send(KORE_MSG_PARENT, KORE_MSG_SHUTDOWN, NULL, 0);
+ return;
+ }
+
+ fatal("kore_shutdown: called from parent");
+}
+
static void
kore_server_sslstart(void)
{
diff --git a/src/python.c b/src/python.c
@@ -959,6 +959,14 @@ python_kore_fatalx(PyObject *self, PyObject *args)
}
static PyObject *
+python_kore_shutdown(PyObject *self, PyObject *args)
+{
+ kore_shutdown();
+
+ Py_RETURN_TRUE;
+}
+
+static PyObject *
python_import(const char *path)
{
PyObject *module;