From: Thomas Ferrin Date: Wed, 23 Aug 1989 11:04:49 +0000 (-0800) Subject: update the status file when printing is disabled X-Git-Tag: BSD-4_3_Reno-Snapshot-Development~5699 X-Git-Url: https://git.subgeniuskitty.com/unix-history/.git/commitdiff_plain/845a514d2d77646eeead099ccd0a752cbad65c7d update the status file when printing is disabled SCCS-vsn: usr.sbin/lpr/lpc/cmds.c 5.6 --- diff --git a/usr/src/usr.sbin/lpr/lpc/cmds.c b/usr/src/usr.sbin/lpr/lpc/cmds.c index 76f5d8679c..e84747770a 100644 --- a/usr/src/usr.sbin/lpr/lpc/cmds.c +++ b/usr/src/usr.sbin/lpr/lpc/cmds.c @@ -16,7 +16,7 @@ */ #ifndef lint -static char sccsid[] = "@(#)cmds.c 5.5 (Berkeley) %G%"; +static char sccsid[] = "@(#)cmds.c 5.6 (Berkeley) %G%"; #endif /* not lint */ /* @@ -87,13 +87,16 @@ abortpr(dis) if (stat(line, &stbuf) >= 0) { if (chmod(line, (stbuf.st_mode & 0777) | 0100) < 0) printf("\tcannot disable printing\n"); - else + else { + upstat("printing disabled\n"); printf("\tprinting disabled\n"); + } } else if (errno == ENOENT) { if ((fd = open(line, O_WRONLY|O_CREAT, 0760)) < 0) printf("\tcannot create lock file\n"); else { (void) close(fd); + upstat("printing disabled\n"); printf("\tprinting disabled\n"); printf("\tno daemon to abort\n"); } @@ -122,6 +125,33 @@ abortpr(dis) printf("\tdaemon (pid %d) killed\n", pid); } +/* + * Write a message into the status file. + */ +upstat(msg) + char *msg; +{ + register int fd; + char statfile[BUFSIZ]; + + bp = pbuf; + if ((ST = pgetstr("st", &bp)) == NULL) + ST = DEFSTAT; + (void) sprintf(statfile, "%s/%s", SD, ST); + umask(0); + fd = open(statfile, O_WRONLY|O_CREAT, 0664); + if (fd < 0 || flock(fd, LOCK_EX) < 0) { + printf("\tcannot create status file\n"); + return; + } + (void) ftruncate(fd, 0); + if (msg == (char *)NULL) + (void) write(fd, "\n", 1); + else + (void) write(fd, msg, strlen(msg)); + (void) close(fd); +} + /* * Remove all spool files and temporaries from the spooling area. */ @@ -763,13 +793,16 @@ stoppr() if (stat(line, &stbuf) >= 0) { if (chmod(line, (stbuf.st_mode & 0777) | 0100) < 0) printf("\tcannot disable printing\n"); - else + else { + upstat("printing disabled\n"); printf("\tprinting disabled\n"); + } } else if (errno == ENOENT) { if ((fd = open(line, O_WRONLY|O_CREAT, 0760)) < 0) printf("\tcannot create lock file\n"); else { (void) close(fd); + upstat("printing disabled\n"); printf("\tprinting disabled\n"); } } else