From 568c2e039bac388003068cd8debb2f93619dd462 Mon Sep 17 00:00:00 2001 From: Ozan Tezcan Date: Thu, 6 Jan 2022 10:54:21 +0300 Subject: [PATCH] Set errno to EEXIST in redisFork() if child process exists (#10059) Callers of redisFork() are logging `strerror(errno)` on failure. `errno` is not set when there is already a child process, causing printing current value of errno which was set before `redisFork()` call. Setting errno to EEXIST on this failure to provide more meaningful error message. --- src/server.c | 4 +++- tests/unit/moduleapi/fork.tcl | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/server.c b/src/server.c index 42b6198d9..911441d56 100644 --- a/src/server.c +++ b/src/server.c @@ -5937,8 +5937,10 @@ void closeChildUnusedResourceAfterFork() { /* purpose is one of CHILD_TYPE_ types */ int redisFork(int purpose) { if (isMutuallyExclusiveChildType(purpose)) { - if (hasActiveChildProcess()) + if (hasActiveChildProcess()) { + errno = EEXIST; return -1; + } openChildInfoPipe(); } diff --git a/tests/unit/moduleapi/fork.tcl b/tests/unit/moduleapi/fork.tcl index a6a9b8a1e..64184d01e 100644 --- a/tests/unit/moduleapi/fork.tcl +++ b/tests/unit/moduleapi/fork.tcl @@ -32,4 +32,11 @@ start_server {tags {"modules"}} { assert {[count_log_message "fork child exiting"] eq "1"} } + test {Module fork twice} { + r fork.create 0 + after 250 + catch {r fork.create 0} + assert {[count_log_message "Can't fork for module: File exists"] eq "1"} + } + }