add Berkeley specific copyright notice
[unix-history] / usr / src / old / vpr / vpd.c
index 530d7fc..b6d9e49 100644 (file)
@@ -4,17 +4,17 @@
  * vpd.c                                               updated %G%
  * Varian or Versatec printer daemon
  */
  * vpd.c                                               updated %G%
  * Varian or Versatec printer daemon
  */
-char vpdSCCSid[] = "@(#)vpd.c  1.2\t%G%";
+char vpdSCCSid[] = "@(#)vpd.c  1.5\t%G%";
 
 #include <stdio.h>
 
 #include <stdio.h>
-#include <sys/types.h>
-#include <dir.h>
+#include <sys/param.h>
+#include <sys/dir.h>
 #include <signal.h>
 #include <signal.h>
-#include <stat.h>
+#include <sys/stat.h>
 #include <sgtty.h>
 #include <errno.h>
 #include <sys/vcmd.h>
 #include <sgtty.h>
 #include <errno.h>
 #include <sys/vcmd.h>
-#include <wait.h>
+#include <sys/wait.h>
 
 int    debug;
 extern int errno;
 
 int    debug;
 extern int errno;
@@ -48,7 +48,6 @@ int   linel;
 FILE   *dfb;
 char   dfname[33] = DFNAME;
 int    waittm = 6;
 FILE   *dfb;
 char   dfname[33] = DFNAME;
 int    waittm = 6;
-struct dir dbuf;
 int    onalrm ();
 char   tmplock[] = "lockXXXXXX";
 char   fonts[4][50] = {
 int    onalrm ();
 char   tmplock[] = "lockXXXXXX";
 char   fonts[4][50] = {
@@ -59,14 +58,34 @@ char        fonts[4][50] = {
 };
 
 main(argc, argv)
 };
 
 main(argc, argv)
+       int argc;
+       char **argv;
 {
 {
-       char dp, n;
+       char n;
        register char *p1, *p2;
        register int df;
        register char *p1, *p2;
        register int df;
+       register struct direct *dirp;
+       DIR *dp;
        struct stat stb;
        int offline = 0;
        int i, okreque = 1;
 
        struct stat stb;
        int offline = 0;
        int i, okreque = 1;
 
+       while (argc > 1) {
+               argc--;
+               argv++;
+               if (argv[0][0] != '-')
+                       continue;
+               switch (argv[0][1]) {
+               case 'n':
+                       if (argc < 2)
+                               break;
+                       argv++;
+                       argc--;
+                       nice(atol(argv[0]));
+                       break;
+               }
+       }
+       setuid(getuid());
        signal(SIGHUP, SIG_IGN);
        signal(SIGINT, SIG_IGN);
        signal(SIGQUIT, SIG_IGN);
        signal(SIGHUP, SIG_IGN);
        signal(SIGINT, SIG_IGN);
        signal(SIGQUIT, SIG_IGN);
@@ -125,14 +144,14 @@ reopen:
                }
                sleep(10);
        }
                }
                sleep(10);
        }
-       dp = open(".", 0);
+       dp = opendir(".");
 search:
        dprcons("search\n");
        if (okreque == 1) {
 search:
        dprcons("search\n");
        if (okreque == 1) {
-               lseek(dp, 0, 0);
+               rewinddir(dp);
                do {
                do {
-                       n = read(dp, &dbuf, sizeof dbuf);
-                       if (n <= 0) {
+                       dirp = readdir(dp);
+                       if (dirp == NULL) {
                                if (printflag)
                                        lastpage();
                                unlink("lock");
                                if (printflag)
                                        lastpage();
                                unlink("lock");
@@ -144,13 +163,13 @@ search:
                                dprcons("one last time\n");
                                printflag = 0;
                                close(3);
                                dprcons("one last time\n");
                                printflag = 0;
                                close(3);
+                               closedir(dp);
                                sleep(30);
                                goto begin;
                        }
                                sleep(30);
                                goto begin;
                        }
-               } while (!dbuf.d_ino
-                   || dbuf.d_name[0] != 'd' || dbuf.d_name[1] != 'f');
-               strcpy(&dfname[15], dbuf.d_name);
-               dprcons("found %s\n", dbuf.d_name);
+               } while (dirp->d_name[0] != 'd' || dirp->d_name[1] != 'f');
+               strcpy(&dfname[15], dirp->d_name);
+               dprcons("found %s\n", dirp->d_name);
        }
        dprcons("trying %s\n", dfname);
        printflag = 1;
        }
        dprcons("trying %s\n", dfname);
        printflag = 1;
@@ -158,7 +177,7 @@ search:
                feedpage();
        if (trysend(dfname, okreque)) {
                okreque = 0;
                feedpage();
        if (trysend(dfname, okreque)) {
                okreque = 0;
-               close(dp);
+               closedir(dp);
                printf("reque %s\n", dfname);
                close(3);
                goto reopen;
                printf("reque %s\n", dfname);
                close(3);
                goto reopen;