update the status file when printing is disabled
authorThomas Ferrin <tef@ucbvax.Berkeley.EDU>
Wed, 23 Aug 1989 11:04:49 +0000 (03:04 -0800)
committerThomas Ferrin <tef@ucbvax.Berkeley.EDU>
Wed, 23 Aug 1989 11:04:49 +0000 (03:04 -0800)
SCCS-vsn: usr.sbin/lpr/lpc/cmds.c 5.6

usr/src/usr.sbin/lpr/lpc/cmds.c

index 76f5d86..e847477 100644 (file)
@@ -16,7 +16,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)cmds.c     5.5 (Berkeley) %G%";
+static char sccsid[] = "@(#)cmds.c     5.6 (Berkeley) %G%";
 #endif /* not lint */
 
 /*
 #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");
                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");
                                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);
                } 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");
                        }
                                printf("\tprinting disabled\n");
                                printf("\tno daemon to abort\n");
                        }
@@ -122,6 +125,33 @@ abortpr(dis)
                printf("\tdaemon (pid %d) killed\n", pid);
 }
 
                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.
  */
 /*
  * 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");
        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");
                        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);
        } 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
                        printf("\tprinting disabled\n");
                }
        } else