Skip to content

Commit

Permalink
Fix log printing always shows the role as child under daemonize
Browse files Browse the repository at this point in the history
In valkey-io#1282, we init server.pid earlier to keep log message role
consistent, but we forgot to consider daemonize. In daemonize
mode, we will always print the child role.

We need to reset server.pid after daemonize(), otherwise the
log printing role will always be the child.

Signed-off-by: Binbin <binloveplay1314@qq.com>
  • Loading branch information
enjoy-binbin committed Nov 13, 2024
1 parent 2df56d8 commit 0a98333
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -7064,7 +7064,12 @@ __attribute__((weak)) int main(int argc, char **argv) {
/* Daemonize if needed */
server.supervised = serverIsSupervised(server.supervised_mode);
int background = server.daemonize && !server.supervised;
if (background) daemonize();
if (background) {
/* We need to reset server.pid after daemonize(), otherwise the
* log printing role will always be the child. */
daemonize();
server.pid = getpid();
}

serverLog(LL_NOTICE, "oO0OoO0OoO0Oo Valkey is starting oO0OoO0OoO0Oo");
serverLog(LL_NOTICE, "Valkey version=%s, bits=%d, commit=%s, modified=%d, pid=%d, just started", VALKEY_VERSION,
Expand Down

0 comments on commit 0a98333

Please sign in to comment.