|
|
1.1 root 1: /* rwhod.c - rwhod */
2:
3: #include <conf.h>
4: #include <kernel.h>
5: #include <network.h>
6: #include <rwho.h>
7: #include <shell.h>
8:
9: /*------------------------------------------------------------------------
10: * rwhod - Periodically clean cache and (optionally) send rwho packets
11: *------------------------------------------------------------------------
12: */
13: PROCESS rwhod()
14: {
15: int i, j;
16: struct rwent *rwptr;
17: struct rwent *myptr;
18: struct rwhopac *rpacptr;
19: struct rw_who *rwwptr;
20: struct epacket *packet;
21: IPaddr mynet;
22: long now;
23: int len;
24: PStype ps;
25:
26: /* Initialize rwho information */
27:
28: Rwho.rwnent = 1;
29: Rwho.rwsend = TRUE;
30: getutim(&Rwho.rwbtime);
31: myptr = &Rwho.rwcache[0];
32: getname(myptr->rwmach);
33:
34: myptr->rwboot = myptr->rwlast = myptr->rwslast = Rwho.rwbtime;
35: for (i=0 ; i<3 ; i++)
36: myptr->rwload[i] = 0L;
37: myptr->rwusers = 1;
38:
39: getnet(mynet);
40: for( ; TRUE ; sleep(RWDELAY) ) {
41: getutim(&now);
42: myptr->rwlast = myptr->rwslast = now;
43: disable(ps);
44: for (i=0 ; i<Rwho.rwnent ; i++) {
45: rwptr = &Rwho.rwcache[i];
46: if (now - rwptr->rwlast > RWMAXDT) {
47: Rwho.rwnent--;
48: for (j=i-- ; j<Rwho.rwnent ; j++)
49: Rwho.rwcache[j] = Rwho.rwcache[j+1];
50: }
51: }
52: restore(ps);
53: if (!Rwho.rwsend)
54: continue;
55: packet = (struct epacket *)getbuf(Net.netpool);
56: rpacptr = (struct rwhopac *)
57: ((struct udp *)
58: (((struct ip *)packet->ep_data)->i_data))->u_data;
59: rpacptr->rw_vers = RWVERSION;
60: rpacptr->rw_type= RWSTATUS;
61: rpacptr->rw_sndtim = hl2net(now);
62: rpacptr->rw_rtim = 0L;
63: getname(rpacptr->rw_host);
64: for (j=0 ; j<RWNLOAD ; j++)
65: rpacptr->rw_load[j] = 0L;
66: rpacptr->rw_btim = hl2net(Rwho.rwbtime);
67: len = RWMINP;
68: if ( marked(Shl.shmark) && Shl.shused ) {
69: rwwptr = &rpacptr->rw_rww[0];
70: strcpy (rwwptr->rw_tty, "Console");
71: strncpy(rwwptr->rw_nam, Shl.shuser, RWNLEN);
72: rwwptr->rw_ton = hl2net(Shl.shlogon);
73: rwwptr->rw_idle = hl2net(now - Shl.shlast);
74: len += sizeof(struct rw_who);
75: }
76: udpsend(mynet, URWHO, URWHO, packet, len);
77: }
78: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.