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.
This commit is contained in:
Ozan Tezcan 2022-01-06 10:54:21 +03:00 committed by GitHub
parent 5dd15443ac
commit 568c2e039b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -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();
}

View File

@ -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"}
}
}