Skip to content

Commit

Permalink
Fix log printing always shows the role as child under daemonize (#1301)
Browse files Browse the repository at this point in the history
In #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. It also causes a
incorrect server.pid value, affecting the concatenation of
some pid names.

Signed-off-by: Binbin <[email protected]>
  • Loading branch information
enjoy-binbin authored Nov 14, 2024
1 parent 2df56d8 commit 6fba747
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 6fba747

Please sign in to comment.