Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.sbin/lpr/lpd Rather than relying on pure luck to get the...
details: https://anonhg.NetBSD.org/src/rev/e16a65c392fb
branches: trunk
changeset: 538696:e16a65c392fb
user: thorpej <thorpej%NetBSD.org@localhost>
date: Sat Oct 26 01:47:52 2002 +0000
description:
Rather than relying on pure luck to get the log file on STDERR_FILENO,
explictly dup2 the log file dscriptor to STDERR_FILENO and close the
original.
diffstat:
usr.sbin/lpr/lpd/printjob.c | 21 ++++++++++++++-------
usr.sbin/lpr/lpd/recvjob.c | 17 +++++++++++------
2 files changed, 25 insertions(+), 13 deletions(-)
diffs (95 lines):
diff -r 308ab4654956 -r e16a65c392fb usr.sbin/lpr/lpd/printjob.c
--- a/usr.sbin/lpr/lpd/printjob.c Sat Oct 26 01:46:31 2002 +0000
+++ b/usr.sbin/lpr/lpd/printjob.c Sat Oct 26 01:47:52 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: printjob.c,v 1.36 2002/09/04 13:49:20 abs Exp $ */
+/* $NetBSD: printjob.c,v 1.37 2002/10/26 01:47:52 thorpej Exp $ */
/*
* Copyright (c) 1983, 1993
@@ -45,7 +45,7 @@
#if 0
static char sccsid[] = "@(#)printjob.c 8.7 (Berkeley) 5/10/95";
#else
-__RCSID("$NetBSD: printjob.c,v 1.36 2002/09/04 13:49:20 abs Exp $");
+__RCSID("$NetBSD: printjob.c,v 1.37 2002/10/26 01:47:52 thorpej Exp $");
#endif
#endif /* not lint */
@@ -150,17 +150,24 @@
struct stat stb;
struct queue *q, **qp;
struct queue **queue;
- int i, nitems;
+ int i, nitems, fd;
off_t pidoff;
int errcnt, count = 0;
init(); /* set up capabilities */
- (void)write(STDOUT_FILENO, "", 1); /* ack that daemon is started */
- (void)close(STDERR_FILENO); /* set up log file */
- if (open(LF, O_WRONLY|O_APPEND, 0664) < 0) {
+ (void)write(STDOUT_FILENO, "", 1); /* ack that daemon is started */
+
+ /* set up log file */
+ if ((fd = open(LF, O_WRONLY|O_APPEND, 0664)) < 0) {
syslog(LOG_ERR, "%s: %m", LF);
- (void)open(_PATH_DEVNULL, O_WRONLY);
+ fd = open(_PATH_DEVNULL, O_WRONLY);
}
+ if (fd > 0) {
+ (void) dup2(fd, STDERR_FILENO);
+ (void) close(fd);
+ } else
+ (void)close(STDERR_FILENO);
+
setgid(getegid());
pid = getpid(); /* for use with lprm */
setpgrp(0, pid);
diff -r 308ab4654956 -r e16a65c392fb usr.sbin/lpr/lpd/recvjob.c
--- a/usr.sbin/lpr/lpd/recvjob.c Sat Oct 26 01:46:31 2002 +0000
+++ b/usr.sbin/lpr/lpd/recvjob.c Sat Oct 26 01:47:52 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: recvjob.c,v 1.16 2002/07/14 15:28:00 wiz Exp $ */
+/* $NetBSD: recvjob.c,v 1.17 2002/10/26 01:47:52 thorpej Exp $ */
/*
* Copyright (c) 1983, 1993
@@ -45,7 +45,7 @@
#if 0
static char sccsid[] = "@(#)recvjob.c 8.2 (Berkeley) 4/27/95";
#else
-__RCSID("$NetBSD: recvjob.c,v 1.16 2002/07/14 15:28:00 wiz Exp $");
+__RCSID("$NetBSD: recvjob.c,v 1.17 2002/10/26 01:47:52 thorpej Exp $");
#endif
#endif /* not lint */
@@ -91,7 +91,7 @@
recvjob(void)
{
struct stat stb;
- int status;
+ int status, fd;
/*
* Perform lookup for printer name or abbreviation
@@ -110,11 +110,16 @@
if (cgetstr(bp, "lo", &LO) == -1)
LO = DEFLOCK;
- (void)close(2); /* set up log file */
- if (open(LF, O_WRONLY|O_APPEND, 0664) < 0) {
+ /* Set up the log file. */
+ if ((fd = open(LF, O_WRONLY|O_APPEND, 0664)) < 0) {
syslog(LOG_ERR, "%s: %m", LF);
- (void)open(_PATH_DEVNULL, O_WRONLY);
+ fd = open(_PATH_DEVNULL, O_WRONLY);
}
+ if (fd > 0) {
+ (void) dup2(fd, STDERR_FILENO);
+ (void) close(fd);
+ } else
+ (void) close(STDERR_FILENO);
if (chdir(SD) < 0)
frecverr("%s: %s: %m", printer, SD);
Home |
Main Index |
Thread Index |
Old Index