From 49356a47fc321826a65f752181838a232f104a80 Mon Sep 17 00:00:00 2001 From: Andy Green <andy@warmcat.com> Date: Wed, 23 Jan 2019 18:20:53 +0800 Subject: [PATCH] daemonize: use pid_t After report from Vitaly Shevtsov https://libwebsockets.org/pipermail/libwebsockets/2019-January/007787.html --- lib/core/context.c | 4 ++-- lib/core/private.h | 4 +++- lib/misc/daemonize.c | 4 ++-- lib/plat/unix/unix-service.c | 2 ++ test-apps/test-server.c | 3 --- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/core/context.c b/lib/core/context.c index 4bd2b05a..cab88616 100644 --- a/lib/core/context.c +++ b/lib/core/context.c @@ -823,7 +823,7 @@ lws_create_context(const struct lws_context_creation_info *info) struct lws_context *context = NULL; struct lws_plat_file_ops *prev; #ifndef LWS_NO_DAEMONIZE - int pid_daemon = get_daemonize_pid(); + pid_t pid_daemon = get_daemonize_pid(); #endif int n; #if defined(__ANDROID__) @@ -934,7 +934,7 @@ lws_create_context(const struct lws_context_creation_info *info) #ifndef LWS_NO_DAEMONIZE if (pid_daemon) { context->started_with_parent = pid_daemon; - lwsl_info(" Started with daemon pid %d\n", pid_daemon); + lwsl_info(" Started with daemon pid %u\n", (unsigned int)pid_daemon); } #endif #if defined(__ANDROID__) diff --git a/lib/core/private.h b/lib/core/private.h index c1a0a661..4b210e6f 100644 --- a/lib/core/private.h +++ b/lib/core/private.h @@ -696,7 +696,9 @@ struct lws_context { int max_fds; int count_event_loop_static_asset_handles; - int started_with_parent; +#if !defined(LWS_NO_DAEMONIZE) + pid_t started_with_parent; +#endif int uid, gid; int fd_random; diff --git a/lib/misc/daemonize.c b/lib/misc/daemonize.c index b41609f4..52fd6ea0 100644 --- a/lib/misc/daemonize.c +++ b/lib/misc/daemonize.c @@ -28,10 +28,10 @@ #include "core/private.h" -unsigned int pid_daemon; +pid_t pid_daemon; static char *lock_path; -int get_daemonize_pid() +pid_t get_daemonize_pid() { return pid_daemon; } diff --git a/lib/plat/unix/unix-service.c b/lib/plat/unix/unix-service.c index e61ef599..b2c05ea5 100644 --- a/lib/plat/unix/unix-service.c +++ b/lib/plat/unix/unix-service.c @@ -197,8 +197,10 @@ lws_plat_service(struct lws_context *context, int timeout_ms) void lws_plat_service_periodic(struct lws_context *context) { +#if !defined(LWS_NO_DAEMONIZE) /* if our parent went down, don't linger around */ if (context->started_with_parent && kill(context->started_with_parent, 0) < 0) kill(getpid(), SIGTERM); +#endif } diff --git a/test-apps/test-server.c b/test-apps/test-server.c index 2319cb49..99e0e779 100644 --- a/test-apps/test-server.c +++ b/test-apps/test-server.c @@ -363,9 +363,6 @@ int main(int argc, char **argv) #ifndef LWS_NO_DAEMONIZE case 'D': daemonize = 1; - #if !defined(_WIN32) && !defined(__sun) - syslog_options &= ~LOG_PERROR; - #endif break; #endif case 'u': -- GitLab