NetBSD Problem Report #27309
From gnats-bugs-owner-gnats=mail-index.netbsd.org@gnats.NetBSD.org Thu Oct 21 15:07:57 2004
Return-Path: <gnats-bugs-owner-gnats=mail-index.netbsd.org@gnats.NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [204.152.190.11])
by narn.netbsd.org (Postfix) with SMTP id 3B258251ED6
for <gnats@www.netbsd.org>; Thu, 21 Oct 2004 15:07:57 +0000 (UTC)
Message-Id: <20041021150755.4370E548E98@dogfish-head.cs.stevens.edu>
Date: Thu, 21 Oct 2004 11:07:55 -0400 (EDT)
From: jschauma@stevens-tech.edu
Reply-To: jschauma@stevens-tech.edu
To: gnats-bugs@gnats.NetBSD.org
Subject: syslogd -u can't create pidfile
X-Send-Pr-Version: 3.95
>Number: 27309
>Category: bin
>Synopsis: syslogd -u can't create pidfile
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: bin-bug-people
>State: closed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Fri Oct 22 08:47:01 +0000 2004
>Closed-Date: Sat Nov 09 16:17:20 +0000 2024
>Last-Modified: Sat Nov 09 16:17:20 +0000 2024
>Originator: Jan Schaumann
>Release: NetBSD 2.0_RC3
>Organization:
>Environment:
System: NetBSD dogfish-head.cs.stevens.edu 2.0_RC3 NetBSD 2.0_RC3 (BOCK) #20: Mon Oct 4 14:19:22 EDT 2004 jschauma@doppelbock.hpcf.cs.stevens-tech.edu:/share/src/sys/arch/i386/compile/obj/BOCK i386
Architecture: i386
Machine: i386
>Description:
When starting syslogd(8) with the '-u' option, syslogd will be unable
to create the standard pidfile, as it changes UID and the user likely
does not have write permission to /var/run/.
>How-To-Repeat:
Add:
syslogd=YES
syslogd_flags="-u syslogd -g syslogd"
to /etc/rc.conf
/etc/rc.d/syslogd restart
syslogd not running? (check /var/run/syslogd.pid).
Starting syslogd.
ls /var/run/syslogd.pid
ls: /var/run/syslogd.pid: No such file or directory
ps ax | grep sysl
8461 ?? Ss 0:00.00 /usr/sbin/syslogd -u syslogd -g syslogd
/etc/rc.d/syslogd restart
syslogd not running? (check /var/run/syslogd.pid).
Starting syslogd.
syslogd: bind() failed: Address already in use
syslogd: Fatal error, exiting
>Fix:
Well, create pidfile before changing UID. However, there seems
to be a problem: syslogd.c around #464 indicates that we can't
daemonize until we're sure we don't get any fatal errors. So we
can't daemonize until we've changed UID. We can't create the pidfile
before daemonizing, obviously, either.
>Release-Note:
>Audit-Trail:
From: Jan Schaumann <jschauma@netmeister.org>
To: gnats-bugs@netbsd.org
Cc:
Subject: Re: bin/27309
Date: Thu, 7 Nov 2024 21:36:23 -0500
Stumbling upon this old bug from (double-checks
creation date) 20 years ago, I figured I'd take a stab
at addressing it:
Index: syslogd.c
===================================================================
RCS file: /cvsroot/src/usr.sbin/syslogd/syslogd.c,v
retrieving revision 1.145
diff -u -p -b -u -r1.145 syslogd.c
--- syslogd.c 8 Nov 2024 02:23:54 -0000 1.145
+++ syslogd.c 8 Nov 2024 02:30:20 -0000
@@ -316,6 +316,7 @@ main(int argc, char *argv[])
struct group *gr;
struct passwd *pw;
unsigned long l;
++ char pfpath[PATH_MAX];
/* should we set LC_TIME="C" to ensure correct timestamps&parsing? */
(void)setlocale(LC_ALL, "");
@@ -564,6 +565,33 @@ getgroup:
LOG_NFACILITIES, IETF_NUM_PRIVALUES>>3);
#endif
+#ifdef __NetBSD_Version__
+ if ((uid != 0) || (gid != 0)) {
+ /* Create the pidfile here so we can chown it to the target
+ * user/group and possibly report any error before daemonizing.
+ * We then call pidfile(3) again to write the actual
+ * daemon pid below.
+ *
+ * Note: this will likely leave the truncated pidfile in
+ * place upon exit, since the effective user is unlikely
+ * to have write permissions to _PATH_VARRUN. */
+ if (pidfile(NULL)) {
+ logerror("Failed to create pidfile");
+ die(0, 0, NULL);
+ }
+ l = sizeof(pfpath);
+ if ((size_t)snprintf(pfpath, l, "%s%s.pid",
+ _PATH_VARRUN, getprogname()) >= l) {
+ logerror("Pidfile path `%s' too long.", pfpath);
+ die(0, 0, NULL);
+ }
+ if (chown(pfpath, uid, gid) < 0) {
+ logerror("Failed to chown pidfile `%s` to `%d:%d`", pfpath, uid, gid);
+ die(0, 0, NULL);
+ }
+ }
+#endif /* __NetBSD_Version__ */
+
/*
* All files are open, we can drop privileges and chroot.
*/
State-Changed-From-To: open->closed
State-Changed-By: jschauma@NetBSD.org
State-Changed-When: Sat, 09 Nov 2024 16:17:20 +0000
State-Changed-Why:
Fixed in rev1.146 of syslogd.c.
>Unformatted:
>Quarter:
>Keywords:
>Date-Required:
(Contact us)
$NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.