diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-07-24 08:57:24 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-07-24 08:57:24 +0100 |
commit | ae66be67da3b3f4d90fc4a6f8499183d715238bf (patch) | |
tree | 127016e45535ee080b50a7c1e578ec9694038b2a /src/lua | |
parent | 2f0c6e0f26c6d96442c24e54331c2939ca50127c (diff) | |
download | rspamd-ae66be67da3b3f4d90fc4a6f8499183d715238bf.tar.gz rspamd-ae66be67da3b3f4d90fc4a6f8499183d715238bf.zip |
[Minor] Further fixes for subprocess spawning logic
Diffstat (limited to 'src/lua')
-rw-r--r-- | src/lua/lua_common.c | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/src/lua/lua_common.c b/src/lua/lua_common.c index e94cbe281..762069294 100644 --- a/src/lua/lua_common.c +++ b/src/lua/lua_common.c @@ -1466,12 +1466,11 @@ rspamd_lua_cld_handler (struct rspamd_worker_signal_handler *sigh, void *ud) /* We still need to call on_complete callback */ rspamd_lua_call_on_complete (cbdata->L, cbdata, "Worker has died without reply", NULL, 0); + event_del (&cbdata->ev); } /* Free structures */ - event_del (&cbdata->ev); close (cbdata->sp[0]); - close (cbdata->sp[1]); luaL_unref (L, LUA_REGISTRYINDEX, cbdata->func_cbref); luaL_unref (L, LUA_REGISTRYINDEX, cbdata->cb_cbref); g_string_free (cbdata->io_buf, TRUE); @@ -1496,7 +1495,7 @@ rspamd_lua_subprocess_io (gint fd, short what, gpointer ud) struct rspamd_lua_process_cbdata *cbdata = ud; gssize r; - if (cbdata->io_buf->len < sizeof (guint64)) { + if (cbdata->sz == (guint64)-1) { guint64 sz; /* We read size of reply + flags first */ @@ -1506,6 +1505,8 @@ rspamd_lua_subprocess_io (gint fd, short what, gpointer ud) if (r == 0) { rspamd_lua_call_on_complete (cbdata->L, cbdata, "Unexpected EOF", NULL, 0); + event_del (&cbdata->ev); + cbdata->replied = TRUE; kill (cbdata->cpid, SIGTERM); return; @@ -1517,6 +1518,8 @@ rspamd_lua_subprocess_io (gint fd, short what, gpointer ud) else { rspamd_lua_call_on_complete (cbdata->L, cbdata, strerror (errno), NULL, 0); + event_del (&cbdata->ev); + cbdata->replied = TRUE; kill (cbdata->cpid, SIGTERM); return; @@ -1547,6 +1550,8 @@ rspamd_lua_subprocess_io (gint fd, short what, gpointer ud) if (r == 0) { rspamd_lua_call_on_complete (cbdata->L, cbdata, "Unexpected EOF", NULL, 0); + event_del (&cbdata->ev); + cbdata->replied = TRUE; kill (cbdata->cpid, SIGTERM); return; @@ -1558,6 +1563,8 @@ rspamd_lua_subprocess_io (gint fd, short what, gpointer ud) else { rspamd_lua_call_on_complete (cbdata->L, cbdata, strerror (errno), NULL, 0); + event_del (&cbdata->ev); + cbdata->replied = TRUE; kill (cbdata->cpid, SIGTERM); return; @@ -1580,6 +1587,9 @@ rspamd_lua_subprocess_io (gint fd, short what, gpointer ud) NULL, cbdata->io_buf->str, cbdata->io_buf->len); } + event_del (&cbdata->ev); + cbdata->replied = TRUE; + /* Write reply to the child */ rspamd_socket_blocking (cbdata->sp[0]); memset (rep, 0, sizeof (rep)); @@ -1627,6 +1637,7 @@ lua_worker_spawn_process (lua_State *L) cbdata->wrk = w; cbdata->L = L; cbdata->ev_base = actx->ev_base; + cbdata->sz = (guint64)-1; pid = fork (); |