home *** CD-ROM | disk | FTP | other *** search
/ minnie.tuhs.org / unixen.tar / unixen / PDP-11 / Trees / V7 / usr / src / cmd / wall.c < prev    next >
Encoding:
C/C++ Source or Header  |  1979-01-10  |  1.1 KB  |  69 lines

  1. #include <stdio.h>
  2. #include <utmp.h>
  3. #define    USERS    50
  4.  
  5. char    mesg[3000];
  6. int    msize;
  7. struct    utmp utmp[USERS];
  8. char    *strcpy();
  9. char    *strcat();
  10.  
  11. main(argc, argv)
  12. char *argv[];
  13. {
  14.     register i;
  15.     register struct utmp *p;
  16.     FILE *f;
  17.  
  18.     if((f = fopen("/etc/utmp", "r")) == NULL) {
  19.         fprintf(stderr, "Cannot open /etc/utmp\n");
  20.         exit(1);
  21.     }
  22.     fread((char *)utmp, sizeof(struct utmp), USERS, f);
  23.     fclose(f);
  24.     f = stdin;
  25.     if(argc >= 2) {
  26.         if((f = fopen(argv[1], "r")) == NULL) {
  27.             fprintf(stderr,"Cannot open %s\n", argv[1]);
  28.             exit(1);
  29.         }
  30.     }
  31.     while((i = getc(f)) != EOF) mesg[msize++] = i;
  32.     fclose(f);
  33.     for(i=0; i<USERS; i++) {
  34.         p = &utmp[i];
  35.         if(p->ut_name[0] == 0)
  36.             continue;
  37.         sleep(1);
  38.         sendmes(p->ut_line);
  39.     }
  40.     exit(0);
  41. }
  42.  
  43. sendmes(tty)
  44. char *tty;
  45. {
  46.     register i;
  47.     char t[50], buf[BUFSIZ];
  48.     FILE *f;
  49.  
  50.     i = fork();
  51.     if(i == -1) {
  52.         fprintf(stderr, "Try again\n");
  53.         return;
  54.     }
  55.     if(i)
  56.         return;
  57.     strcpy(t, "/dev/");
  58.     strcat(t, tty);
  59.  
  60.     if((f = fopen(t, "w")) == NULL) {
  61.         fprintf(stderr,"cannot open %s\n", t);
  62.         exit(1);
  63.     }
  64.     setbuf(f, buf);
  65.     fprintf(f, "Broadcast Message ...\n\n");
  66.     fwrite(mesg, msize, 1, f);
  67.     exit(0);
  68. }
  69.