Unverified Commit 7de64518 authored by Qu Chen's avatar Qu Chen Committed by GitHub
Browse files

Properly initialize variable to make valgrind happy in checkChildrenDone()....

Properly initialize variable to make valgrind happy in checkChildrenDone(). Removed usage for the obsolete wait3() and wait4() in favor of waitpid(), and properly check for the exit status code. (#8666)
parent 3060de88
...@@ -218,7 +218,7 @@ void killAppendOnlyChild(void) { ...@@ -218,7 +218,7 @@ void killAppendOnlyChild(void) {
serverLog(LL_NOTICE,"Killing running AOF rewrite child: %ld", serverLog(LL_NOTICE,"Killing running AOF rewrite child: %ld",
(long) server.child_pid); (long) server.child_pid);
if (kill(server.child_pid,SIGUSR1) != -1) { if (kill(server.child_pid,SIGUSR1) != -1) {
while(wait3(&statloc,0,NULL) != server.child_pid); while(waitpid(-1, &statloc, 0) != server.child_pid);
} }
/* Reset the buffer accumulating changes while the child saves. */ /* Reset the buffer accumulating changes while the child saves. */
aofRewriteBufferReset(); aofRewriteBufferReset();
......
...@@ -7821,7 +7821,7 @@ int TerminateModuleForkChild(int child_pid, int wait) { ...@@ -7821,7 +7821,7 @@ int TerminateModuleForkChild(int child_pid, int wait) {
serverLog(LL_VERBOSE,"Killing running module fork child: %ld", serverLog(LL_VERBOSE,"Killing running module fork child: %ld",
(long) server.child_pid); (long) server.child_pid);
if (kill(server.child_pid,SIGUSR1) != -1 && wait) { if (kill(server.child_pid,SIGUSR1) != -1 && wait) {
while(wait4(server.child_pid,&statloc,0,NULL) != while(waitpid(server.child_pid, &statloc, 0) !=
server.child_pid); server.child_pid);
} }
/* Reset the buffer accumulating changes while the child saves. */ /* Reset the buffer accumulating changes while the child saves. */
......
...@@ -2732,7 +2732,7 @@ void backgroundSaveDoneHandler(int exitcode, int bysignal) { ...@@ -2732,7 +2732,7 @@ void backgroundSaveDoneHandler(int exitcode, int bysignal) {
* the cleanup needed. */ * the cleanup needed. */
void killRDBChild(void) { void killRDBChild(void) {
kill(server.child_pid, SIGUSR1); kill(server.child_pid, SIGUSR1);
/* Because we are not using here wait4 (like we have in killAppendOnlyChild /* Because we are not using here waitpid (like we have in killAppendOnlyChild
* and TerminateModuleForkChild), all the cleanup operations is done by * and TerminateModuleForkChild), all the cleanup operations is done by
* checkChildrenDone, that later will find that the process killed. * checkChildrenDone, that later will find that the process killed.
* This includes: * This includes:
......
...@@ -904,7 +904,7 @@ void sentinelCollectTerminatedScripts(void) { ...@@ -904,7 +904,7 @@ void sentinelCollectTerminatedScripts(void) {
int statloc; int statloc;
pid_t pid; pid_t pid;
while ((pid = wait3(&statloc,WNOHANG,NULL)) > 0) { while ((pid = waitpid(-1, &statloc, WNOHANG)) > 0) {
int exitcode = WEXITSTATUS(statloc); int exitcode = WEXITSTATUS(statloc);
int bysignal = 0; int bysignal = 0;
listNode *ln; listNode *ln;
...@@ -916,7 +916,7 @@ void sentinelCollectTerminatedScripts(void) { ...@@ -916,7 +916,7 @@ void sentinelCollectTerminatedScripts(void) {
ln = sentinelGetScriptListNodeByPid(pid); ln = sentinelGetScriptListNodeByPid(pid);
if (ln == NULL) { if (ln == NULL) {
serverLog(LL_WARNING,"wait3() returned a pid (%ld) we can't find in our scripts execution queue!", (long)pid); serverLog(LL_WARNING,"waitpid() returned a pid (%ld) we can't find in our scripts execution queue!", (long)pid);
continue; continue;
} }
sj = ln->value; sj = ln->value;
......
...@@ -1928,11 +1928,11 @@ void updateCachedTime(int update_daylight_info) { ...@@ -1928,11 +1928,11 @@ void updateCachedTime(int update_daylight_info) {
} }
void checkChildrenDone(void) { void checkChildrenDone(void) {
int statloc; int statloc = 0;
pid_t pid; pid_t pid;
if ((pid = wait3(&statloc,WNOHANG,NULL)) != 0) { if ((pid = waitpid(-1, &statloc, WNOHANG)) != 0) {
int exitcode = WEXITSTATUS(statloc); int exitcode = WIFEXITED(statloc) ? WEXITSTATUS(statloc) : -1;
int bysignal = 0; int bysignal = 0;
if (WIFSIGNALED(statloc)) bysignal = WTERMSIG(statloc); if (WIFSIGNALED(statloc)) bysignal = WTERMSIG(statloc);
...@@ -1940,15 +1940,14 @@ void checkChildrenDone(void) { ...@@ -1940,15 +1940,14 @@ void checkChildrenDone(void) {
/* sigKillChildHandler catches the signal and calls exit(), but we /* sigKillChildHandler catches the signal and calls exit(), but we
* must make sure not to flag lastbgsave_status, etc incorrectly. * must make sure not to flag lastbgsave_status, etc incorrectly.
* We could directly terminate the child process via SIGUSR1 * We could directly terminate the child process via SIGUSR1
* without handling it, but in this case Valgrind will log an * without handling it */
* annoying error. */
if (exitcode == SERVER_CHILD_NOERROR_RETVAL) { if (exitcode == SERVER_CHILD_NOERROR_RETVAL) {
bysignal = SIGUSR1; bysignal = SIGUSR1;
exitcode = 1; exitcode = 1;
} }
if (pid == -1) { if (pid == -1) {
serverLog(LL_WARNING,"wait3() returned an error: %s. " serverLog(LL_WARNING,"waitpid() returned an error: %s. "
"child_type: %s, child_pid = %d", "child_type: %s, child_pid = %d",
strerror(errno), strerror(errno),
strChildType(server.child_type), strChildType(server.child_type),
......
...@@ -722,7 +722,7 @@ start_server {tags {"repl"}} { ...@@ -722,7 +722,7 @@ start_server {tags {"repl"}} {
test "diskless replication child being killed is collected" { test "diskless replication child being killed is collected" {
# when diskless master is waiting for the replica to become writable # when diskless master is waiting for the replica to become writable
# it removes the read event from the rdb pipe so if the child gets killed # it removes the read event from the rdb pipe so if the child gets killed
# the replica will hung. and the master may not collect the pid with wait3 # the replica will hung. and the master may not collect the pid with waitpid
start_server {tags {"repl"}} { start_server {tags {"repl"}} {
set master [srv 0 client] set master [srv 0 client]
set master_host [srv 0 host] set master_host [srv 0 host]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment