commit 0c0a9371bdd0e27d12e90a6d9428b0c87e313f76
parent 86294192530b5426f1ce03561c0fbee27d8069db
Author: Joris Vink <joris@coders.se>
Date: Wed, 1 Feb 2017 17:12:11 +0100
Change kore_preload() and kore_onload().
Renamed both of them:
kore_preload -> kore_parent_configure
kore_onload -> kore_worker_configure
These functions will now always be called if they are defined in any module
regardless of your application being built as a single binary or not.
Diffstat:
3 files changed, 13 insertions(+), 25 deletions(-)
diff --git a/includes/kore.h b/includes/kore.h
@@ -693,10 +693,8 @@ void kore_buf_replace_string(struct kore_buf *, char *, void *, size_t);
void kore_keymgr_run(void);
void kore_keymgr_cleanup(void);
-#if defined(KORE_SINGLE_BINARY)
-void kore_preload(void);
-void kore_onload(void);
-#endif
+void kore_parent_configure(void);
+void kore_worker_configure(void);
#if defined(__cplusplus)
}
diff --git a/src/kore.c b/src/kore.c
@@ -308,15 +308,14 @@ kore_server_bind(const char *ip, const char *port, const char *ccb)
if ((l->fd = socket(results->ai_family, SOCK_STREAM, 0)) == -1) {
kore_free(l);
freeaddrinfo(results);
- kore_debug("socket(): %s", errno_s);
- printf("failed to create socket: %s\n", errno_s);
+ kore_log(LOG_ERR, "socket(): %s", errno_s);
return (KORE_RESULT_ERROR);
}
if (!kore_connection_nonblock(l->fd, 1)) {
kore_free(l);
freeaddrinfo(results);
- printf("failed to make socket non blocking: %s\n", errno_s);
+ kore_log(LOG_ERR, "kore_connection_nonblock(): %s", errno_s);
return (KORE_RESULT_ERROR);
}
@@ -326,8 +325,7 @@ kore_server_bind(const char *ip, const char *port, const char *ccb)
close(l->fd);
kore_free(l);
freeaddrinfo(results);
- kore_debug("setsockopt(): %s", errno_s);
- printf("failed to set SO_REUSEADDR: %s\n", errno_s);
+ kore_log(LOG_ERR, "setsockopt(): %s", errno_s);
return (KORE_RESULT_ERROR);
}
@@ -335,8 +333,7 @@ kore_server_bind(const char *ip, const char *port, const char *ccb)
close(l->fd);
kore_free(l);
freeaddrinfo(results);
- kore_debug("bind(): %s", errno_s);
- printf("failed to bind to %s port %s: %s\n", ip, port, errno_s);
+ kore_log(LOG_ERR, "bind(): %s", errno_s);
return (KORE_RESULT_ERROR);
}
@@ -345,14 +342,13 @@ kore_server_bind(const char *ip, const char *port, const char *ccb)
if (listen(l->fd, kore_socket_backlog) == -1) {
close(l->fd);
kore_free(l);
- kore_debug("listen(): %s", errno_s);
- printf("failed to listen on socket: %s\n", errno_s);
+ kore_log(LOG_ERR, "listen(): %s", errno_s);
return (KORE_RESULT_ERROR);
}
if (ccb != NULL) {
if ((l->connect = kore_runtime_getcall(ccb)) == NULL) {
- printf("no such callback: '%s'\n", ccb);
+ kore_log(LOG_ERR, "no such callback: '%s'", ccb);
close(l->fd);
kore_free(l);
return (KORE_RESULT_ERROR);
@@ -410,9 +406,7 @@ kore_server_start(void)
{
u_int32_t tmp;
int quit;
-#if defined(KORE_SINGLE_BINARY)
struct kore_runtime_call *rcall;
-#endif
if (foreground == 0 && daemon(1, 1) == -1)
fatal("cannot daemon(): %s", errno_s);
@@ -431,13 +425,12 @@ kore_server_start(void)
#if defined(KORE_USE_JSONRPC)
kore_log(LOG_NOTICE, "jsonrpc built-in enabled");
#endif
-#if defined(KORE_SINGLE_BINARY)
- rcall = kore_runtime_getcall("kore_preload");
+
+ rcall = kore_runtime_getcall("kore_parent_configure");
if (rcall != NULL) {
kore_runtime_execute(rcall);
kore_free(rcall);
}
-#endif
kore_platform_proctitle("kore [parent]");
kore_msg_init();
diff --git a/src/worker.c b/src/worker.c
@@ -266,12 +266,10 @@ kore_worker_privdrop(void)
void
kore_worker_entry(struct kore_worker *kw)
{
+ struct kore_runtime_call *rcall;
char buf[16];
int quit, had_lock, r;
u_int64_t now, next_lock, netwait;
-#if defined(KORE_SINGLE_BINARY)
- struct kore_runtime_call *rcall;
-#endif
worker = kw;
@@ -335,13 +333,12 @@ kore_worker_entry(struct kore_worker *kw)
kore_log(LOG_NOTICE, "worker %d started (cpu#%d)", kw->id, kw->cpu);
-#if defined(KORE_SINGLE_BINARY)
- rcall = kore_runtime_getcall("kore_onload");
+ rcall = kore_runtime_getcall("kore_worker_configure");
if (rcall != NULL) {
kore_runtime_execute(rcall);
kore_free(rcall);
}
-#endif
+
kore_module_onload();
for (;;) {