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.
This commit is contained in:
parent
d2ed7ebdd1
commit
2b3b2f08d6
@ -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
|
* Copyright (c) 1983, 1993
|
||||||
@ -45,7 +45,7 @@ __COPYRIGHT("@(#) Copyright (c) 1983, 1993\n\
|
|||||||
#if 0
|
#if 0
|
||||||
static char sccsid[] = "@(#)printjob.c 8.7 (Berkeley) 5/10/95";
|
static char sccsid[] = "@(#)printjob.c 8.7 (Berkeley) 5/10/95";
|
||||||
#else
|
#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
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
@ -150,17 +150,24 @@ printjob(void)
|
|||||||
struct stat stb;
|
struct stat stb;
|
||||||
struct queue *q, **qp;
|
struct queue *q, **qp;
|
||||||
struct queue **queue;
|
struct queue **queue;
|
||||||
int i, nitems;
|
int i, nitems, fd;
|
||||||
off_t pidoff;
|
off_t pidoff;
|
||||||
int errcnt, count = 0;
|
int errcnt, count = 0;
|
||||||
|
|
||||||
init(); /* set up capabilities */
|
init(); /* set up capabilities */
|
||||||
(void)write(STDOUT_FILENO, "", 1); /* ack that daemon is started */
|
(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) {
|
/* set up log file */
|
||||||
|
if ((fd = open(LF, O_WRONLY|O_APPEND, 0664)) < 0) {
|
||||||
syslog(LOG_ERR, "%s: %m", LF);
|
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());
|
setgid(getegid());
|
||||||
pid = getpid(); /* for use with lprm */
|
pid = getpid(); /* for use with lprm */
|
||||||
setpgrp(0, pid);
|
setpgrp(0, pid);
|
||||||
|
@ -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
|
* Copyright (c) 1983, 1993
|
||||||
@ -45,7 +45,7 @@ __COPYRIGHT("@(#) Copyright (c) 1983, 1993\n\
|
|||||||
#if 0
|
#if 0
|
||||||
static char sccsid[] = "@(#)recvjob.c 8.2 (Berkeley) 4/27/95";
|
static char sccsid[] = "@(#)recvjob.c 8.2 (Berkeley) 4/27/95";
|
||||||
#else
|
#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
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
@ -91,7 +91,7 @@ void
|
|||||||
recvjob(void)
|
recvjob(void)
|
||||||
{
|
{
|
||||||
struct stat stb;
|
struct stat stb;
|
||||||
int status;
|
int status, fd;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Perform lookup for printer name or abbreviation
|
* Perform lookup for printer name or abbreviation
|
||||||
@ -110,11 +110,16 @@ recvjob(void)
|
|||||||
if (cgetstr(bp, "lo", &LO) == -1)
|
if (cgetstr(bp, "lo", &LO) == -1)
|
||||||
LO = DEFLOCK;
|
LO = DEFLOCK;
|
||||||
|
|
||||||
(void)close(2); /* set up log file */
|
/* Set up the log file. */
|
||||||
if (open(LF, O_WRONLY|O_APPEND, 0664) < 0) {
|
if ((fd = open(LF, O_WRONLY|O_APPEND, 0664)) < 0) {
|
||||||
syslog(LOG_ERR, "%s: %m", LF);
|
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)
|
if (chdir(SD) < 0)
|
||||||
frecverr("%s: %s: %m", printer, SD);
|
frecverr("%s: %s: %m", printer, SD);
|
||||||
|
Loading…
Reference in New Issue
Block a user