Annotation of xinu/sys/shell/x_uptime.c, revision 1.1.1.1

1.1       root        1: /* x_uptime.c - x_uptime */
                      2: 
                      3: #include <conf.h>
                      4: #include <kernel.h>
                      5: #include <network.h>
                      6: #include <rwho.h>
                      7: 
                      8: /*------------------------------------------------------------------------
                      9:  *  x_uptime  -  (command uptime or ruptime) print remote machine status
                     10:  *------------------------------------------------------------------------
                     11:  */
                     12: COMMAND        x_uptime(stdin, stdout, stderr, nargs, args)
                     13: int    stdin, stdout, stderr, nargs;
                     14: char   *args[];
                     15: {
                     16:        int     i, j;
                     17:        struct  rwent   *rwptr;
                     18:        long    tottim;
                     19:        int     hours, days, mins;
                     20:        Bool    up;
                     21:        Bool    found, all;
                     22:        long    now;
                     23:        char    mach[32];
                     24:        char    str[80];
                     25: 
                     26:        switch (nargs) {
                     27: 
                     28:        case 1:
                     29:                if (strcmp(args[0],"ruptime") == 0) {
                     30:                        all = TRUE;
                     31:                        break;
                     32:                }
                     33:                getname(mach); /* called as "uptime" */
                     34:                args[1] = mach;
                     35:                /* fall through */
                     36:        case 2:
                     37:                all = FALSE;
                     38:                break;
                     39:        default:
                     40:                fprintf(stderr, "use: %s [host]\n", args[0]);
                     41:                return(SYSERR);
                     42:        }
                     43:        gettime(&now);
                     44:        found = FALSE;
                     45:        for (i=0 ; i<Rwho.rwnent ; i++) {
                     46:                rwptr = &Rwho.rwcache[i];
                     47:                if (!all && strcmp(rwptr->rwmach,args[1])!=0)
                     48:                        continue;
                     49:                found = TRUE;
                     50:                sprintf(str,"%-14s", rwptr->rwmach);
                     51:                tottim = now - rwptr->rwlast;
                     52:                if (up = (tottim < RWCDOWN))
                     53:                        tottim = rwptr->rwslast - rwptr->rwboot + 59;
                     54:                days = tottim / (24L * 60L * 60L);
                     55:                 tottim %= (24L * 60L * 60L);
                     56:                hours = tottim / (60L * 60L);
                     57:                 tottim %= (60L * 60L);
                     58:                mins = tottim / 60L;
                     59:                sprintf(&str[strlen(str)], "%s", up?"up  " : "down");
                     60:                if (days > 0)
                     61:                        sprintf(&str[strlen(str)], " %2d +", days);
                     62:                else
                     63:                        strcat(str, "     ");
                     64:                sprintf(&str[strlen(str)], " %2d:%02d", hours, mins);
                     65:                if (!up) {
                     66:                        strcat(str, "\n");
                     67:                        write(stdout, str, strlen(str));
                     68:                        continue;
                     69:                }
                     70:                sprintf(&str[strlen(str)],
                     71:                        "  %2d users,    load ", (int)rwptr->rwusers);
                     72:                for (j=0 ; j<RWNLOAD ; j++) {
                     73:                        if (j >0)
                     74:                                strcat(str, ", ");
                     75:                        sprintf(&str[strlen(str)], "%2d.%02d",
                     76:                                rwptr->rwload[j] / 100,
                     77:                                rwptr->rwload[j] % 100);
                     78:                }
                     79:                strcat(str, "\n");
                     80:                write(stdout, str, strlen(str));
                     81:        }
                     82:        if (!found && !all)
                     83:                fprintf(stderr, "%s ???\n", args[1]);
                     84:        return(OK);
                     85: }

unix.superglobalmegacorp.com

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