forked from mirrors/kore
Teach single binaries about SIGHUP.
Make sure kore_onload() and kore_preload() can be called either in native or python runtime.
This commit is contained in:
parent
3023ca0e57
commit
c06ecf1c70
|
@ -216,7 +216,7 @@ struct kore_runtime {
|
|||
int (*http_request)(void *, struct http_request *);
|
||||
int (*validator)(void *, struct http_request *, void *);
|
||||
#endif
|
||||
int (*execute)(void *, void *);
|
||||
void (*execute)(void *);
|
||||
int (*onload)(void *, int);
|
||||
void (*connect)(void *, struct connection *);
|
||||
};
|
||||
|
@ -618,6 +618,7 @@ void kore_module_handler_free(struct kore_module_handle *);
|
|||
|
||||
struct kore_runtime_call *kore_runtime_getcall(const char *);
|
||||
|
||||
void kore_runtime_execute(struct kore_runtime_call *);
|
||||
int kore_runtime_onload(struct kore_runtime_call *, int);
|
||||
void kore_runtime_connect(struct kore_runtime_call *, struct connection *);
|
||||
#if !defined(KORE_NO_HTTP)
|
||||
|
|
|
@ -434,7 +434,7 @@ kore_server_start(void)
|
|||
#if defined(KORE_SINGLE_BINARY)
|
||||
rcall = kore_runtime_getcall("kore_preload");
|
||||
if (rcall != NULL) {
|
||||
rcall->runtime->execute(rcall->addr, NULL);
|
||||
kore_runtime_execute(rcall);
|
||||
kore_free(rcall);
|
||||
}
|
||||
#endif
|
||||
|
@ -458,10 +458,8 @@ kore_server_start(void)
|
|||
if (sig_recv != 0) {
|
||||
switch (sig_recv) {
|
||||
case SIGHUP:
|
||||
#if !defined(KORE_SINGLE_BINARY)
|
||||
kore_worker_dispatch_signal(sig_recv);
|
||||
kore_module_reload(0);
|
||||
#endif
|
||||
break;
|
||||
case SIGINT:
|
||||
case SIGQUIT:
|
||||
|
|
26
src/python.c
26
src/python.c
|
@ -46,6 +46,7 @@ static void python_push_type(const char *, PyObject *, PyTypeObject *);
|
|||
static int python_runtime_http_request(void *, struct http_request *);
|
||||
static int python_runtime_validator(void *, struct http_request *, void *);
|
||||
#endif
|
||||
static void python_runtime_execute(void *);
|
||||
static int python_runtime_onload(void *, int);
|
||||
static void python_runtime_connect(void *, struct connection *);
|
||||
|
||||
|
@ -73,7 +74,8 @@ struct kore_runtime kore_python_runtime = {
|
|||
.validator = python_runtime_validator,
|
||||
#endif
|
||||
.onload = python_runtime_onload,
|
||||
.connect = python_runtime_connect
|
||||
.connect = python_runtime_connect,
|
||||
.execute = python_runtime_execute
|
||||
};
|
||||
|
||||
static struct {
|
||||
|
@ -339,6 +341,28 @@ python_runtime_validator(void *addr, struct http_request *req, void *data)
|
|||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
python_runtime_execute(void *addr)
|
||||
{
|
||||
PyObject *callable, *args, *pyret;
|
||||
|
||||
callable = (PyObject *)addr;
|
||||
|
||||
if ((args = PyTuple_New(0)) == NULL)
|
||||
fatal("python_runtime_execute: PyTuple_New failed");
|
||||
|
||||
PyErr_Clear();
|
||||
pyret = PyObject_Call(callable, args, NULL);
|
||||
Py_DECREF(args);
|
||||
|
||||
if (pyret == NULL) {
|
||||
python_log_error("python_runtime_execute");
|
||||
fatal("failed to execute python call");
|
||||
}
|
||||
|
||||
Py_DECREF(pyret);
|
||||
}
|
||||
|
||||
static int
|
||||
python_runtime_onload(void *addr, int action)
|
||||
{
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include "python_api.h"
|
||||
#endif
|
||||
|
||||
static void native_runtime_execute(void *);
|
||||
static int native_runtime_onload(void *, int);
|
||||
static void native_runtime_connect(void *, struct connection *);
|
||||
#if !defined(KORE_NO_HTTP)
|
||||
|
@ -40,7 +41,8 @@ struct kore_runtime kore_native_runtime = {
|
|||
.validator = native_runtime_validator,
|
||||
#endif
|
||||
.onload = native_runtime_onload,
|
||||
.connect = native_runtime_connect
|
||||
.connect = native_runtime_connect,
|
||||
.execute = native_runtime_execute
|
||||
};
|
||||
|
||||
struct kore_runtime_call *
|
||||
|
@ -61,6 +63,12 @@ kore_runtime_getcall(const char *symbol)
|
|||
return (rcall);
|
||||
}
|
||||
|
||||
void
|
||||
kore_runtime_execute(struct kore_runtime_call *rcall)
|
||||
{
|
||||
rcall->runtime->execute(rcall->addr);
|
||||
}
|
||||
|
||||
int
|
||||
kore_runtime_onload(struct kore_runtime_call *rcall, int action)
|
||||
{
|
||||
|
@ -89,6 +97,15 @@ kore_runtime_validator(struct kore_runtime_call *rcall,
|
|||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
native_runtime_execute(void *addr)
|
||||
{
|
||||
void (*cb)(void);
|
||||
|
||||
*(void **)&(cb) = addr;
|
||||
cb();
|
||||
}
|
||||
|
||||
static void
|
||||
native_runtime_connect(void *addr, struct connection *c)
|
||||
{
|
||||
|
|
|
@ -338,20 +338,17 @@ kore_worker_entry(struct kore_worker *kw)
|
|||
#if defined(KORE_SINGLE_BINARY)
|
||||
rcall = kore_runtime_getcall("kore_onload");
|
||||
if (rcall != NULL) {
|
||||
rcall->runtime->execute(rcall->addr, NULL);
|
||||
kore_runtime_execute(rcall);
|
||||
kore_free(rcall);
|
||||
}
|
||||
#else
|
||||
kore_module_onload();
|
||||
#endif
|
||||
kore_module_onload();
|
||||
|
||||
for (;;) {
|
||||
if (sig_recv != 0) {
|
||||
switch (sig_recv) {
|
||||
case SIGHUP:
|
||||
#if !defined(KORE_SINGLE_BINARY)
|
||||
kore_module_reload(1);
|
||||
#endif
|
||||
break;
|
||||
case SIGQUIT:
|
||||
case SIGINT:
|
||||
|
|
Loading…
Reference in New Issue