1: char mesg[3000];
2: int msize;
3: struct
4: {
5: char name[8];
6: char tty[2];
7: int time[2];
8: int junk;
9: } utmp[50];
10:
11: main(argc, argv)
12: char *argv[];
13: {
14: register i, *p;
15: int f;
16:
17: f = open("/etc/utmp", 0);
18: if(f < 0) {
19: printf("utmp?\n");
20: exit();
21: }
22: read(f, utmp, sizeof utmp);
23: close(f);
24: f = 0;
25: if(argc >= 2) {
26: f = open(argv[1], 0);
27: if(f < 0) {
28: printf("%s?\n", argv[1]);
29: exit();
30: }
31: }
32: while((i = read(f, &mesg[msize], sizeof mesg - msize)) > 0)
33: msize =+ i;
34: close(f);
35: for(i=0; i<sizeof utmp/sizeof utmp[0]; i++) {
36: p = &utmp[i];
37: if(p->tty[0] == 0)
38: continue;
39: sleep(1);
40: sendmes(p->tty[0]);
41: }
42: }
43:
44: sendmes(tty)
45: {
46: register i;
47: register char *s;
48:
49: i = fork();
50: if(i == -1) {
51: printf("try again\n");
52: return;
53: }
54: if(i)
55: return;
56: s = "/dev/ttyx";
57: s[8] = tty;
58: i = open(s, 1);
59: if(i < 0) {
60: printf("cannot open tty%c\n", tty);
61: exit();
62: }
63: close(1);
64: dup(i);
65: printf("Broadcast Message ...\n\n");
66: write(1, mesg, msize);
67: exit();
68: }
Defined functions
main
defined in line
11;
never used
Defined variables
mesg
defined in line
1; used 3 times
msize
defined in line
2; used 4 times