On Tue, 27 Oct 2015 14:28:51 +0100, Jan Stary wrote:
> $ find /var/run/ -name \*pid
> /var/run/syslog.pid
> /var/run/unbound.pid
> /var/run/lpd.pid
> /var/run/sshd.pid
> /var/run/smtpd.pid
> /var/run/cron.pid
>
> - should these stop using pidfiles too?
unbound and cron have already had the pidfile removed.
Below is a diff for lpd.
- todd
Index: usr.sbin/lpr/SMM.doc/7.t
===================================================================
RCS file: /cvs/src/usr.sbin/lpr/SMM.doc/7.t,v
retrieving revision 1.5
diff -u -p -u -r1.5 7.t
--- usr.sbin/lpr/SMM.doc/7.t 2 Jun 2003 23:36:53 -0000 1.5
+++ usr.sbin/lpr/SMM.doc/7.t 27 Oct 2015 15:28:56 -0000
@@ -74,7 +74,7 @@ restart
.DE
You can also check the state of the master printer daemon with the following.
.DS
-% ps l`cat /var/run/lpd.pid`
+% pgrep -l lpd
.DE
.IP
Another possibility is that the
Index: usr.sbin/lpr/common_source/pathnames.h
===================================================================
RCS file: /cvs/src/usr.sbin/lpr/common_source/pathnames.h,v
retrieving revision 1.5
diff -u -p -u -r1.5 pathnames.h
--- usr.sbin/lpr/common_source/pathnames.h 20 Apr 2014 22:35:10 -0000
1.5
+++ usr.sbin/lpr/common_source/pathnames.h 27 Oct 2015 15:28:56 -0000
@@ -37,7 +37,6 @@
#define _PATH_DEFDEVLP "/dev/lp"
#define _PATH_DEFSPOOL "/var/spool/output/lpd"
#define _PATH_HOSTSLPD "/etc/hosts.lpd"
-#define _PATH_MASTERLOCK "/var/run/lpd.pid"
#define _PATH_PR "/usr/bin/pr"
#define _PATH_PRINTCAP "/etc/printcap"
#define _PATH_SOCKETNAME "/var/run/printer"
Index: usr.sbin/lpr/lpd/lpd.8
===================================================================
RCS file: /cvs/src/usr.sbin/lpr/lpd/lpd.8,v
retrieving revision 1.27
diff -u -p -u -r1.27 lpd.8
--- usr.sbin/lpr/lpd/lpd.8 12 Sep 2015 15:17:11 -0000 1.27
+++ usr.sbin/lpr/lpd/lpd.8 27 Oct 2015 15:28:56 -0000
@@ -324,9 +324,6 @@ and
.Bl -tag -width "/var/spool/output/*/minfree" -compact
.It Pa /etc/printcap
printer description file
-.It Pa /var/run/lpd.pid
-lock file for
-.Nm
.It Pa /var/spool/output/*
spool directories
.It Pa /var/spool/output/*/minfree
Index: usr.sbin/lpr/lpd/lpd.c
===================================================================
RCS file: /cvs/src/usr.sbin/lpr/lpd/lpd.c,v
retrieving revision 1.61
diff -u -p -u -r1.61 lpd.c
--- usr.sbin/lpr/lpd/lpd.c 27 Oct 2015 15:23:28 -0000 1.61
+++ usr.sbin/lpr/lpd/lpd.c 27 Oct 2015 15:28:56 -0000
@@ -1,4 +1,4 @@
-/* $OpenBSD: lpd.c,v 1.61 2015/10/27 15:23:28 millert Exp $ */
+/* $OpenBSD: lpd.c,v 1.61 2015/10/27 15:23:28 millert Exp $ */
/* $NetBSD: lpd.c,v 1.33 2002/01/21 14:42:29 wiz Exp $ */
/*
@@ -122,7 +122,7 @@ main(int argc, char **argv)
struct sockaddr_un un, fromunix;
struct sockaddr_storage frominet;
sigset_t mask, omask;
- int lfd, i, f, funix, *finet;
+ int i, funix, *finet;
int options, maxfd;
long l;
long child_max = 32; /* more than enough to hose the system */
@@ -222,6 +222,23 @@ main(int argc, char **argv)
usage();
}
+ funix = socket(AF_UNIX, SOCK_STREAM, 0);
+ if (funix < 0)
+ err(1, "socket");
+ memset(&un, 0, sizeof(un));
+ un.sun_family = AF_UNIX;
+ strlcpy(un.sun_path, _PATH_SOCKETNAME, sizeof(un.sun_path));
+ PRIV_START;
+ if (connect(funix, (struct sockaddr *)&un, sizeof(un)) == 0)
+ errx(1, "already running");
+ if (errno != ENOENT)
+ (void)unlink(un.sun_path);
+ if (bind(funix, (struct sockaddr *)&un, sizeof(un)) < 0)
+ err(1, "bind %s", un.sun_path);
+ chmod(_PATH_SOCKETNAME, 0660);
+ chown(_PATH_SOCKETNAME, -1, real_gid);
+ PRIV_END;
+
#ifndef DEBUG
/*
* Set up standard environment by detaching from the parent.
@@ -232,38 +249,11 @@ main(int argc, char **argv)
openlog("lpd", LOG_PID, LOG_LPR);
syslog(LOG_INFO, "restarted");
(void)umask(0);
- PRIV_START;
- lfd = open(_PATH_MASTERLOCK, O_WRONLY|O_CREAT|O_EXLOCK|O_NONBLOCK,
0644);
- PRIV_END;
- if (lfd < 0) {
- if (errno == EWOULDBLOCK) /* active daemon present */
- exit(0);
- syslog(LOG_ERR, "%s: %m", _PATH_MASTERLOCK);
- exit(1);
- }
- ftruncate(lfd, 0);
- /*
- * write process id for others to know
- */
- (void)snprintf(line, sizeof(line), "%u\n", getpid());
- f = strlen(line);
- if (write(lfd, line, f) != f) {
- syslog(LOG_ERR, "%s: %m", _PATH_MASTERLOCK);
- exit(1);
- }
signal(SIGCHLD, reapchild);
/*
* Restart all the printers.
*/
startup();
- PRIV_START;
- (void)unlink(_PATH_SOCKETNAME);
- PRIV_END;
- funix = socket(AF_UNIX, SOCK_STREAM, 0);
- if (funix < 0) {
- syslog(LOG_ERR, "socket: %m");
- exit(1);
- }
sigemptyset(&mask);
sigaddset(&mask, SIGHUP);
@@ -276,18 +266,6 @@ main(int argc, char **argv)
signal(SIGINT, mcleanup);
signal(SIGQUIT, mcleanup);
signal(SIGTERM, mcleanup);
- memset(&un, 0, sizeof(un));
- un.sun_family = AF_UNIX;
- strlcpy(un.sun_path, _PATH_SOCKETNAME, sizeof(un.sun_path));
- PRIV_START;
- if (bind(funix, (struct sockaddr *)&un, sizeof(un)) < 0) {
- syslog(LOG_ERR, "ubind: %m");
- exit(1);
- }
- chmod(_PATH_SOCKETNAME, 0660);
- chown(_PATH_SOCKETNAME, -1, real_gid);
- PRIV_END;
- (void)umask(0); /* XXX */
sigprocmask(SIG_SETMASK, &omask, NULL);
FD_ZERO(&defreadfds);
FD_SET(funix, &defreadfds);
@@ -438,7 +416,6 @@ mcleanup(int signo)
syslog_r(LOG_INFO, &sdata, "exiting");
PRIV_START;
unlink(_PATH_SOCKETNAME);
- unlink(_PATH_MASTERLOCK);
_exit(0);
}