summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr.sbin/lpr/SMM.doc/7.t4
-rw-r--r--usr.sbin/lpr/common_source/pathnames.h3
-rw-r--r--usr.sbin/lpr/lpd/lpd.87
-rw-r--r--usr.sbin/lpr/lpd/lpd.c61
4 files changed, 24 insertions, 51 deletions
diff --git a/usr.sbin/lpr/SMM.doc/7.t b/usr.sbin/lpr/SMM.doc/7.t
index 4ed0c1cdf3b..20370d15e1c 100644
--- a/usr.sbin/lpr/SMM.doc/7.t
+++ b/usr.sbin/lpr/SMM.doc/7.t
@@ -1,4 +1,4 @@
-.\" $OpenBSD: 7.t,v 1.5 2003/06/02 23:36:53 millert Exp $
+.\" $OpenBSD: 7.t,v 1.6 2015/10/28 13:25:55 millert Exp $
.\"
.\" Copyright (c) 1983, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -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
diff --git a/usr.sbin/lpr/common_source/pathnames.h b/usr.sbin/lpr/common_source/pathnames.h
index 92bc6e43cc8..6cd87d7a645 100644
--- a/usr.sbin/lpr/common_source/pathnames.h
+++ b/usr.sbin/lpr/common_source/pathnames.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: pathnames.h,v 1.5 2014/04/20 22:35:10 ajacoutot Exp $ */
+/* $OpenBSD: pathnames.h,v 1.6 2015/10/28 13:25:55 millert Exp $ */
/* $NetBSD: pathnames.h,v 1.5 1995/11/28 19:43:27 jtc Exp $ */
/*
@@ -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"
diff --git a/usr.sbin/lpr/lpd/lpd.8 b/usr.sbin/lpr/lpd/lpd.8
index 9db496434ca..b0da89c7db6 100644
--- a/usr.sbin/lpr/lpd/lpd.8
+++ b/usr.sbin/lpr/lpd/lpd.8
@@ -1,4 +1,4 @@
-.\" $OpenBSD: lpd.8,v 1.27 2015/09/12 15:17:11 schwarze Exp $
+.\" $OpenBSD: lpd.8,v 1.28 2015/10/28 13:25:55 millert Exp $
.\" $NetBSD: lpd.8,v 1.23 2002/02/08 01:38:50 ross Exp $
.\"
.\" Copyright (c) 1983, 1991, 1993
@@ -30,7 +30,7 @@
.\"
.\" @(#)lpd.8 8.3 (Berkeley) 4/19/94
.\"
-.Dd $Mdocdate: September 12 2015 $
+.Dd $Mdocdate: October 28 2015 $
.Dt LPD 8
.Os
.Sh NAME
@@ -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
diff --git a/usr.sbin/lpr/lpd/lpd.c b/usr.sbin/lpr/lpd/lpd.c
index 17985c8cf06..c457d41c6f8 100644
--- a/usr.sbin/lpr/lpd/lpd.c
+++ b/usr.sbin/lpr/lpd/lpd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: lpd.c,v 1.61 2015/10/27 15:23:28 millert Exp $ */
+/* $OpenBSD: lpd.c,v 1.62 2015/10/28 13:25:55 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);
}