}
}
-static void ipc_close(uv_handle_t *handle)
-{
- free(handle);
-}
-
/* @internal AF_LOCAL reads may still be interrupted, loop it. */
static bool ipc_readall(int fd, char *dst, size_t len)
{
struct engine *engine = handle->data;
if (status != 0) {
kr_log_error("[system] ipc: %s\n", uv_strerror(status));
- ipc_close((uv_handle_t *)handle);
return;
}
/* Get file descriptor from handle */
errno = EINVAL;
}
if (!rbuf) {
- kr_log_error("[system] ipc: %s\n", strerror(errno));
- engine_stop(engine); /* Panic and stop this fork. */
- return;
+ goto failure;
}
if (!ipc_readall(fd, rbuf, len)) {
goto failure;
if (ret > 0) {
message = lua_tostring(engine->L, -1);
}
+ /* Clear the Lua stack */
+ lua_settop(engine->L, 0);
/* Send response back */
len = strlen(message);
if (write(fd, &len, sizeof(len)) != sizeof(len) ||
write(fd, message, len) != len) {
- kr_log_error("[system] ipc: %s\n", strerror(errno));
+ goto failure;
}
- /* Clear the Lua stack */
- lua_settop(engine->L, 0);
- return;
+ return; /* success! */
failure:
- kr_log_error("[system] ipc: %s\n", strerror(errno));
+ /* Note that if the piped command got read or written partially,
+ * we would get out of sync and only receive rubbish now.
+ * Therefore we prefer to stop IPC, but we try to continue with all else.
+ */
+ kr_log_error("[system] stopping ipc because of: %s\n", strerror(errno));
+ uv_poll_stop(handle);
}
static bool ipc_watch(uv_loop_t *loop, struct engine *engine, int fd)