[Bug 268666] syslog(3) prints parent's pid after fork()

From: <bugzilla-noreply_at_freebsd.org>
Date: Sat, 31 Dec 2022 10:16:09 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=268666

            Bug ID: 268666
           Summary: syslog(3) prints parent's pid after fork()
           Product: Base System
           Version: 12.4-RELEASE
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Many People
          Priority: ---
         Component: bin
          Assignee: bugs@FreeBSD.org
          Reporter: fjo@ogris.de

$ cat t.c
#include <unistd.h>
#include <syslog.h>
int main()
{
  openlog("test", LOG_PERROR, LOG_USER);
  syslog(LOG_INFO, "before fork: %d\n", getpid());
  fork();
  syslog(LOG_INFO, "after fork:  %d\n", getpid());
  return 0;
}
$ cc -o t t.c

On 12.4-RELEASE (note last line):
$ ./t
test 55317 - - before fork: 55317
test 55317 - - after fork:  55317
test 55317 - - after fork:  55318

On 13.1-RELEASE-p3:
$ ./t
test 16590 - - before fork: 16590
test 16590 - - after fork:  16590
test 16591 - - after fork:  16591

Suggested fix for 12.4: Make LogPid a local variable inside vsyslog1(), let
parse_tag() return either the parsed pid or -1, and assign LogPid either that
return value or getpid().

-- 
You are receiving this mail because:
You are the assignee for the bug.