|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T c
Length: 4072 (0xfe8) Types: TextFile Names: »cubestat.c«
└─⟦b20c6495f⟧ Bits:30007238 EUUGD18: Wien-båndet, efterår 1987 └─⟦this⟧ »EUUGD18/General/Cubes/cubestat.c«
/* vi:set sw=4 ts=4: */ #ifndef lint static char sccsid[] = "@(#)cubestat.c 5.1 (G.M. Paris) 89/01/22"; #endif lint /* ** ** cubes 5.1 Copyright 1989 Gregory M. Paris ** Permission granted to redistribute on a no charge basis. ** All other rights are reserved. ** */ #include <stdio.h> #include <sys/types.h> #include <sys/time.h> #include <sys/socket.h> #include <netinet/in.h> #include <netdb.h> #include <sysexits.h> #include "cubes.h" #define EX_CUBES_INPROGRESS 0 /* success */ #define EX_CUBES_IDLE 1 /* fail, sort of */ extern int optind; extern int opterr; extern char *optarg; extern char *getenv(); struct hostent *gethostbyname(); struct servent *getservbyname(); main(ac, av) char *av[]; { int c; char *cubehost = 0; /* server hostname */ register int qsock; struct sockaddr_in server; struct servent *ps; struct hostent *ph; struct timeval timo; fd_set rdy; char query; char status[STATLEN]; boolean waitforbeg = False; boolean waitforend = False; opterr = 0; while((c = getopt(ac, av, "beh:")) >= 0) { switch(c) { case 'b': waitforbeg = (waitforbeg == True) ? False : True; break; case 'e': waitforend = (waitforend == True) ? False : True; break; case 'h': cubehost = optarg; break; default: fprintf(stderr, "usage -- cubestat [-{be}] [-h host]\n"); exit(EX_USAGE); } } if(waitforbeg == True && waitforend == True) { fprintf(stderr, "cubestat: can't wait for both begin and end\n"); exit(EX_USAGE); } if(waitforbeg == True || waitforend == True) { static char fake[] = "lock -"; int n; for(c = 0;c < ac;++c) for(n = 0;av[c][n] != '\0';++n) av[c][n] = (c > 0 || n >= sizeof fake - 1) ? ' ' : fake[n]; } /* ** If cubehost hasn't been set, check the CUBEHOST environment variable. ** If cubehost is null or not set, use this host. */ if(cubehost == 0) cubehost = getenv("CUBEHOST"); if(cubehost == 0 || *cubehost == '\0') { static char thishost[256]; (void) gethostname(thishost, sizeof thishost); cubehost = thishost; } if((ph = gethostbyname(cubehost)) == 0) { fprintf(stderr, "cubestat: unknown host `%s'\n", cubehost); exit(EX_NOHOST); } /* ** Look up the cubestat service. */ if((ps = getservbyname("cubestat", "udp")) == 0) { fprintf(stderr, "cubestat: no cubestat/udp service listed\n"); exit(EX_UNAVAILABLE); } /* ** Get a datagram socket then point it at the server. */ if((qsock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { perror("cubestat: socket"); exit(EX_OSERR); } bzero((char *)&server, sizeof server); server.sin_family = AF_INET; server.sin_port = ps->s_port; bcopy(ph->h_addr, (char *)&server.sin_addr, ph->h_length); if(connect(qsock, &server, sizeof server) < 0) { perror("cubestat: connect"); exit(EX_OSERR); } /* ** For now, we only know how to ask for a roster. ** Set up for a few tries. We'll wait a reasonable time before retrying. */ query = Q_ROSTER; timo.tv_sec = 2 * READTIMO; timo.tv_usec = 0; for(c = 0;c < 3 || waitforbeg == True || waitforend == True;++c) { if(send(qsock, &query, sizeof query, 0) < 0) { perror("cubestat: send"); exit(EX_IOERR); } FD_ZERO(&rdy); FD_SET(qsock, &rdy); if(select(qsock+1, &rdy, NOSEL, NOSEL, &timo) > 0) { if(recv(qsock, status, STATLEN, 0) > 0) { switch(status[0]) { case S_IDLE: if(waitforbeg == False) { fputs(&status[1], stdout); exit(EX_CUBES_IDLE); } if(c % 20 == 0) fputs(&status[1], stdout); sleep(3); break; case S_ROSTER: fputs(&status[1], stdout); if(waitforend == False) exit(EX_CUBES_INPROGRESS); sleep(1); break; case S_UNRECOG: fprintf(stderr, "cubestat: unrecognized query \\%o\n", query); exit(EX_PROTOCOL); default: fprintf(stderr, "cubestat: unrecognized response \\%o\n", status[0]); exit(EX_PROTOCOL); } } } } fprintf(stderr, "cubestat: no response from server on %s\n", cubehost); exit(EX_UNAVAILABLE); }