summaryrefslogtreecommitdiff
path: root/usr.sbin/lpr/lpd
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>1996-11-03 23:24:14 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>1996-11-03 23:24:14 +0000
commitd72e5b4dcb4aa82963fd3ce24000a3197269442f (patch)
treee787b78982c67b5d53ce5899cd0f71510b2624cc /usr.sbin/lpr/lpd
parente0ef2b64c7bd3c27ea81ce04d46444656105a9c6 (diff)
Improve portability by using ANSI/POSIX interfaces when possible.
Diffstat (limited to 'usr.sbin/lpr/lpd')
-rw-r--r--usr.sbin/lpr/lpd/lpd.c12
-rw-r--r--usr.sbin/lpr/lpd/printjob.c36
-rw-r--r--usr.sbin/lpr/lpd/recvjob.c2
3 files changed, 27 insertions, 23 deletions
diff --git a/usr.sbin/lpr/lpd/lpd.c b/usr.sbin/lpr/lpd/lpd.c
index 973346682a6..a9780fe2285 100644
--- a/usr.sbin/lpr/lpd/lpd.c
+++ b/usr.sbin/lpr/lpd/lpd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: lpd.c,v 1.10 1996/10/26 12:33:41 deraadt Exp $ */
+/* $OpenBSD: lpd.c,v 1.11 1996/11/03 23:24:08 millert Exp $ */
/* $NetBSD: lpd.c,v 1.7 1996/04/24 14:54:06 mrg Exp $ */
/*
@@ -126,7 +126,11 @@ main(argc, argv)
uid = getuid();
options = 0;
gethostname(host, sizeof(host));
- name = argv[0];
+
+ if (euid != 0) {
+ fprintf(stderr,"lpd: must run as root\n");
+ exit(1);
+ }
while (--argc > 0) {
argv++;
@@ -289,9 +293,9 @@ static void
reapchild(signo)
int signo;
{
- union wait status;
+ int status;
- while (wait3((int *)&status, WNOHANG, 0) > 0)
+ while (waitpid((pid_t)-1, &status, WNOHANG) > 0)
;
}
diff --git a/usr.sbin/lpr/lpd/printjob.c b/usr.sbin/lpr/lpd/printjob.c
index 21370f43bd9..5c15e12b6fb 100644
--- a/usr.sbin/lpr/lpd/printjob.c
+++ b/usr.sbin/lpr/lpd/printjob.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: printjob.c,v 1.9 1996/10/25 19:38:23 deraadt Exp $ */
+/* $OpenBSD: printjob.c,v 1.10 1996/11/03 23:24:10 millert Exp $ */
/* $NetBSD: printjob.c,v 1.9.4.3 1996/07/12 22:31:39 jtc Exp $ */
/*
@@ -266,7 +266,7 @@ again:
syslog(LOG_WARNING, "%s: job could not be %s (%s)", printer,
remote ? "sent to remote host" : "printed", q->q_name);
if (i == REPRINT) {
- /* insure we don't attempt this job again */
+ /* ensure we don't attempt this job again */
(void) unlink(q->q_name);
q->q_name[0] = 'd';
(void) unlink(q->q_name);
@@ -574,7 +574,7 @@ print(format, file)
dup2(fi, 0); /* file is stdin */
dup2(p[1], 1); /* pipe is stdout */
closelog();
- for (n = 3, nofile = getdtablesize(); n < nofile; n++)
+ for (n = 3, nofile = sysconf(_SC_OPEN_MAX); n < nofile; n++)
(void) close(n);
execl(_PATH_PR, "pr", width, length,
"-h", *title ? title : " ", 0);
@@ -663,7 +663,7 @@ print(format, file)
printer, format);
return(ERROR);
}
- if ((av[0] = rindex(prog, '/')) != NULL)
+ if ((av[0] = strrchr(prog, '/')) != NULL)
av[0]++;
else
av[0] = prog;
@@ -676,14 +676,14 @@ print(format, file)
fo = pfd;
if (ofilter > 0) { /* stop output filter */
write(ofd, "\031\1", 2);
- while ((pid =
- wait3((int *)&status, WUNTRACED, 0)) > 0 && pid != ofilter)
+ while ((pid = waitpid((pid_t)-1, (int *)&status, WUNTRACED)) > 0
+ && pid != ofilter)
;
if (status.w_stopval != WSTOPPED) {
(void) close(fi);
syslog(LOG_WARNING,
- "%s: output filter died (retcode=%d termsig=%d)",
- printer, status.w_retcode, status.w_termsig);
+ "%s: output filter died (retcode=%d termsig=%d)",
+ printer, status.w_retcode, status.w_termsig);
return(REPRINT);
}
stopped++;
@@ -696,7 +696,7 @@ start:
if (n >= 0)
dup2(n, 2);
closelog();
- for (n = 3, nofile = getdtablesize(); n < nofile; n++)
+ for (n = 3, nofile = sysconf(_SC_OPEN_MAX); n < nofile; n++)
(void) close(n);
execv(prog, av);
syslog(LOG_ERR, "cannot execv %s", prog);
@@ -889,9 +889,6 @@ sendfile(type, file)
}
}
-
-
-
(void) close(f);
if (sizerr) {
syslog(LOG_INFO, "%s: %s: changed size", printer, file);
@@ -1057,9 +1054,9 @@ sendmail(user, bombed)
if ((s = dofork(DORETURN)) == 0) { /* child */
dup2(p[0], 0);
closelog();
- for (i = 3, nofile = getdtablesize(); i < nofile; i++)
+ for (i = 3, nofile = sysconf(_SC_OPEN_MAX); i < nofile; i++)
(void) close(i);
- if ((cp = rindex(_PATH_SENDMAIL, '/')) != NULL)
+ if ((cp = strrchr(_PATH_SENDMAIL, '/')) != NULL)
cp++;
else
cp = _PATH_SENDMAIL;
@@ -1266,7 +1263,7 @@ openpr()
char *cp;
if (!remote && *LP) {
- if (cp = index(LP, '@'))
+ if (cp = strchr(LP, '@'))
opennet(cp);
else
opentty();
@@ -1290,9 +1287,9 @@ openpr()
dup2(p[0], 0); /* pipe is std in */
dup2(pfd, 1); /* printer is std out */
closelog();
- for (i = 3, nofile = getdtablesize(); i < nofile; i++)
+ for (i = 3, nofile = sysconf(_SC_OPEN_MAX); i < nofile; i++)
(void) close(i);
- if ((cp = rindex(OF, '/')) == NULL)
+ if ((cp = strrchr(OF, '/')) == NULL)
cp = OF;
else
cp++;
@@ -1494,7 +1491,10 @@ setty()
p = strdup(MS);
ap = argv;
while ((val = strsep(&p, " \t,")) != NULL) {
- *ap++ = strdup(val);
+ if ((*ap++ = strdup(val)) == NULL) {
+ syslog(LOG_ERR, "%s: strdup: %m", printer);
+ exit(1);
+ }
}
for (; *argv; ++argv) {
diff --git a/usr.sbin/lpr/lpd/recvjob.c b/usr.sbin/lpr/lpd/recvjob.c
index ea2128cd31e..9af9e8bb89c 100644
--- a/usr.sbin/lpr/lpd/recvjob.c
+++ b/usr.sbin/lpr/lpd/recvjob.c
@@ -203,7 +203,7 @@ readjob()
}
(void) strncpy(dfname, cp, sizeof dfname-1);
dfname[sizeof dfname-1] = '\0';
- if (index(dfname, '/'))
+ if (strchr(dfname, '/'))
frecverr("readjob: %s: illegal path name",
dfname);
(void) readfile(dfname, size);