SCCS-vsn: usr.sbin/lpr/lpd/lpd.c 4.8
SCCS-vsn: usr.sbin/lpr/lpd/printjob.c 4.12
-static char sccsid[] = "@(#)lpd.c 4.7 (Berkeley) %G%";
+static char sccsid[] = "@(#)lpd.c 4.8 (Berkeley) %G%";
(void) close(f);
}
#endif
(void) close(f);
}
#endif
-#define mask(s) (1 << ((s) - 1))
-#define ALLINTS mask(SIGHUP)|mask(SIGINT)|mask(SIGQUIT)|mask(SIGTERM)
- omask = sigblock(ALLINTS);
- signal(SIGHUP, cleanup);
- signal(SIGINT, cleanup);
- signal(SIGQUIT, cleanup);
- signal(SIGTERM, cleanup);
signal(SIGCHLD, reapchild);
(void) umask(0);
/*
signal(SIGCHLD, reapchild);
(void) umask(0);
/*
logerr("socket");
exit(1);
}
logerr("socket");
exit(1);
}
+#define mask(s) (1 << ((s) - 1))
+ omask = sigblock(mask(SIGHUP)|mask(SIGINT)|mask(SIGQUIT)|mask(SIGTERM));
+ signal(SIGHUP, cleanup);
+ signal(SIGINT, cleanup);
+ signal(SIGQUIT, cleanup);
+ signal(SIGTERM, cleanup);
sun.sun_family = AF_UNIX;
strcpy(sun.sun_path, SOCKETNAME);
if (bind(funix, &sun, strlen(sun.sun_path) + 2) < 0) {
sun.sun_family = AF_UNIX;
strcpy(sun.sun_path, SOCKETNAME);
if (bind(funix, &sun, strlen(sun.sun_path) + 2) < 0) {
exit(1);
}
sigsetmask(omask);
exit(1);
}
sigsetmask(omask);
+ defreadfds = 1 << funix;
+ listen(funix, 5);
finet = socket(AF_INET, SOCK_STREAM, 0);
if (finet >= 0) {
struct servent *sp;
finet = socket(AF_INET, SOCK_STREAM, 0);
if (finet >= 0) {
struct servent *sp;
logerr("internet domain bind");
cleanup();
}
logerr("internet domain bind");
cleanup();
}
- }
- /*
- * Main loop: listen, accept, do a request, continue.
- */
- defreadfds = 1 << funix;
- listen(funix, 5);
- if (finet >= 0) {
defreadfds |= 1 << finet;
listen(finet, 5);
}
defreadfds |= 1 << finet;
listen(finet, 5);
}
+ /*
+ * Main loop: accept, do a request, continue.
+ */
for (;;) {
int domain, nfds, s, readfds = defreadfds;
for (;;) {
int domain, nfds, s, readfds = defreadfds;
+ if (lflag)
+ log("cleanup()");
unlink(SOCKETNAME);
exit(0);
}
unlink(SOCKETNAME);
exit(0);
}
-static char sccsid[] = "@(#)printjob.c 4.11 (Berkeley) %G%";
+static char sccsid[] = "@(#)printjob.c 4.12 (Berkeley) %G%";
static int child; /* id of any filters */
static int ofilter; /* id of output filter, if any */
static int tof; /* true if at top of form */
static int child; /* id of any filters */
static int ofilter; /* id of output filter, if any */
static int tof; /* true if at top of form */
+static int count; /* Number of files actually printed */
static int remote; /* true if sending files to remote */
static int remote; /* true if sending files to remote */
+static char fromhost[32]; /* user's host machine */
static char logname[32]; /* user's login name */
static char jobname[32]; /* job or file name */
static char class[32]; /* classification field */
static char logname[32]; /* user's login name */
static char jobname[32]; /* job or file name */
static char class[32]; /* classification field */
}
if (stat(LO, &stb) == 0 && (stb.st_mode & 0100))
exit(0); /* printing disabled */
}
if (stat(LO, &stb) == 0 && (stb.st_mode & 0100))
exit(0); /* printing disabled */
- lfd = open(LO, O_WRONLY|O_CREAT|O_TRUNC, 0644);
+ lfd = open(LO, O_WRONLY|O_CREAT, 0644);
if (lfd < 0) {
log("cannot create %s", LO);
exit(1);
if (lfd < 0) {
log("cannot create %s", LO);
exit(1);
- /*
- * Check to see if we should try reprinting the job.
- */
- if (i > 0) {
+ if (i == 0) /* file ok and printed */
+ count++;
+ else if (i > 0) { /* try reprinting the job */
log("restarting");
if (ofilter > 0) {
kill(ofilter, SIGCONT); /* to be sure */
log("restarting");
if (ofilter > 0) {
kill(ofilter, SIGCONT); /* to be sure */
}
if (nitems == 0) { /* no more work to do */
done:
}
if (nitems == 0) { /* no more work to do */
done:
- if (!SF && !tof)
- (void) write(ofd, FF, strlen(FF));
- if (TR != NULL) /* output trailer */
- (void) write(ofd, TR, strlen(TR));
+ if (count > 0) { /* Files actually printed */
+ if (!SF && !tof)
+ (void) write(ofd, FF, strlen(FF));
+ if (TR != NULL) /* output trailer */
+ (void) write(ofd, TR, strlen(TR));
+ }
while (getline(cfp))
switch (line[0]) {
case 'H':
while (getline(cfp))
switch (line[0]) {
case 'H':
+ strcpy(fromhost, line+1);
if (class[0] == '\0')
strcpy(class, line+1);
continue;
if (class[0] == '\0')
strcpy(class, line+1);
continue;
*/
(void) fclose(cfp);
(void) unlink(file);
*/
(void) fclose(cfp);
(void) unlink(file);
+ return(bombed ? -1 : 0);
av[n++] = "-n";
av[n++] = logname;
av[n++] = "-h";
av[n++] = "-n";
av[n++] = logname;
av[n++] = "-h";
av[n++] = AF;
av[n] = 0;
fo = pfd;
av[n++] = AF;
av[n] = 0;
fo = pfd;
- sprintf(buf, "%s@%s", line+1, host);
+ sprintf(buf, "%s@%s", line+1, fromhost);
execl(MAIL, cp, buf, 0);
exit(0);
} else if (stat > 0) { /* parent */
dup2(p[1], 1);
execl(MAIL, cp, buf, 0);
exit(0);
} else if (stat > 0) { /* parent */
dup2(p[1], 1);
- printf("To: %s\n", line+1);
+ printf("To: %s@%s\n", line+1, fromhost);
printf("Subject: printer job\n\n");
printf("Your printer job ");
if (*jobname)
printf("Subject: printer job\n\n");
printf("Your printer job ");
if (*jobname)