Annotation of 43BSDTahoe/new/dsh/src/getloadave.c, revision 1.1

1.1     ! root        1: /*(@(#)getloadave.c    1.2             /ra/csr/presotto/hacks/src/worm/sccs/s.getloadave.c)*/
        !             2: #include <sys/types.h>
        !             3: #include <nlist.h>
        !             4: #include <sys/stat.h>
        !             5: 
        !             6: #define MAXRETRIES 20
        !             7: 
        !             8: struct nlist nl[] = {
        !             9: #define        NL_AVENRUN      0
        !            10:        { "_avenrun" },
        !            11:        0
        !            12: };
        !            13: int    kmemf = -1;             /* fd for kmem */
        !            14: time_t vmunixdate = 0;         /* update time for vmunix */
        !            15: 
        !            16: initnlist ()
        !            17: {
        !            18:     int                        i;
        !            19:     struct nlist       *nlp;
        !            20:     struct stat                sbuf;
        !            21: 
        !            22:     i = stat ("/vmunix", &sbuf);
        !            23:     if (i == -1) {
        !            24:        error ("can't read /vmunix");
        !            25:     }
        !            26:     if (vmunixdate != sbuf.st_mtime) {
        !            27:        for (i = 0; i < MAXRETRIES; sleep (5), i++) {
        !            28:            for (nlp = &nl[sizeof (nl) / sizeof (nl[0])]; --nlp >= nl; ) {
        !            29:                nlp->n_value = 0;
        !            30:                nlp->n_type = 0;
        !            31:            }
        !            32:            nlist("/vmunix", nl);
        !            33:            if (nl[0].n_value == 0) {
        !            34:                warn ("/vmunix namelist botch");
        !            35:                continue;
        !            36:            }
        !            37:            break;
        !            38:        }
        !            39:        if (i >= MAXRETRIES)
        !            40:            exit (-1);
        !            41:        vmunixdate = sbuf.st_mtime;
        !            42:     }
        !            43: 
        !            44:     if (kmemf == -1) {
        !            45:        kmemf = open("/dev/kmem", 0);
        !            46:        if (kmemf < 0) {
        !            47:            error ("opening /dev/kmem");
        !            48:        }
        !            49:     }
        !            50: }
        !            51: 
        !            52: 
        !            53: /*
        !            54:  *     Get the current load average 
        !            55:  */
        !            56: getloadave (avenrun)
        !            57: double *avenrun;
        !            58: {
        !            59:     double             template[3];
        !            60: 
        !            61:     initnlist ();
        !            62:     (void) lseek(kmemf, (long)nl[NL_AVENRUN].n_value, 0);
        !            63:     (void) read(kmemf, (char *)avenrun, sizeof (template));
        !            64: }

unix.superglobalmegacorp.com

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