From adec4d9eb7b645e5d1096e4e18504a4b7dfa97a5 Mon Sep 17 00:00:00 2001 From: Sam Leffler Date: Wed, 15 Jun 1983 21:58:02 -0800 Subject: [PATCH] open and flock defines changed SCCS-vsn: usr.sbin/lpr/lpc/cmds.c 4.4 SCCS-vsn: usr.sbin/lpr/common_source/displayq.c 4.6 SCCS-vsn: usr.sbin/lpr/lpc/lpc.c 4.3 SCCS-vsn: usr.sbin/lpr/lpd/lpd.c 4.5 SCCS-vsn: usr.sbin/lpr/lpr/lpr.c 4.20 SCCS-vsn: usr.sbin/lpr/lpd/printjob.c 4.7 SCCS-vsn: usr.sbin/lpr/lpd/recvjob.c 4.4 SCCS-vsn: usr.sbin/lpr/common_source/rmjob.c 4.5 --- usr/src/usr.sbin/lpr/common_source/displayq.c | 8 +++-- usr/src/usr.sbin/lpr/common_source/rmjob.c | 4 +-- usr/src/usr.sbin/lpr/lpc/cmds.c | 18 +++++----- usr/src/usr.sbin/lpr/lpc/lpc.c | 4 +-- usr/src/usr.sbin/lpr/lpd/lpd.c | 35 +++++-------------- usr/src/usr.sbin/lpr/lpd/printjob.c | 22 +++++++----- usr/src/usr.sbin/lpr/lpd/recvjob.c | 6 ++-- usr/src/usr.sbin/lpr/lpr/lpr.c | 10 +++--- 8 files changed, 49 insertions(+), 58 deletions(-) diff --git a/usr/src/usr.sbin/lpr/common_source/displayq.c b/usr/src/usr.sbin/lpr/common_source/displayq.c index ee86638ab2..1c7b980c0d 100644 --- a/usr/src/usr.sbin/lpr/common_source/displayq.c +++ b/usr/src/usr.sbin/lpr/common_source/displayq.c @@ -1,4 +1,4 @@ -/* displayq.c 4.5 83/06/02 */ +/* displayq.c 4.6 83/06/15 */ /* * Routines to display the state of the queue. */ @@ -116,7 +116,7 @@ displayq(format) return(0); } fp = fopen(LO, "r"); - if (fp == NULL || flock(fileno(fp), FSHLOCK|FNBLOCK) == 0) { + if (fp == NULL || flock(fileno(fp), LOCK_SH|LOCK_NB) == 0) { if (fp != NULL) fclose(fp); garbage = nitems; @@ -141,7 +141,9 @@ displayq(format) */ if (sendtorem) printf("\n%s: ", host); - if ((fd = open(ST, FRDONLY|FSHLOCK)) >= 0) { + fd = open(ST, O_RDONLY); + if (fd >= 0) { + (void) flock(fd, LOCK_SH); while ((i = read(fd, line, sizeof(line))) > 0) (void) fwrite(line, 1, i, stdout); (void) close(fd); diff --git a/usr/src/usr.sbin/lpr/common_source/rmjob.c b/usr/src/usr.sbin/lpr/common_source/rmjob.c index 0054b38245..85984fa297 100644 --- a/usr/src/usr.sbin/lpr/common_source/rmjob.c +++ b/usr/src/usr.sbin/lpr/common_source/rmjob.c @@ -1,4 +1,4 @@ -/* rmjob.c 4.4 83/06/02 */ +/* rmjob.c 4.5 83/06/15 */ /* * rmjob - remove the specified jobs from the queue. */ @@ -108,7 +108,7 @@ lockchk(s) fatal("can't access lock file"); else return(0); - if (!getline(fp) || flock(fileno(fp), FSHLOCK|FNBLOCK) == 0) { + if (!getline(fp) || flock(fileno(fp), LOCK_SH|LOCK_NB) == 0) { (void) fclose(fp); return(0); /* no daemon present */ } diff --git a/usr/src/usr.sbin/lpr/lpc/cmds.c b/usr/src/usr.sbin/lpr/lpc/cmds.c index 96fb37b91f..49ba8eb426 100644 --- a/usr/src/usr.sbin/lpr/lpc/cmds.c +++ b/usr/src/usr.sbin/lpr/lpc/cmds.c @@ -1,5 +1,5 @@ #ifndef lint -static char sccsid[] = "@(#)cmds.c 4.3 (Berkeley) %G%"; +static char sccsid[] = "@(#)cmds.c 4.4 (Berkeley) %G%"; #endif /* @@ -70,7 +70,7 @@ abortpr() else printf("\tprinting disabled\n"); } else if (errno == ENOENT) { - if ((fd = open(line, FWRONLY|FCREATE, 0760)) < 0) + if ((fd = open(line, O_WRONLY|O_CREAT, 0760)) < 0) printf("\tcannot create lock file\n"); else { (void) close(fd); @@ -89,7 +89,7 @@ abortpr() printf("\tcannot open lock file\n"); return; } - if (!getline(fp) || flock(fileno(fp), FSHLOCK|FNBLOCK) == 0) { + if (!getline(fp) || flock(fileno(fp), LOCK_SH|LOCK_NB) == 0) { (void) fclose(fp); printf("\tno daemon to abort\n"); return; @@ -293,7 +293,7 @@ disablepr() else printf("\tqueuing disabled\n"); } else if (errno == ENOENT) { - if ((fd = open(line, FWRONLY|FCREATE, 0670)) < 0) + if ((fd = open(line, O_WRONLY|O_CREAT, 0670)) < 0) printf("\tcannot create lock file\n"); else { (void) close(fd); @@ -499,8 +499,8 @@ prstat() printf("\t1 entry in spool area\n"); else printf("\t%d entries in spool area\n", i); - fd = open(line, FRDONLY); - if (fd < 0 || flock(fd, FSHLOCK|FNBLOCK) == 0) { + fd = open(line, O_RDONLY); + if (fd < 0 || flock(fd, LOCK_SH|LOCK_NB) == 0) { (void) close(fd); printf("\tno daemon present\n"); return; @@ -508,7 +508,9 @@ prstat() (void) close(fd); putchar('\t'); (void) sprintf(line, "%s/%s", SD, ST); - if ((fd = open(line, FRDONLY|FSHLOCK)) >= 0) { + fd = open(line, O_RDONLY); + if (fd >= 0) { + (void) flock(fd, LOCK_SH); while ((i = read(fd, line, sizeof(line))) > 0) (void) fwrite(line, 1, i, stdout); (void) close(fd); @@ -577,7 +579,7 @@ stoppr() else printf("\tprinting disabled\n"); } else if (errno == ENOENT) { - if ((fd = open(line, FWRONLY|FCREATE, 0760)) < 0) + if ((fd = open(line, O_WRONLY|O_CREAT, 0760)) < 0) printf("\tcannot create lock file\n"); else { (void) close(fd); diff --git a/usr/src/usr.sbin/lpr/lpc/lpc.c b/usr/src/usr.sbin/lpr/lpc/lpc.c index ffaef6c790..a986d9af2d 100644 --- a/usr/src/usr.sbin/lpr/lpc/lpc.c +++ b/usr/src/usr.sbin/lpr/lpc/lpc.c @@ -1,5 +1,5 @@ #ifndef lint -static char sccsid[] = "@(#)lpc.c 4.2 (Berkeley) %G%"; +static char sccsid[] = "@(#)lpc.c 4.3 (Berkeley) %G%"; #endif /* @@ -51,7 +51,7 @@ main(argc, argv) fromatty = isatty(fileno(stdin)); top = setjmp(toplevel) == 0; if (top) - sigset(SIGINT, intr); + signal(SIGINT, intr); for (;;) { cmdscanner(top); top = 1; diff --git a/usr/src/usr.sbin/lpr/lpd/lpd.c b/usr/src/usr.sbin/lpr/lpd/lpd.c index 39aa7df05d..3a191a1b15 100644 --- a/usr/src/usr.sbin/lpr/lpd/lpd.c +++ b/usr/src/usr.sbin/lpr/lpd/lpd.c @@ -1,4 +1,4 @@ -/* lpd.c 4.4 83/06/02 */ +/* lpd.c 4.5 83/06/15 */ /* * lpd -- line printer daemon. * @@ -41,7 +41,7 @@ static char *logfile = DEFLOGF; static struct sockaddr_in sin = { AF_INET }; int reapchild(); -char *ntoa(); +char *inet_ntoa(); main(argc, argv) int argc; @@ -95,10 +95,10 @@ main(argc, argv) exit(0); for (f = 0; f < 3; f++) (void) close(f); - (void) open("/dev/null", FRDONLY, 0); - (void) open("/dev/null", FWRONLY, 0); - (void) open(logfile, FWRONLY|FAPPEND, 0); - f = open("/dev/tty", FRDWR, 0); + (void) open("/dev/null", O_RDONLY); + (void) open("/dev/null", O_WRONLY); + (void) open(logfile, O_WRONLY|O_APPEND); + f = open("/dev/tty", O_RDWR); if (f > 0) { ioctl(f, TIOCNOTTY, 0); (void) close(f); @@ -126,7 +126,7 @@ main(argc, argv) /* * Main loop: listen, accept, do a request, continue. */ - sigset(SIGCHLD, reapchild); + signal(SIGCHLD, reapchild); listen(f, 10); for (;;) { int s, len = sizeof(fromaddr); @@ -139,7 +139,7 @@ main(argc, argv) exit(1); } if (fork() == 0) { - sigset(SIGCHLD, SIG_IGN); + signal(SIGCHLD, SIG_IGN); (void) close(f); doit(s, &fromaddr); exit(0); @@ -197,7 +197,7 @@ doit(f, fromaddr) fromaddr->sin_family); if (hp == 0) fatal("Host name for your address (%s) unknown", - ntoa(fromaddr->sin_addr)); + inet_ntoa(fromaddr->sin_addr)); strcpy(fromb, hp->h_name); from = fromb; if (chkhost()) @@ -350,23 +350,6 @@ chkhost() return(-1); } -/* - * Convert network-format internet address - * to base 256 d.d.d.d representation. - */ -static char * -ntoa(in) - struct in_addr in; -{ - static char b[18]; - register char *p; - - p = (char *)∈ -#define UC(b) (((int)b)&0xff) - sprintf(b, "%d.%d.%d.%d", UC(p[0]), UC(p[1]), UC(p[2]), UC(p[3])); - return (b); -} - /*VARARGS1*/ log(msg, a1, a2, a3) char *msg; diff --git a/usr/src/usr.sbin/lpr/lpd/printjob.c b/usr/src/usr.sbin/lpr/lpd/printjob.c index 814b1c5935..7f0f62333f 100644 --- a/usr/src/usr.sbin/lpr/lpd/printjob.c +++ b/usr/src/usr.sbin/lpr/lpd/printjob.c @@ -1,4 +1,4 @@ -/* printjob.c 4.6 83/06/02 */ +/* printjob.c 4.7 83/06/15 */ /* * printjob -- print jobs in the queue. * @@ -44,12 +44,12 @@ printjob() init(); /* set up capabilities */ (void) close(1); /* set up log file */ (void) close(2); - if (open(LF, FWRONLY|FAPPEND, 0) < 0) - (void) open("/dev/null", FWRONLY); + if (open(LF, O_WRONLY|O_APPEND) < 0) + (void) open("/dev/null", O_WRONLY); dup(1); pid = getpid(); /* for use with lprm */ setpgrp(0, pid); - sigset(SIGINT, onintr); + signal(SIGINT, onintr); /* * uses short form file names @@ -60,12 +60,14 @@ printjob() } if (stat(LO, &stb) == 0 && (stb.st_mode & 0100)) exit(0); /* printing disabled */ - if ((lfd = open(LO, FWRONLY|FCREATE|FTRUNCATE|FEXLOCK|FNBLOCK, 0664)) < 0) { + lfd = open(LO, O_WRONLY|O_CREAT, 0664); + if (lfd < 0 || flock(lfd, LOCK_EX|LOCK_NB) < 0) { if (errno == EWOULDBLOCK) /* active deamon present */ exit(0); log("cannot create %s", LO); exit(1); } + ftruncate(lfd, 0); /* * write process id for others to know */ @@ -334,7 +336,7 @@ print(format, file) int pid, p[2], stopped = 0; union wait status; - if ((fi = open(file, FRDONLY, 0)) < 0) { + if ((fi = open(file, O_RDONLY)) < 0) { log("%s: open failure ", file, errno); return(-1); } @@ -586,7 +588,7 @@ sendfile(type, file) char buf[BUFSIZ]; int sizerr; - if ((f = open(file, FRDONLY, 0)) < 0 || fstat(f, &stb) < 0) { + if ((f = open(file, O_RDONLY)) < 0 || fstat(f, &stb) < 0) { log("file (%s) open failure ", file, errno); return(-1); } @@ -937,7 +939,7 @@ openpr() if (*LP) { for (i = 1; ; i = i < 32 ? i << 1 : i) { - pfd = open(LP, RW ? FRDWR : FWRONLY, 0); + pfd = open(LP, RW ? O_RDWR : O_WRONLY); if (pfd >= 0) break; if (errno == ENOENT) { @@ -1083,8 +1085,10 @@ status(msg, a1, a2, a3) char buf[BUFSIZ]; umask(0); - if ((fd = open(ST, FWRONLY|FCREATE|FTRUNCATE|FEXLOCK, 0664)) < 0) + fd = open(ST, O_WRONLY|O_CREAT, 0664); + if (fd < 0 || flock(fd, LOCK_EX) < 0) fatal("cannot create status file"); + ftruncate(fd, 0); sprintf(buf, msg, a1, a2, a3); strcat(buf, "\n"); (void) write(fd, buf, strlen(buf)); diff --git a/usr/src/usr.sbin/lpr/lpd/recvjob.c b/usr/src/usr.sbin/lpr/lpd/recvjob.c index 27792b9c62..638e603fab 100644 --- a/usr/src/usr.sbin/lpr/lpd/recvjob.c +++ b/usr/src/usr.sbin/lpr/lpd/recvjob.c @@ -1,4 +1,4 @@ -/* recvjob.c 4.3 83/06/02 */ +/* recvjob.c 4.4 83/06/15 */ /* * Receive printer jobs from the network, queue them and * start the printer daemon. @@ -30,7 +30,7 @@ recvjob() LO = DEFLOCK; (void) close(2); - (void) open(LF, FWRONLY|FAPPEND, 0); + (void) open(LF, O_WRONLY|O_APPEND); if (chdir(SD) < 0) fatal("cannot chdir to %s", SD); if (stat(LO, &stb) == 0 && (stb.st_mode & 010)) { @@ -123,7 +123,7 @@ readfile(file, size) register int i, j, amt; int fd, err; - fd = open(file, FWRONLY|FCREATE, FILMOD); + fd = open(file, O_WRONLY|O_CREAT, FILMOD); if (fd < 0) fatal("cannot create %s", file); ack(); diff --git a/usr/src/usr.sbin/lpr/lpr/lpr.c b/usr/src/usr.sbin/lpr/lpr/lpr.c index c159ea2713..f84aa5918d 100644 --- a/usr/src/usr.sbin/lpr/lpr/lpr.c +++ b/usr/src/usr.sbin/lpr/lpr/lpr.c @@ -55,7 +55,7 @@ char lpr_id[] = "~|^`lpr.c:\t4.2\t1 May 1981\n"; -/* lpr.c 4.19 83/06/02 */ +/* lpr.c 4.20 83/06/15 */ /* * lpr -- off line print * @@ -288,7 +288,7 @@ main(argc, argv) } if (sflag) printf("%s: %s: not linked, copying instead\n", name, arg); - if ((i = open(arg, 0)) < 0) { + if ((i = open(arg, O_RDONLY)) < 0) { printf("%s: cannot open %s\n", name, arg); continue; } @@ -304,7 +304,7 @@ main(argc, argv) /* * Touch the control file to fix position in the queue. */ - if ((tfd = open(tfname, 2)) >= 0) { + if ((tfd = open(tfname, O_RDWR)) >= 0) { char c; if (read(tfd, &c, 1) == 1 && lseek(tfd, 0L, 0) == 0 && @@ -504,7 +504,7 @@ test(file) printf("%s: %s is a directory\n", name, file); return(-1); } - if ((fd = open(file, 0)) < 0) { + if ((fd = open(file, O_RDONLY)) < 0) { printf("%s: cannot open %s\n", name, file); return(-1); } @@ -604,7 +604,7 @@ mktemps() n = 0; } else { setbuf(fp, buf); - if (flock(fileno(fp), FEXLOCK)) { + if (flock(fileno(fp), LOCK_EX)) { printf("%s: cannot lock %s\n", name, buf); exit(1); } -- 2.20.1