Annotation of 40BSD/cmd/cifplot/dump.c, revision 1.1.1.1

1.1       root        1: 
                      2: #include <stdio.h>
                      3: #include <sys/types.h>
                      4: #include <sys/stat.h>
                      5: #include <sys/vcmd.h>
                      6: #include <signal.h>
                      7: #include <errno.h>
                      8: 
                      9: char * LOCK    = "/usr/spool/vad/lock";
                     10: char * DEVICE  = "/dev/va0";
                     11: char * DAEMON  = "/usr/lib/vad";
                     12: char * NAME    = "Varian";
                     13: 
                     14: extern char *ctime(),*getlogin();
                     15: 
                     16: #define BUFSIZE        16384
                     17: char vpbuf[BUFSIZE];
                     18: 
                     19: extern int errno;
                     20: extern quit();
                     21: 
                     22: int plotmd [] = { VPLOT, 0, 0 };
                     23: int prtmd  [] = { VPRINT, 0, 0 };
                     24: int vp;
                     25: FILE *f;
                     26: struct stat stbuf;
                     27: long clock;
                     28: int running;
                     29: char *name;
                     30: char **argv;
                     31: int argc;
                     32: int offline = 0;
                     33: 
                     34: main(count,v)
                     35: int count;
                     36: char **v;
                     37: {
                     38:      int i,k;
                     39:      argv = v;
                     40:      argc = count;
                     41:      name = argv[1];
                     42: 
                     43:      if(argc < 2) {
                     44:        fprintf(stderr,"Usage: %s bit_file [banner [message]] [-W]\n",argv[0]);
                     45:        exit(1);
                     46:        }
                     47: 
                     48:      if( (f=fopen(argv[1],"r")) == NULL) {
                     49:        fprintf(stderr,"Can't open %s\n",argv[1]);
                     50:        exit(1);
                     51:        }
                     52:      
                     53:      for(i=0;i<16;i++)
                     54:        signal(i,quit);
                     55: 
                     56:      signal(SIGHUP,SIG_IGN);
                     57:      signal(SIGINT,SIG_IGN);
                     58: 
                     59:      if( '-' == argv[argc-1][0]) {
                     60:        switch(argv[argc-1][1]) {
                     61:                case 'W':
                     62:                        LOCK   = "/usr/spool/vpd/lock";
                     63:                        DEVICE = "/dev/vp0";
                     64:                        NAME   = "Versatec";
                     65:                        DAEMON = "/usr/lib/vpd";
                     66:                        break;
                     67:                case 'V':
                     68:                        break;
                     69:                default:
                     70:                        fprintf(stderr,"%s: unknown option - quit\n",argv[argc-1]);
                     71:                        quit(0);
                     72:                }
                     73:        argc--;
                     74:        }
                     75: 
                     76:      while( stat(LOCK, &stbuf) >= 0) {
                     77:        sleep(30);
                     78:        }
                     79: 
                     80:      if( creat(LOCK, 0666) < 0) {
                     81:        fprintf(stderr,"Can't create %s\n",LOCK);
                     82:        quit(0);
                     83:        }
                     84:      
                     85:      while(1) {
                     86:        if( (vp = open(DEVICE, 1)) >= 0) break;
                     87:        if( errno != EIO ) {
                     88:            perror(DEVICE);
                     89:            quit(0);
                     90:            }
                     91:        if(offline == 0) {
                     92:            fprintf(stderr,"%s is offline\n",NAME);
                     93:            offline = 1;
                     94:            }
                     95:        sleep(30);
                     96:        }
                     97: 
                     98:      /*
                     99:      if( (vp = open(DEVICE, 1)) < 0) {
                    100:        printf("Put the %s on line\n",NAME);
                    101:        for( k=0; k<24 && vp == NULL; k++) {
                    102:                sleep(10);
                    103:                vp = open(DEVICE,1);
                    104:                }
                    105:        if( vp == NULL ) {
                    106:                fprintf(stderr,"Can't open %s\n",NAME);
                    107:                unlink(LOCK);
                    108:                quit(0);
                    109:                }
                    110:        }
                    111:        */
                    112: 
                    113:      ioctl(vp, VSETSTATE, prtmd);
                    114:      running = 1;
                    115: 
                    116:      clock = time(0);
                    117:      if(argc < 3)
                    118:        sprintf(vpbuf, "%s: %s\n",getlogin(),ctime(&clock));
                    119:       else
                    120:        sprintf(vpbuf, "%s: %s%s\n",getlogin(),ctime(&clock),argv[2]);
                    121:      write(vp, vpbuf, BUFSIZE);
                    122: 
                    123:      ioctl( vp, VSETSTATE, plotmd);
                    124:      while( (i=read(fileno(f),vpbuf, BUFSIZE)) > 0)
                    125:                write(vp,vpbuf,i);
                    126:      quit(-1);
                    127:      }
                    128: 
                    129: quit(n)
                    130: int n;
                    131: {
                    132:     if(running) {
                    133:        ioctl(vp, VSETSTATE, prtmd);
                    134:        write(vp, "\f\f", 2);
                    135:        }
                    136:     close(vp);
                    137:     unlink(LOCK);
                    138:     unlink(name);
                    139:     if(n < 0) {
                    140:        if(argc > 2)  fprintf(stderr,"%s\n",argv[3]);
                    141:        }
                    142:       else fprintf(stderr,"Plotting Aborted\n");
                    143:     execl( DAEMON, DAEMON, 0 );
                    144:     exit(0);
                    145:     }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.