Print this page
2849 uptime should use locale settings for current time


 112                         *p_sibling,     /* sibling pointer */
 113                         *p_pgrpl,       /* pgrp link */
 114                         *p_link;        /* hash table chain pointer */
 115 };
 116 
 117 /*
 118  *      define hash table for struct uproc
 119  *      Hash function uses process id
 120  *      and the size of the hash table(HSIZE)
 121  *      to determine process index into the table.
 122  */
 123 static struct uproc     pr_htbl[HSIZE];
 124 
 125 static struct   uproc   *findhash(pid_t);
 126 static time_t   findidle(char *);
 127 static void     clnarglist(char *);
 128 static void     showtotals(struct uproc *);
 129 static void     calctotals(struct uproc *);
 130 static void     prttime(time_t, char *);
 131 static void     prtat(time_t *time);
 132 static void     checkampm(char *str);
 133 
 134 static char     *prog;          /* pointer to invocation name */
 135 static int      header = 1;     /* true if -h flag: don't print heading */
 136 static int      lflag = 1;      /* set if -l flag; 0 for -s flag: short form */
 137 static char     *sel_user;      /* login of particular user selected */
 138 static char     firstchar;      /* first char of name of prog invoked as */
 139 static int      login;          /* true if invoked as login shell */
 140 static time_t   now;            /* current time of day */
 141 static time_t   uptime;         /* time of last reboot & elapsed time since */
 142 static int      nusers;         /* number of users logged in now */
 143 static time_t   idle;           /* number of minutes user is idle */
 144 static time_t   jobtime;        /* total cpu time visible */
 145 static char     doing[520];     /* process attached to terminal */
 146 static time_t   proctime;       /* cpu time of process in doing */
 147 static pid_t    curpid, empty;
 148 static int      add_times;      /* boolean: add the cpu times or not */
 149 
 150 #if SIGQUIT > SIGINT
 151 #define ACTSIZE SIGQUIT
 152 #else


 659         } else if (tim > 0) {
 660                 PRINTF((dcgettext(NULL, "    %2d", LC_TIME), (int)tim));
 661         } else {
 662                 PRINTF(("      "));
 663         }
 664         PRINTF(("%s", tail));
 665 }
 666 
 667 /*
 668  * prints a 12 hour time given a pointer to a time of day
 669  */
 670 static void
 671 prtat(time_t *time)
 672 {
 673         struct tm       *p;
 674 
 675         p = localtime(time);
 676         if (now - *time <= 18 * HR) {
 677                 char timestr[50];
 678                 (void) strftime(timestr, sizeof (timestr),
 679                     dcgettext(NULL, "%l:%M""%p", LC_TIME), p);
 680                 checkampm(timestr);
 681                 PRINTF((" %s", timestr));
 682         } else if (now - *time <= 7 * DAY) {
 683                 char weekdaytime[20];
 684 
 685                 (void) strftime(weekdaytime, sizeof (weekdaytime),
 686                     dcgettext(NULL, "%a%l%p", LC_TIME), p);
 687                 checkampm(weekdaytime);
 688                 PRINTF((" %s", weekdaytime));
 689         } else {
 690                 char monthtime[20];
 691 
 692                 (void) strftime(monthtime, sizeof (monthtime),
 693                     dcgettext(NULL, "%e%b%y", LC_TIME), p);
 694                 PRINTF((" %s", monthtime));
 695         }
 696 }
 697 
 698 /*
 699  * find & return number of minutes current tty has been idle
 700  */
 701 static time_t
 702 findidle(char *devname)
 703 {
 704         struct stat stbuf;
 705         time_t lastaction, diff;
 706         char ttyname[64];
 707 
 708         (void) strcpy(ttyname, "/dev/");
 709         (void) strcat(ttyname, devname);
 710         if (stat(ttyname, &stbuf) != -1) {
 711                 lastaction = stbuf.st_atime;
 712                 diff = now - lastaction;
 713                 diff = DIV60(diff);


 721 /*
 722  * given a pointer to the argument string get rid of unsavory characters.
 723  */
 724 static void
 725 clnarglist(char *arglist)
 726 {
 727         char    *c;
 728         int     err = 0;
 729 
 730         /* get rid of unsavory characters */
 731         for (c = arglist; *c != NULL; c++) {
 732                 if ((*c < ' ') || (*c > 0176)) {
 733                         if (err++ > 5) {
 734                                 *arglist = NULL;
 735                                 break;
 736                         }
 737                         *c = '?';
 738                 }
 739         }
 740 }
 741 
 742 /* replaces all occurences of AM/PM with am/pm */
 743 static void
 744 checkampm(char *str)
 745 {
 746         char *ampm;
 747         while ((ampm = strstr(str, "AM")) != NULL ||
 748             (ampm = strstr(str, "PM")) != NULL) {
 749                 *ampm = tolower(*ampm);
 750                 *(ampm+1) = tolower(*(ampm+1));
 751         }
 752 }


 112                         *p_sibling,     /* sibling pointer */
 113                         *p_pgrpl,       /* pgrp link */
 114                         *p_link;        /* hash table chain pointer */
 115 };
 116 
 117 /*
 118  *      define hash table for struct uproc
 119  *      Hash function uses process id
 120  *      and the size of the hash table(HSIZE)
 121  *      to determine process index into the table.
 122  */
 123 static struct uproc     pr_htbl[HSIZE];
 124 
 125 static struct   uproc   *findhash(pid_t);
 126 static time_t   findidle(char *);
 127 static void     clnarglist(char *);
 128 static void     showtotals(struct uproc *);
 129 static void     calctotals(struct uproc *);
 130 static void     prttime(time_t, char *);
 131 static void     prtat(time_t *time);

 132 
 133 static char     *prog;          /* pointer to invocation name */
 134 static int      header = 1;     /* true if -h flag: don't print heading */
 135 static int      lflag = 1;      /* set if -l flag; 0 for -s flag: short form */
 136 static char     *sel_user;      /* login of particular user selected */
 137 static char     firstchar;      /* first char of name of prog invoked as */
 138 static int      login;          /* true if invoked as login shell */
 139 static time_t   now;            /* current time of day */
 140 static time_t   uptime;         /* time of last reboot & elapsed time since */
 141 static int      nusers;         /* number of users logged in now */
 142 static time_t   idle;           /* number of minutes user is idle */
 143 static time_t   jobtime;        /* total cpu time visible */
 144 static char     doing[520];     /* process attached to terminal */
 145 static time_t   proctime;       /* cpu time of process in doing */
 146 static pid_t    curpid, empty;
 147 static int      add_times;      /* boolean: add the cpu times or not */
 148 
 149 #if SIGQUIT > SIGINT
 150 #define ACTSIZE SIGQUIT
 151 #else


 658         } else if (tim > 0) {
 659                 PRINTF((dcgettext(NULL, "    %2d", LC_TIME), (int)tim));
 660         } else {
 661                 PRINTF(("      "));
 662         }
 663         PRINTF(("%s", tail));
 664 }
 665 
 666 /*
 667  * prints a 12 hour time given a pointer to a time of day
 668  */
 669 static void
 670 prtat(time_t *time)
 671 {
 672         struct tm       *p;
 673 
 674         p = localtime(time);
 675         if (now - *time <= 18 * HR) {
 676                 char timestr[50];
 677                 (void) strftime(timestr, sizeof (timestr),
 678                     " %R  ", p);

 679                 PRINTF((" %s", timestr));
 680         } else if (now - *time <= 7 * DAY) {
 681                 char weekdaytime[20];
 682 
 683                 (void) strftime(weekdaytime, sizeof (weekdaytime),
 684                     "%a%H  ", p);

 685                 PRINTF((" %s", weekdaytime));
 686         } else {
 687                 char monthtime[20];
 688 
 689                 (void) strftime(monthtime, sizeof (monthtime),
 690                     "%e%b%y", p);
 691                 PRINTF((" %s", monthtime));
 692         }
 693 }
 694 
 695 /*
 696  * find & return number of minutes current tty has been idle
 697  */
 698 static time_t
 699 findidle(char *devname)
 700 {
 701         struct stat stbuf;
 702         time_t lastaction, diff;
 703         char ttyname[64];
 704 
 705         (void) strcpy(ttyname, "/dev/");
 706         (void) strcat(ttyname, devname);
 707         if (stat(ttyname, &stbuf) != -1) {
 708                 lastaction = stbuf.st_atime;
 709                 diff = now - lastaction;
 710                 diff = DIV60(diff);


 718 /*
 719  * given a pointer to the argument string get rid of unsavory characters.
 720  */
 721 static void
 722 clnarglist(char *arglist)
 723 {
 724         char    *c;
 725         int     err = 0;
 726 
 727         /* get rid of unsavory characters */
 728         for (c = arglist; *c != NULL; c++) {
 729                 if ((*c < ' ') || (*c > 0176)) {
 730                         if (err++ > 5) {
 731                                 *arglist = NULL;
 732                                 break;
 733                         }
 734                         *c = '?';
 735                 }
 736         }
 737 }