From 7d237da3934bec416fab604af74f61e8c53f0505 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Mon, 4 Nov 2019 16:05:46 +0000 Subject: [PATCH] [Minor] Slightly improve logging in case of termination --- src/libserver/rspamd_control.c | 11 ++++++++--- src/lua/lua_worker.c | 3 ++- src/rspamd.c | 12 +++++++----- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/libserver/rspamd_control.c b/src/libserver/rspamd_control.c index 503825184..e119e64d4 100644 --- a/src/libserver/rspamd_control.c +++ b/src/libserver/rspamd_control.c @@ -655,10 +655,15 @@ rspamd_control_default_worker_handler (EV_P_ ev_io *w, int revents) r = recvmsg (w->fd, &msg, 0); if (r == -1) { - msg_err ("cannot read request from the control socket: %s", - strerror (errno)); - if (errno != EAGAIN && errno != EINTR) { + if (errno != ECONNRESET) { + /* + * In case of connection reset it means that main process + * has died, so do not pollute logs + */ + msg_err ("cannot read request from the control socket: %s", + strerror (errno)); + } ev_io_stop (cd->ev_base, &cd->io_ev); close (w->fd); } diff --git a/src/lua/lua_worker.c b/src/lua/lua_worker.c index 940c6ae4a..4a3e4e908 100644 --- a/src/lua/lua_worker.c +++ b/src/lua/lua_worker.c @@ -841,7 +841,8 @@ lua_worker_spawn_process (lua_State *L) /* Wait for parent to reply and exit */ rc = read (cbdata->sp[1], inbuf, sizeof (inbuf)); - if (memcmp (inbuf, "\0\0\0\0", 4) == 0) { + if (rc >= sizeof (inbuf) && + memcmp (inbuf, "\0\0\0\0", sizeof (inbuf)) == 0) { exit (EXIT_SUCCESS); } else { diff --git a/src/rspamd.c b/src/rspamd.c index 4b33e7577..4eed0205f 100644 --- a/src/rspamd.c +++ b/src/rspamd.c @@ -1092,11 +1092,13 @@ rspamd_cld_handler (EV_P_ ev_child *w, struct rspamd_main *rspamd_main, close (wrk->srv_pipe[0]); } - cmd.type = RSPAMD_CONTROL_CHILD_CHANGE; - cmd.cmd.child_change.what = rspamd_child_terminated; - cmd.cmd.child_change.pid = wrk->pid; - cmd.cmd.child_change.additional = w->rstatus; - rspamd_control_broadcast_srv_cmd (rspamd_main, &cmd, wrk->pid); + if (!rspamd_main->wanna_die) { + cmd.type = RSPAMD_CONTROL_CHILD_CHANGE; + cmd.cmd.child_change.what = rspamd_child_terminated; + cmd.cmd.child_change.pid = wrk->pid; + cmd.cmd.child_change.additional = w->rstatus; + rspamd_control_broadcast_srv_cmd (rspamd_main, &cmd, wrk->pid); + } if (wrk->finish_actions) { g_ptr_array_free (wrk->finish_actions, TRUE); -- 2.39.5