From d4cede0234fb8523e34fea43ae58ebb8f461d835 Mon Sep 17 00:00:00 2001 From: Egor Ignatov Date: Wed, 12 Jul 2023 18:54:00 +0300 Subject: [PATCH] daemon: fix pid value by using getpid() in the child process Previously ctx.pid was getting it's value indirectly from fork(), which is always zero in the child process. Fixed a bug introduced in 2b3ca2b. Signed-off-by: Egor Ignatov --- src/daemon.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/daemon.c b/src/daemon.c index d66dd50..0c81aa7 100644 --- a/src/daemon.c +++ b/src/daemon.c @@ -1191,10 +1191,8 @@ daemonize(cms_context *cms_ctx, char *certdir, int do_fork) sleep(2); return 0; } - ctx.pid = pid; - } else { - ctx.pid = getpid(); } + ctx.pid = getpid(); write_pid_file(ctx.pid); ctx.backup_cms->log(ctx.backup_cms, ctx.priority|LOG_NOTICE, "pesignd starting (pid %d)", ctx.pid);