fixed `fc' and `fs' when 0177777 is needed.
[unix-history] / usr / src / usr.sbin / lpr / common_source / displayq.c
index 7b5ab45..ce86140 100644 (file)
@@ -1,12 +1,13 @@
-/*     displayq.c      4.2     83/05/13        */
+/*     displayq.c      4.7     83/06/17        */
 /*
  * Routines to display the state of the queue.
  */
 
 #include "lp.h"
 
 /*
  * Routines to display the state of the queue.
  */
 
 #include "lp.h"
 
-#define        JOBCOL          40      /* column for job # in -l format */
-#define OWNCOL         7       /* start of Owner column in normal */
+#define JOBCOL 40              /* column for job # in -l format */
+#define OWNCOL 7               /* start of Owner column in normal */
+#define SIZCOL 62              /* start of Size column in normal */
 
 /*
  * Stuff for handling job specifications
 
 /*
  * Stuff for handling job specifications
@@ -16,19 +17,18 @@ extern int  users;          /* # of users in user array */
 extern int     requ[];         /* job number of spool entries */
 extern int     requests;       /* # of spool requests */
 
 extern int     requ[];         /* job number of spool entries */
 extern int     requests;       /* # of spool requests */
 
-int    lflag;                  /* long output option */
-char   current[40];            /* current file being printed */
-int    garbage;                /* # of garbage cf files */
-int    rank;                   /* order to be printed (-1=none, 0=active) */
-long   totsize;                /* total print job size in bytes */
-int    first;                  /* first file in ``files'' column? */
-int    col;                    /* column on screen */
-int    SIZCOL = 62;            /* start of Size column in normal */
-int    sendtorem;              /* are we sending to a remote? */
-char   file[132];              /* print file name */
+static int     lflag;          /* long output option */
+static char    current[40];    /* current file being printed */
+static int     garbage;        /* # of garbage cf files */
+static int     rank;           /* order to be printed (-1=none, 0=active) */
+static long    totsize;        /* total print job size in bytes */
+static int     first;          /* first file in ``files'' column? */
+static int     col;            /* column on screen */
+static int     sendtorem;      /* are we sending to a remote? */
+static char    file[132];      /* print file name */
 
 
-char   *head0 = "Rank   Owner      Job  Files";
-char   *head1 = "Total Size\n";
+static char    *head0 = "Rank   Owner      Job  Files";
+static char    *head1 = "Total Size\n";
 
 /*
  * Display the current state of the queue. Format = 1 if long format.
 
 /*
  * Display the current state of the queue. Format = 1 if long format.
@@ -84,7 +84,7 @@ displayq(format)
                        strcpy(cp, user[i]);
                }
                strcat(line, "\n");
                        strcpy(cp, user[i]);
                }
                strcat(line, "\n");
-               fd = getport();
+               fd = getport(RM);
                if (fd < 0) {
                        if (from != host)
                                printf("%s: ", host);
                if (fd < 0) {
                        if (from != host)
                                printf("%s: ", host);
@@ -105,17 +105,23 @@ displayq(format)
                fatal("cannot chdir to spooling directory");
        if ((nitems = getq(&queue)) < 0)
                fatal("cannot examine spooling area\n");
                fatal("cannot chdir to spooling directory");
        if ((nitems = getq(&queue)) < 0)
                fatal("cannot examine spooling area\n");
-       if (nitems == 0) {
+       if (stat(LO, &statb) >= 0 && (statb.st_mode & 010)) {
                if (sendtorem)
                        printf("\n%s: ", host);
                if (sendtorem)
                        printf("\n%s: ", host);
-               printf("no entries\n");
+               printf("Warning: %s queue is turned off\n", printer);
+       }
+       if (nitems == 0) {
+               if (!sendtorem)
+                       printf("no entries\n");
                return(0);
        }
        fp = fopen(LO, "r");
                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)
                if (fp != NULL)
-                       fclose(fp);
+                       fclose(fp);     /* unlocks as well */
                garbage = nitems;
                garbage = nitems;
+               if (sendtorem)
+                       printf("\n%s: ", host);
                if (stat(LO, &statb) >= 0 && (statb.st_mode & 0100))
                        printf("Warning: %s is down\n", printer);
                else
                if (stat(LO, &statb) >= 0 && (statb.st_mode & 0100))
                        printf("Warning: %s is down\n", printer);
                else
@@ -135,10 +141,12 @@ displayq(format)
                 */
                if (sendtorem)
                        printf("\n%s: ", host);
                 */
                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);
                        while ((i = read(fd, line, sizeof(line))) > 0)
                                (void) fwrite(line, 1, i, stdout);
-                       (void) close(fd);
+                       (void) close(fd);       /* unlocks as well */
                } else
                        putchar('\n');
        }
                } else
                        putchar('\n');
        }
@@ -160,6 +168,7 @@ displayq(format)
 /*
  * Print the header for the short listing format
  */
 /*
  * Print the header for the short listing format
  */
+static
 header()
 {
        printf(head0);
 header()
 {
        printf(head0);
@@ -168,6 +177,7 @@ header()
        printf(head1);
 }
 
        printf(head1);
 }
 
+static
 inform(cf)
        char *cf;
 {
 inform(cf)
        char *cf;
 {
@@ -230,6 +240,7 @@ inform(cf)
        }
 }
 
        }
 }
 
+static
 inlist(name, file)
        char *name, *file;
 {
 inlist(name, file)
        char *name, *file;
 {
@@ -255,6 +266,7 @@ inlist(name, file)
        return(0);
 }
 
        return(0);
 }
 
+static
 show(nfile, file, copies)
        register char *nfile, *file;
 {
 show(nfile, file, copies)
        register char *nfile, *file;
 {
@@ -269,6 +281,7 @@ show(nfile, file, copies)
 /*
  * Fill the line with blanks to the specified column
  */
 /*
  * Fill the line with blanks to the specified column
  */
+static
 blankfill(n)
        register int n;
 {
 blankfill(n)
        register int n;
 {
@@ -279,6 +292,7 @@ blankfill(n)
 /*
  * Give the abbreviated dump of the file names
  */
 /*
  * Give the abbreviated dump of the file names
  */
+static
 dump(nfile, file, copies)
        char *nfile, *file;
 {
 dump(nfile, file, copies)
        char *nfile, *file;
 {
@@ -310,6 +324,7 @@ dump(nfile, file, copies)
 /*
  * Print the long info about the file
  */
 /*
  * Print the long info about the file
  */
+static
 ldump(nfile, file, copies)
        char *nfile, *file;
 {
 ldump(nfile, file, copies)
        char *nfile, *file;
 {
@@ -331,6 +346,7 @@ ldump(nfile, file, copies)
  * Print the job's rank in the queue,
  *   update col for screen management
  */
  * Print the job's rank in the queue,
  *   update col for screen management
  */
+static
 prank(n)
 {
        char line[100];
 prank(n)
 {
        char line[100];