DataMuseum.dk

Presents historical artifacts from the history of:

Commodore CBM-900

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about Commodore CBM-900

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - download

⟦3a68dd9a2⟧

    Length: 5180 (0x143c)
    Notes: UNIX file
    Names: »lpd1.c«

Derivation

└─⟦f27320a65⟧ Bits:30001972 Commodore 900 hard disk image with partial source code
    └─⟦f4b8d8c84⟧ UNIX V7 Filesystem
        └─ ⟦this⟧ »cmd/lpr/lpd1.c« 

Hex Dump

0x0000…0020 2f 2a 0a 20 2a 20 54 68 65 20 6c 69 6e 65 20 70 72 69 6e 74 65 72 20 73 70 6f 6f 6c 65 72 20 64   ┆/*  * The line printer spooler d┆
0x0020…0040 61 65 6d 6f 6e 2e 0a 20 2a 20 54 68 69 73 20 73 68 6f 75 6c 64 20 62 65 20 69 6e 76 6f 6b 65 64   ┆aemon.  * This should be invoked┆
0x0040…0060 20 66 72 6f 6d 20 74 68 65 20 60 2f 65 74 63 2f 72 63 27 0a 20 2a 20 66 69 6c 65 20 61 6e 64 20   ┆ from the `/etc/rc'  * file and ┆
0x0060…0080 62 79 20 74 68 65 20 60 6c 70 72 27 20 63 6f 6d 6d 61 6e 64 2e 0a 20 2a 20 28 4e 4f 54 45 3a 20   ┆by the `lpr' command.  * (NOTE: ┆
0x0080…00a0 74 68 69 73 20 63 6f 6d 6d 61 6e 64 20 73 68 6f 75 6c 64 20 62 65 20 73 65 74 75 69 64 20 74 6f   ┆this command should be setuid to┆
0x00a0…00c0 20 64 61 65 6d 6f 6e 29 0a 20 2a 2f 0a 0a 23 69 6e 63 6c 75 64 65 20 3c 73 74 64 69 6f 2e 68 3e   ┆ daemon)  */  #include <stdio.h>┆
0x00c0…00e0 0a 23 69 6e 63 6c 75 64 65 20 3c 64 69 72 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 20 3c 70 77 64 2e   ┆ #include <dir.h> #include <pwd.┆
0x00e0…0100 68 3e 0a 23 69 6e 63 6c 75 64 65 20 3c 73 67 74 74 79 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 20 3c   ┆h> #include <sgtty.h> #include <┆
0x0100…0120 73 69 67 6e 61 6c 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 20 3c 65 72 72 6e 6f 2e 68 3e 0a 0a 23 64   ┆signal.h> #include <errno.h>  #d┆
0x0120…0140 65 66 69 6e 65 20 44 41 45 4d 4f 4e 09 31 09 09 2f 2a 20 44 61 65 6d 6f 6e 27 73 20 6d 61 67 69   ┆efine DAEMON 1  /* Daemon's magi┆
0x0140…0160 63 20 6e 75 6d 62 65 72 20 2a 2f 0a 23 64 65 66 69 6e 65 09 42 41 4e 57 49 44 09 31 30 09 09 2f   ┆c number */ #define BANWID 10  /┆
0x0160…0180 2a 20 4c 6f 6e 67 65 73 74 20 62 61 6e 6e 65 72 20 2a 2f 0a 23 64 65 66 69 6e 65 09 4d 41 58 43   ┆* Longest banner */ #define MAXC┆
0x0180…01a0 4f 4d 09 34 30 09 09 2f 2a 20 4c 6f 6e 67 65 73 74 20 63 6f 6d 6d 65 6e 74 20 6c 69 6e 65 20 73   ┆OM 40  /* Longest comment line s┆
0x01a0…01c0 65 6e 74 20 74 68 72 6f 75 67 68 20 6d 61 69 6c 20 2a 2f 0a 23 64 65 66 69 6e 65 09 46 46 09 30   ┆ent through mail */ #define FF 0┆
0x01c0…01e0 31 34 09 09 2f 2a 20 46 6f 72 6d 20 66 65 65 64 20 2a 2f 0a 23 64 65 66 69 6e 65 09 53 4d 41 4c   ┆14  /* Form feed */ #define SMAL┆
0x01e0…0200 4c 09 30 33 37 09 09 2f 2a 20 53 65 74 20 73 6d 61 6c 6c 20 63 68 61 72 61 63 74 65 72 73 20 2d   ┆L 037  /* Set small characters -┆
0x0200…0220 2d 20 70 61 70 65 72 20 74 69 67 65 72 20 2a 2f 0a 23 64 65 66 69 6e 65 09 4e 4f 52 4d 41 4c 09   ┆- paper tiger */ #define NORMAL ┆
0x0220…0240 30 33 36 09 09 2f 2a 20 53 65 74 20 6e 6f 72 6d 61 6c 20 63 68 61 72 61 63 74 65 72 73 20 2d 2d   ┆036  /* Set normal characters --┆
0x0240…0260 20 70 61 70 65 72 20 74 69 67 65 72 20 2a 2f 0a 0a 63 68 61 72 09 73 70 6f 6f 6c 64 69 72 5b 5d   ┆ paper tiger */  char spooldir[]┆
0x0260…0280 20 3d 20 22 2f 75 73 72 2f 73 70 6f 6f 6c 2f 6c 70 64 22 3b 0a 63 68 61 72 09 6c 6f 63 6b 66 69   ┆ = "/usr/spool/lpd"; char lockfi┆
0x0280…02a0 6c 65 5b 5d 20 3d 20 22 64 70 69 64 22 3b 0a 63 68 61 72 09 2a 70 72 69 6e 74 65 72 20 3d 20 22   ┆le[] = "dpid"; char *printer = "┆
0x02a0…02c0 2f 64 65 76 2f 6c 70 22 3b 0a 0a 63 68 61 72 09 6f 62 75 66 5b 42 55 46 53 49 5a 5d 3b 0a 63 68   ┆/dev/lp";  char obuf[BUFSIZ]; ch┆
0x02c0…02e0 61 72 09 63 66 6c 69 6e 65 5b 33 30 30 5d 3b 09 09 2f 2a 20 43 6f 6e 74 72 6f 6c 20 66 69 6c 65   ┆ar cfline[300];  /* Control file┆
0x02e0…0300 20 6c 69 6e 65 20 2a 2f 0a 63 68 61 72 09 63 6f 6d 6d 65 6e 74 5b 33 30 30 5d 3b 09 09 2f 2a 20   ┆ line */ char comment[300];  /* ┆
0x0300…0320 43 6f 6d 6d 65 6e 74 20 6c 69 6e 65 20 2a 2f 0a 46 49 4c 45 09 2a 6c 70 3b 0a 69 6e 74 09 70 72   ┆Comment line */ FILE *lp; int pr┆
0x0320…0340 69 6e 74 69 6e 67 3b 09 09 2f 2a 20 4f 6e 20 77 68 69 6c 65 20 70 72 69 6e 74 69 6e 67 20 2a 2f   ┆inting;  /* On while printing */┆
0x0340…0360 0a 0a 63 68 61 72 09 2a 6c 67 65 74 73 28 29 3b 0a 69 6e 74 09 63 61 6e 63 65 6c 28 29 3b 0a 69   ┆  char *lgets(); int cancel(); i┆
0x0360…0380 6e 74 09 72 65 73 74 61 72 74 28 29 3b 0a 0a 6d 61 69 6e 28 61 72 67 63 2c 20 61 72 67 76 29 0a   ┆nt restart();  main(argc, argv) ┆
0x0380…03a0 63 68 61 72 20 2a 61 72 67 76 5b 5d 3b 0a 7b 0a 09 69 6e 74 20 66 64 3b 0a 09 69 6e 74 20 70 69   ┆char *argv[]; {  int fd;  int pi┆
0x03a0…03c0 64 3b 0a 0a 09 73 65 74 75 69 64 28 44 41 45 4d 4f 4e 29 3b 0a 09 69 66 20 28 63 68 64 69 72 28   ┆d;   setuid(DAEMON);  if (chdir(┆
0x03c0…03e0 73 70 6f 6f 6c 64 69 72 29 20 3c 20 30 29 0a 09 09 6c 70 65 72 72 28 22 73 70 6f 6f 6c 20 64 69   ┆spooldir) < 0)   lperr("spool di┆
0x03e0…0400 72 65 63 74 6f 72 79 20 62 6f 74 63 68 22 29 3b 0a 09 69 66 20 28 28 66 64 20 3d 20 63 72 65 61   ┆rectory botch");  if ((fd = crea┆
0x0400…0420 74 28 6c 6f 63 6b 66 69 6c 65 2c 20 30 34 30 30 29 29 20 3c 20 30 29 0a 09 09 65 78 69 74 28 30   ┆t(lockfile, 0400)) < 0)   exit(0┆
0x0420…0440 29 3b 0a 09 69 66 20 28 66 6f 72 6b 28 29 29 0a 09 09 65 78 69 74 28 30 29 3b 0a 09 73 69 67 6e   ┆);  if (fork())   exit(0);  sign┆
0x0440…0460 61 6c 28 53 49 47 49 4e 54 2c 20 53 49 47 5f 49 47 4e 29 3b 0a 09 73 69 67 6e 61 6c 28 53 49 47   ┆al(SIGINT, SIG_IGN);  signal(SIG┆
0x0460…0480 48 55 50 2c 20 53 49 47 5f 49 47 4e 29 3b 0a 09 73 69 67 6e 61 6c 28 53 49 47 54 52 41 50 2c 20   ┆HUP, SIG_IGN);  signal(SIGTRAP, ┆
0x0480…04a0 63 61 6e 63 65 6c 29 3b 0a 09 73 69 67 6e 61 6c 28 53 49 47 52 45 53 54 2c 20 72 65 73 74 61 72   ┆cancel);  signal(SIGREST, restar┆
0x04a0…04c0 74 29 3b 0a 09 70 69 64 20 3d 20 67 65 74 70 69 64 28 29 3b 0a 09 77 72 69 74 65 28 66 64 2c 20   ┆t);  pid = getpid();  write(fd, ┆
0x04c0…04e0 26 70 69 64 2c 20 73 69 7a 65 6f 66 20 70 69 64 29 3b 0a 09 63 6c 6f 73 65 28 66 64 29 3b 0a 09   ┆&pid, sizeof pid);  close(fd);  ┆
0x04e0…0500 69 66 20 28 61 72 67 63 20 3e 20 31 29 0a 09 09 70 72 69 6e 74 65 72 20 3d 20 61 72 67 76 5b 31   ┆if (argc > 1)   printer = argv[1┆
0x0500…0520 5d 3b 0a 09 69 66 20 28 28 6c 70 20 3d 20 66 6f 70 65 6e 28 70 72 69 6e 74 65 72 2c 20 22 77 22   ┆];  if ((lp = fopen(printer, "w"┆
0x0520…0540 29 29 20 3d 3d 20 4e 55 4c 4c 29 0a 09 09 6c 70 65 72 72 28 20 22 25 73 3a 20 25 73 22 2c 20 70   ┆)) == NULL)   lperr( "%s: %s", p┆
0x0540…0560 72 69 6e 74 65 72 2c 20 73 79 73 5f 65 72 72 6c 69 73 74 5b 65 72 72 6e 6f 5d 29 3b 0a 09 69 6f   ┆rinter, sys_errlist[errno]);  io┆
0x0560…0580 63 74 6c 28 66 69 6c 65 6e 6f 28 6c 70 29 2c 20 54 49 4f 43 45 58 43 4c 2c 20 4e 55 4c 4c 29 3b   ┆ctl(fileno(lp), TIOCEXCL, NULL);┆
0x0580…05a0 0a 09 73 65 74 62 75 66 28 6c 70 2c 20 6f 62 75 66 29 3b 0a 09 70 72 6f 63 65 73 73 28 29 3b 0a   ┆  setbuf(lp, obuf);  process(); ┆
0x05a0…05c0 09 72 6d 65 78 69 74 28 30 29 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20 46 69 6e 64 20 77 6f 72 6b 20 74   ┆ rmexit(0); }  /*  * Find work t┆
0x05c0…05e0 6f 20 64 6f 2e 0a 20 2a 20 54 68 65 20 62 61 73 69 63 20 61 6c 67 6f 72 69 74 68 6d 20 69 73 20   ┆o do.  * The basic algorithm is ┆
0x05e0…0600 74 6f 0a 20 2a 20 72 75 6e 20 64 6f 77 6e 20 74 68 65 20 63 75 72 72 65 6e 74 20 64 69 72 65 63   ┆to  * run down the current direc┆
0x0600…0620 74 6f 72 79 0a 20 2a 20 6c 6f 6f 6b 69 6e 67 20 66 6f 72 20 66 69 6c 65 73 20 77 68 6f 73 65 20   ┆tory  * looking for files whose ┆
0x0620…0640 6e 61 6d 65 73 0a 20 2a 20 62 65 67 69 6e 20 77 69 74 68 20 60 63 66 27 20 61 6e 64 20 64 6f 20   ┆names  * begin with `cf' and do ┆
0x0640…0660 74 68 65 20 77 6f 72 6b 0a 20 2a 20 61 73 73 6f 63 69 61 74 65 64 20 77 69 74 68 20 65 61 63 68   ┆the work  * associated with each┆
0x0660…0680 20 6f 66 20 74 68 65 6d 2e 0a 20 2a 2f 0a 70 72 6f 63 65 73 73 28 29 0a 7b 0a 09 46 49 4c 45 20   ┆ of them.  */ process() {  FILE ┆
0x0680…06a0 2a 64 69 72 66 69 6c 65 3b 0a 09 73 74 72 75 63 74 20 64 69 72 65 63 74 20 64 69 72 3b 0a 09 63   ┆*dirfile;  struct direct dir;  c┆
0x06a0…06c0 68 61 72 20 2a 72 20 3d 20 22 72 22 3b 0a 0a 09 69 66 20 28 28 64 69 72 66 69 6c 65 20 3d 20 66   ┆har *r = "r";   if ((dirfile = f┆
0x06c0…06e0 6f 70 65 6e 28 22 2e 22 2c 20 72 29 29 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 77 68 69 6c 65   ┆open(".", r)) != NULL) {   while┆
0x06e0…0700 20 28 66 72 65 61 64 28 26 64 69 72 2c 20 73 69 7a 65 6f 66 20 64 69 72 2c 20 31 2c 20 64 69 72   ┆ (fread(&dir, sizeof dir, 1, dir┆
0x0700…0720 66 69 6c 65 29 20 3d 3d 20 31 29 20 7b 0a 09 09 09 69 66 20 28 64 69 72 2e 64 5f 69 6e 6f 20 3d   ┆file) == 1) {    if (dir.d_ino =┆
0x0720…0740 3d 20 30 0a 09 09 09 20 7c 7c 20 64 69 72 2e 64 5f 6e 61 6d 65 5b 30 5d 20 21 3d 20 27 63 27 0a   ┆= 0     || dir.d_name[0] != 'c' ┆
0x0740…0760 09 09 09 20 7c 7c 20 64 69 72 2e 64 5f 6e 61 6d 65 5b 31 5d 20 21 3d 20 27 66 27 29 0a 09 09 09   ┆    || dir.d_name[1] != 'f')    ┆
0x0760…0780 09 63 6f 6e 74 69 6e 75 65 3b 0a 09 09 09 63 6f 6e 74 72 6f 6c 28 64 69 72 2e 64 5f 6e 61 6d 65   ┆ continue;    control(dir.d_name┆
0x0780…07a0 29 3b 0a 09 09 09 72 65 77 69 6e 64 28 64 69 72 66 69 6c 65 29 3b 0a 09 09 7d 0a 09 09 66 63 6c   ┆);    rewind(dirfile);   }   fcl┆
0x07a0…07c0 6f 73 65 28 64 69 72 66 69 6c 65 29 3b 0a 09 7d 0a 7d 0a 0a 2f 2a 0a 20 2a 20 44 6f 20 74 68 65   ┆ose(dirfile);  } }  /*  * Do the┆
0x07c0…07e0 20 61 63 74 69 6f 6e 20 73 70 65 63 69 66 69 65 64 20 62 79 20 74 68 65 20 63 6f 6e 74 72 6f 6c   ┆ action specified by the control┆
0x07e0…0800 0a 20 2a 20 66 69 6c 65 2e 20 20 45 73 73 65 6e 74 69 61 6c 6c 79 2c 20 74 68 69 73 20 6d 75 73   ┆  * file.  Essentially, this mus┆
0x0800…0820 74 20 69 6e 74 65 72 70 72 65 74 0a 20 2a 20 74 68 65 20 63 6f 6e 74 72 6f 6c 20 6c 69 6e 65 73   ┆t interpret  * the control lines┆
0x0820…0840 20 66 6f 72 20 73 75 63 68 20 74 68 69 6e 67 73 20 61 73 0a 20 2a 20 6d 61 69 6c 20 6e 6f 74 69   ┆ for such things as  * mail noti┆
0x0840…0860 66 69 63 61 74 69 6f 6e 2c 20 62 61 6e 6e 65 72 73 2c 20 65 74 63 2e 0a 20 2a 2f 0a 63 6f 6e 74   ┆fication, banners, etc.  */ cont┆
0x0860…0880 72 6f 6c 28 63 66 6e 61 6d 65 29 0a 72 65 67 69 73 74 65 72 20 63 68 61 72 20 2a 63 66 6e 61 6d   ┆rol(cfname) register char *cfnam┆
0x0880…08a0 65 3b 0a 7b 0a 09 46 49 4c 45 20 2a 63 66 70 3b 0a 09 63 68 61 72 20 6d 62 75 66 5b 4d 41 58 43   ┆e; {  FILE *cfp;  char mbuf[MAXC┆
0x08a0…08c0 4f 4d 2b 34 30 5d 3b 0a 09 63 68 61 72 20 2a 6d 65 73 73 61 67 65 20 3d 20 22 4c 69 73 74 69 6e   ┆OM+40];  char *message = "Listin┆
0x08c0…08e0 67 20 63 6f 6d 70 6c 65 74 65 3a 20 25 2e 2a 73 5c 6e 22 3b 0a 0a 09 69 66 20 28 28 63 66 70 20   ┆g complete: %.*s\n";   if ((cfp ┆
0x08e0…0900 3d 20 66 6f 70 65 6e 28 63 66 6e 61 6d 65 2c 20 22 72 22 29 29 20 21 3d 20 4e 55 4c 4c 29 20 7b   ┆= fopen(cfname, "r")) != NULL) {┆
0x0900…0920 0a 61 67 61 69 6e 3a 0a 09 09 70 72 69 6e 74 69 6e 67 20 3d 20 31 3b 0a 09 09 66 70 72 69 6e 74   ┆ again:   printing = 1;   fprint┆
0x0920…0940 66 28 6c 70 2c 20 22 25 73 5c 6e 5c 6e 22 2c 20 63 66 6e 61 6d 65 29 3b 0a 09 09 77 68 69 6c 65   ┆f(lp, "%s\n\n", cfname);   while┆
0x0940…0960 20 28 6c 67 65 74 73 28 63 66 6c 69 6e 65 2c 20 73 69 7a 65 6f 66 20 63 66 6c 69 6e 65 2c 20 63   ┆ (lgets(cfline, sizeof cfline, c┆
0x0960…0980 66 70 29 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 09 69 66 20 28 21 70 72 69 6e 74 69 6e 67 29   ┆fp) != NULL) {    if (!printing)┆
0x0980…09a0 0a 09 09 09 09 6d 65 73 73 61 67 65 20 3d 20 22 4c 69 73 74 69 6e 67 20 6b 69 6c 6c 65 64 20 62   ┆     message = "Listing killed b┆
0x09a0…09c0 79 20 6f 72 64 65 72 3a 20 25 2e 2a 73 5c 6e 22 3b 0a 09 09 09 65 6c 73 65 20 69 66 20 28 70 72   ┆y order: %.*s\n";    else if (pr┆
0x09c0…09e0 69 6e 74 69 6e 67 20 3c 20 30 29 20 7b 0a 09 09 09 09 72 65 77 69 6e 64 28 63 66 70 29 3b 0a 09   ┆inting < 0) {     rewind(cfp);  ┆
0x09e0…0a00 09 09 09 70 75 74 63 28 46 46 2c 20 6c 70 29 3b 0a 09 09 09 09 67 6f 74 6f 20 61 67 61 69 6e 3b   ┆   putc(FF, lp);     goto again;┆
0x0a00…0a20 0a 09 09 09 7d 0a 09 09 09 73 77 69 74 63 68 20 28 63 66 6c 69 6e 65 5b 30 5d 29 20 7b 0a 09 09   ┆    }    switch (cfline[0]) {   ┆
0x0a20…0a40 09 63 61 73 65 20 27 41 27 3a 0a 09 09 09 09 69 66 20 28 70 72 69 6e 74 28 63 66 6c 69 6e 65 2b   ┆ case 'A':     if (print(cfline+┆
0x0a40…0a60 31 29 29 20 7b 0a 09 09 09 09 09 6d 65 73 73 61 67 65 20 3d 20 22 50 72 69 6e 74 65 72 20 66 69   ┆1)) {      message = "Printer fi┆
0x0a60…0a80 6c 65 20 65 72 72 6f 72 3a 20 25 2e 2a 73 5c 6e 22 3b 0a 09 09 09 09 09 73 74 72 63 70 79 28 63   ┆le error: %.*s\n";      strcpy(c┆
0x0a80…0aa0 6f 6d 6d 65 6e 74 2c 20 63 66 6c 69 6e 65 2b 31 29 3b 0a 09 09 09 09 7d 0a 09 09 09 09 62 72 65   ┆omment, cfline+1);     }     bre┆
0x0aa0…0ac0 61 6b 3b 0a 0a 09 09 09 63 61 73 65 20 27 44 27 3a 0a 09 09 09 09 73 74 72 63 70 79 28 63 6f 6d   ┆ak;     case 'D':     strcpy(com┆
0x0ac0…0ae0 6d 65 6e 74 2c 20 63 66 6c 69 6e 65 2b 31 29 3b 0a 09 09 09 09 62 72 65 61 6b 3b 0a 0a 09 09 09   ┆ment, cfline+1);     break;     ┆
0x0ae0…0b00 63 61 73 65 20 27 4c 27 3a 0a 09 09 09 09 69 66 20 28 70 72 69 6e 74 69 6e 67 20 3e 20 30 29 20   ┆case 'L':     if (printing > 0) ┆
0x0b00…0b20 7b 0a 09 09 09 09 09 63 66 6c 69 6e 65 5b 42 41 4e 57 49 44 2b 31 5d 20 3d 20 27 5c 30 27 3b 0a   ┆{      cfline[BANWID+1] = '\0'; ┆
0x0b20…0b40 2f 2a 20 50 61 70 65 72 20 74 69 67 65 72 20 63 6f 6e 74 72 6f 6c 73 0a 09 09 09 09 09 70 75 74   ┆/* Paper tiger controls      put┆
0x0b40…0b60 63 28 53 4d 41 4c 4c 2c 20 6c 70 29 3b 0a 20 2a 2f 0a 09 09 09 09 09 62 61 6e 6e 65 72 28 63 66   ┆c(SMALL, lp);  */      banner(cf┆
0x0b60…0b80 6c 69 6e 65 2b 31 2c 20 6c 70 29 3b 0a 2f 2a 20 50 61 70 65 72 20 74 69 67 65 72 20 63 6f 6e 74   ┆line+1, lp); /* Paper tiger cont┆
0x0b80…0ba0 72 6f 6c 73 0a 09 09 09 09 09 70 75 74 63 28 4e 4f 52 4d 41 4c 2c 20 6c 70 29 3b 0a 20 2a 2f 0a   ┆rols      putc(NORMAL, lp);  */ ┆
0x0ba0…0bc0 09 09 09 09 7d 0a 09 09 09 09 62 72 65 61 6b 3b 0a 0a 09 09 09 63 61 73 65 20 27 4d 27 3a 0a 09   ┆    }     break;     case 'M':  ┆
0x0bc0…0be0 09 09 09 73 70 72 69 6e 74 66 28 6d 62 75 66 2c 20 6d 65 73 73 61 67 65 2c 20 4d 41 58 43 4f 4d   ┆   sprintf(mbuf, message, MAXCOM┆
0x0be0…0c00 2c 20 63 6f 6d 6d 65 6e 74 29 3b 0a 09 09 09 09 6e 6f 74 69 66 79 28 63 66 6c 69 6e 65 2b 31 2c   ┆, comment);     notify(cfline+1,┆
0x0c00…0c20 20 6d 62 75 66 29 3b 0a 09 09 09 09 62 72 65 61 6b 3b 0a 0a 09 09 09 63 61 73 65 20 27 52 27 3a   ┆ mbuf);     break;     case 'R':┆
0x0c20…0c40 0a 09 09 09 09 2f 2a 20 43 68 61 72 67 65 20 49 44 20 2d 2d 20 6e 6f 74 20 75 73 65 64 20 2a 2f   ┆     /* Charge ID -- not used */┆
0x0c40…0c60 0a 09 09 09 09 62 72 65 61 6b 3b 0a 0a 09 09 09 63 61 73 65 20 27 55 27 3a 0a 09 09 09 09 75 6e   ┆     break;     case 'U':     un┆
0x0c60…0c80 6c 69 6e 6b 28 63 66 6c 69 6e 65 2b 31 29 3b 0a 09 09 09 09 62 72 65 61 6b 3b 0a 0a 09 09 09 64   ┆link(cfline+1);     break;     d┆
0x0c80…0ca0 65 66 61 75 6c 74 3a 0a 09 09 09 09 6c 70 65 72 72 28 22 42 61 64 20 63 6f 6e 74 72 6f 6c 20 6c   ┆efault:     lperr("Bad control l┆
0x0ca0…0cc0 69 6e 65 20 60 25 73 27 22 2c 20 63 66 6c 69 6e 65 29 3b 0a 09 09 09 7d 0a 09 09 7d 0a 09 09 66   ┆ine `%s'", cfline);    }   }   f┆
0x0cc0…0ce0 63 6c 6f 73 65 28 63 66 70 29 3b 0a 09 09 70 75 74 63 28 46 46 2c 20 6c 70 29 3b 0a 09 09 70 72   ┆close(cfp);   putc(FF, lp);   pr┆
0x0ce0…0d00 69 6e 74 69 6e 67 20 3d 20 30 3b 0a 09 7d 0a 09 75 6e 6c 69 6e 6b 28 63 66 6e 61 6d 65 29 3b 0a   ┆inting = 0;  }  unlink(cfname); ┆
0x0d00…0d20 7d 0a 0a 2f 2a 0a 20 2a 20 52 6f 75 74 69 6e 65 20 74 6f 20 6e 6f 74 69 66 79 20 61 20 75 73 65   ┆}  /*  * Routine to notify a use┆
0x0d20…0d40 72 20 61 62 6f 75 74 0a 20 2a 20 74 68 65 20 63 6f 6d 70 6c 65 74 69 6f 6e 20 6f 66 20 61 20 74   ┆r about  * the completion of a t┆
0x0d40…0d60 72 61 6e 73 61 63 74 69 6f 6e 0a 20 2a 20 55 73 75 61 6c 6c 79 20 63 61 6c 6c 65 64 20 62 79 20   ┆ransaction  * Usually called by ┆
0x0d60…0d80 73 6f 6d 65 20 64 61 65 6d 6f 6e 20 28 65 2e 67 2e 0a 20 2a 20 6c 69 6e 65 20 70 72 69 6e 74 65   ┆some daemon (e.g.  * line printe┆
0x0d80…0da0 72 20 64 61 65 6d 6f 6e 29 2e 0a 20 2a 20 52 65 74 75 72 6e 20 6e 6f 6e 2d 7a 65 72 6f 20 6f 6e   ┆r daemon).  * Return non-zero on┆
0x0da0…0dc0 20 66 61 69 6c 75 72 65 2e 0a 20 2a 2f 0a 6e 6f 74 69 66 79 28 6e 61 6d 65 2c 20 6d 73 67 29 0a   ┆ failure.  */ notify(name, msg) ┆
0x0dc0…0de0 63 68 61 72 20 2a 6e 61 6d 65 3b 0a 63 68 61 72 20 2a 6d 73 67 3b 0a 7b 0a 09 72 65 67 69 73 74   ┆char *name; char *msg; {  regist┆
0x0de0…0e00 65 72 20 73 74 72 75 63 74 20 70 61 73 73 77 64 20 2a 70 77 70 3b 0a 09 69 6e 74 20 70 66 64 5b   ┆er struct passwd *pwp;  int pfd[┆
0x0e00…0e20 32 5d 3b 0a 09 72 65 67 69 73 74 65 72 20 69 6e 74 20 70 69 64 2c 20 66 64 3b 0a 09 69 6e 74 20   ┆2];  register int pid, fd;  int ┆
0x0e20…0e40 73 74 61 74 75 73 3b 0a 0a 09 69 66 20 28 2a 6e 61 6d 65 3e 3d 27 30 27 20 26 26 20 2a 6e 61 6d   ┆status;   if (*name>='0' && *nam┆
0x0e40…0e60 65 3c 3d 27 39 27 29 0a 09 09 69 66 20 28 28 70 77 70 20 3d 20 67 65 74 70 77 75 69 64 28 61 74   ┆e<='9')   if ((pwp = getpwuid(at┆
0x0e60…0e80 6f 69 28 6e 61 6d 65 29 29 29 20 3d 3d 20 4e 55 4c 4c 29 0a 09 09 09 6e 61 6d 65 20 3d 20 4e 55   ┆oi(name))) == NULL)    name = NU┆
0x0e80…0ea0 4c 4c 3b 20 65 6c 73 65 0a 09 09 09 6e 61 6d 65 20 3d 20 70 77 70 2d 3e 70 77 5f 6e 61 6d 65 3b   ┆LL; else    name = pwp->pw_name;┆
0x0ea0…0ec0 0a 09 69 66 20 28 6e 61 6d 65 3d 3d 4e 55 4c 4c 20 7c 7c 20 70 69 70 65 28 70 66 64 29 3c 30 20   ┆  if (name==NULL || pipe(pfd)<0 ┆
0x0ec0…0ee0 7c 7c 20 28 70 69 64 20 3d 20 66 6f 72 6b 28 29 29 3c 30 29 0a 09 09 72 65 74 75 72 6e 20 28 31   ┆|| (pid = fork())<0)   return (1┆
0x0ee0…0f00 29 3b 0a 09 69 66 20 28 70 69 64 29 20 7b 0a 09 09 63 6c 6f 73 65 28 70 66 64 5b 30 5d 29 3b 0a   ┆);  if (pid) {   close(pfd[0]); ┆
0x0f00…0f20 09 09 77 72 69 74 65 28 70 66 64 5b 31 5d 2c 20 6d 73 67 2c 20 73 74 72 6c 65 6e 28 6d 73 67 29   ┆  write(pfd[1], msg, strlen(msg)┆
0x0f20…0f40 29 3b 0a 09 09 63 6c 6f 73 65 28 70 66 64 5b 31 5d 29 3b 0a 09 09 77 68 69 6c 65 20 28 77 61 69   ┆);   close(pfd[1]);   while (wai┆
0x0f40…0f60 74 28 26 73 74 61 74 75 73 29 20 3e 3d 20 30 29 0a 09 09 09 3b 0a 09 7d 20 65 6c 73 65 20 7b 0a   ┆t(&status) >= 0)    ;  } else { ┆
0x0f60…0f80 09 09 63 6c 6f 73 65 28 70 66 64 5b 31 5d 29 3b 0a 09 09 64 75 70 32 28 70 66 64 5b 30 5d 2c 20   ┆  close(pfd[1]);   dup2(pfd[0], ┆
0x0f80…0fa0 30 29 3b 0a 09 09 63 6c 6f 73 65 28 70 66 64 5b 30 5d 29 3b 0a 09 09 66 6f 72 20 28 66 64 3d 33   ┆0);   close(pfd[0]);   for (fd=3┆
0x0fa0…0fc0 3b 20 66 64 3c 5f 4e 46 49 4c 45 3b 20 66 64 2b 2b 29 0a 09 09 09 63 6c 6f 73 65 28 66 64 29 3b   ┆; fd<_NFILE; fd++)    close(fd);┆
0x0fc0…0fe0 0a 09 09 65 78 65 63 6c 70 28 22 2f 62 69 6e 2f 6d 61 69 6c 22 2c 20 22 6d 61 69 6c 22 2c 20 6e   ┆   execlp("/bin/mail", "mail", n┆
0x0fe0…1000 61 6d 65 2c 20 4e 55 4c 4c 29 3b 0a 09 09 72 65 74 75 72 6e 20 28 31 29 3b 0a 09 7d 0a 09 72 65   ┆ame, NULL);   return (1);  }  re┆
0x1000…1020 74 75 72 6e 20 28 30 29 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20 43 61 6e 63 65 6c 20 74 68 65 20 6c 69   ┆turn (0); }  /*  * Cancel the li┆
0x1020…1040 73 74 69 6e 67 20 74 68 61 74 20 69 73 20 70 72 69 6e 74 69 6e 67 0a 20 2a 20 6a 75 73 74 20 6e   ┆sting that is printing  * just n┆
0x1040…1060 6f 77 2e 0a 20 2a 2f 0a 63 61 6e 63 65 6c 28 29 0a 7b 0a 09 73 69 67 6e 61 6c 28 53 49 47 54 52   ┆ow.  */ cancel() {  signal(SIGTR┆
0x1060…1080 41 50 2c 20 53 49 47 5f 49 47 4e 29 3b 0a 09 69 66 20 28 70 72 69 6e 74 69 6e 67 29 20 7b 0a 09   ┆AP, SIG_IGN);  if (printing) {  ┆
0x1080…10a0 09 70 72 69 6e 74 69 6e 67 20 3d 20 30 3b 0a 09 09 66 70 72 69 6e 74 66 28 6c 70 2c 20 22 5c 6e   ┆ printing = 0;   fprintf(lp, "\n┆
0x10a0…10c0 5c 6e 5c 6e 4c 69 73 74 69 6e 67 20 63 61 6e 63 65 6c 6c 65 64 20 62 79 20 6f 72 64 65 72 5c 6e   ┆\n\nListing cancelled by order\n┆
0x10c0…10e0 22 29 3b 0a 09 7d 0a 09 73 69 67 6e 61 6c 28 53 49 47 54 52 41 50 2c 20 63 61 6e 63 65 6c 29 3b   ┆");  }  signal(SIGTRAP, cancel);┆
0x10e0…1100 0a 7d 0a 0a 2f 2a 0a 20 2a 20 52 65 73 74 61 72 74 20 74 68 65 20 6c 69 73 74 69 6e 67 20 74 68   ┆ }  /*  * Restart the listing th┆
0x1100…1120 61 74 0a 20 2a 20 69 73 20 72 75 6e 6e 69 6e 67 20 6a 75 73 74 20 6e 6f 77 2e 0a 20 2a 2f 0a 72   ┆at  * is running just now.  */ r┆
0x1120…1140 65 73 74 61 72 74 28 29 0a 7b 0a 09 73 69 67 6e 61 6c 28 53 49 47 52 45 53 54 2c 20 53 49 47 5f   ┆estart() {  signal(SIGREST, SIG_┆
0x1140…1160 49 47 4e 29 3b 0a 09 69 66 20 28 70 72 69 6e 74 69 6e 67 29 20 7b 0a 09 09 70 72 69 6e 74 69 6e   ┆IGN);  if (printing) {   printin┆
0x1160…1180 67 20 3d 20 2d 31 3b 0a 09 09 66 70 72 69 6e 74 66 28 6c 70 2c 20 22 5c 6e 5c 6e 5c 6e 4c 69 73   ┆g = -1;   fprintf(lp, "\n\n\nLis┆
0x1180…11a0 74 69 6e 67 20 72 65 73 74 61 72 74 65 64 20 62 79 20 6f 72 64 65 72 5c 6e 22 29 3b 0a 09 7d 0a   ┆ting restarted by order\n");  } ┆
0x11a0…11c0 09 73 69 67 6e 61 6c 28 53 49 47 52 45 53 54 2c 20 72 65 73 74 61 72 74 29 3b 0a 7d 0a 0a 2f 2a   ┆ signal(SIGREST, restart); }  /*┆
0x11c0…11e0 0a 20 20 2a 20 4c 69 6b 65 20 66 67 65 74 73 20 62 75 74 20 6e 6f 20 6e 65 77 6c 69 6e 65 20 69   ┆   * Like fgets but no newline i┆
0x11e0…1200 73 20 70 75 74 20 61 74 20 74 68 65 20 65 6e 64 0a 20 2a 20 6f 66 20 74 68 65 20 73 74 72 69 6e   ┆s put at the end  * of the strin┆
0x1200…1220 67 2e 20 20 41 6c 73 6f 20 74 68 65 20 72 65 73 74 20 6f 66 20 61 6e 20 69 6e 70 75 74 0a 20 2a   ┆g.  Also the rest of an input  *┆
0x1220…1240 20 6c 69 6e 65 20 69 73 20 66 6c 75 73 68 65 64 20 6f 6e 20 74 72 15 75 6e 63 61 74 65 64 20 73   ┆ line is flushed on tr uncated s┆
0x1240…1260 74 72 69 6e 67 73 2e 0a 20 2a 2f 0a 63 68 61 72 20 2a 0a 6c 67 65 74 73 28 61 73 2c 20 6c 69 6d   ┆trings.  */ char * lgets(as, lim┆
0x1260…1280 2c 20 69 6f 70 29 0a 63 68 61 72 20 2a 61 73 3b 0a 72 65 67 69 73 74 65 72 20 6c 69 6d 3b 0a 46   ┆, iop) char *as; register lim; F┆
0x1280…12a0 49 4c 45 20 2a 69 6f 70 3b 0a 7b 0a 09 72 65 67 69 73 74 65 72 20 63 3b 0a 09 72 65 67 69 73 74   ┆ILE *iop; {  register c;  regist┆
0x12a0…12c0 65 72 20 63 68 61 72 20 2a 73 3b 0a 0a 09 73 20 3d 20 61 73 3b 0a 09 77 68 69 6c 65 20 28 2d 2d   ┆er char *s;   s = as;  while (--┆
0x12c0…12e0 6c 69 6d 20 3e 20 30 20 26 26 20 28 63 20 3d 20 67 65 74 63 28 69 6f 70 29 29 20 21 3d 20 45 4f   ┆lim > 0 && (c = getc(iop)) != EO┆
0x12e0…1300 46 29 0a 09 09 69 66 20 28 28 2a 73 2b 2b 20 3d 20 63 29 20 3d 3d 20 27 5c 6e 27 29 20 7b 0a 09   ┆F)   if ((*s++ = c) == '\n') {  ┆
0x1300…1320 09 09 73 2d 2d 3b 0a 09 09 09 62 72 65 61 6b 3b 0a 09 09 7d 0a 09 2a 73 20 3d 20 30 3b 0a 09 69   ┆  s--;    break;   }  *s = 0;  i┆
0x1320…1340 66 20 28 6c 69 6d 3d 3d 30 20 26 26 20 63 21 3d 27 5c 6e 27 29 0a 09 09 77 68 69 6c 65 20 28 28   ┆f (lim==0 && c!='\n')   while ((┆
0x1340…1360 63 20 3d 20 67 65 74 63 28 69 6f 70 29 29 21 3d 27 5c 6e 27 20 26 26 20 63 21 3d 45 4f 46 29 0a   ┆c = getc(iop))!='\n' && c!=EOF) ┆
0x1360…1380 09 09 09 3b 0a 09 72 65 74 75 72 6e 20 28 63 3d 3d 45 4f 46 20 26 26 20 73 3d 3d 61 73 20 3f 20   ┆   ;  return (c==EOF && s==as ? ┆
0x1380…13a0 4e 55 4c 4c 20 3a 20 61 73 29 3b 0a 7d 0a 0a 2f 2a 20 56 41 52 41 52 47 53 20 2a 2f 0a 6c 70 65   ┆NULL : as); }  /* VARARGS */ lpe┆
0x13a0…13c0 72 72 28 78 29 0a 7b 0a 09 66 70 72 69 6e 74 66 28 73 74 64 65 72 72 2c 20 22 6c 70 64 3a 20 25   ┆rr(x) {  fprintf(stderr, "lpd: %┆
0x13c0…13e0 72 22 2c 20 26 78 29 3b 0a 09 70 75 74 63 28 27 5c 6e 27 2c 20 73 74 64 65 72 72 29 3b 0a 09 72   ┆r", &x);  putc('\n', stderr);  r┆
0x13e0…1400 6d 65 78 69 74 28 31 29 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20 52 65 6d 6f 76 65 20 6c 6f 63 6b 20 66   ┆mexit(1); }  /*  * Remove lock f┆
0x1400…1420 69 6c 65 20 61 6e 64 20 65 78 69 74 0a 20 2a 2f 0a 72 6d 65 78 69 74 28 73 29 0a 7b 0a 09 75 6e   ┆ile and exit  */ rmexit(s) {  un┆
0x1420…143c 6c 69 6e 6b 28 6c 6f 63 6b 66 69 6c 65 29 3b 0a 09 65 78 69 74 28 73 29 3b 0a 7d 0a   ┆link(lockfile);  exit(s); } ┆