[BACK]Return to main.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / systat

Diff for /src/usr.bin/systat/main.c between version 1.34 and 1.35

version 1.34, 2006/05/09 17:09:22 version 1.35, 2007/02/25 18:21:24
Line 53 
Line 53 
 #include <stdio.h>  #include <stdio.h>
 #include <string.h>  #include <string.h>
 #include <unistd.h>  #include <unistd.h>
   #include <utmp.h>
 #include <stdlib.h>  #include <stdlib.h>
 #include <limits.h>  #include <limits.h>
 #include <stdarg.h>  #include <stdarg.h>
Line 69 
Line 70 
 u_int   naptime = 5;  u_int   naptime = 5;
 int     verbose = 1;            /* to report kvm read errs */  int     verbose = 1;            /* to report kvm read errs */
 int     nflag = 0;  int     nflag = 0;
 int     hz, stathz;  int     ut, hz, stathz;
 char    hostname[MAXHOSTNAMELEN];  char    hostname[MAXHOSTNAMELEN];
 WINDOW  *wnd;  WINDOW  *wnd;
 int     CMDLINE;  int     CMDLINE;
Line 81 
Line 82 
 int  int
 main(int argc, char *argv[])  main(int argc, char *argv[])
 {  {
         int ch;  
         char errbuf[_POSIX2_LINE_MAX];          char errbuf[_POSIX2_LINE_MAX];
         const char *errstr;          const char *errstr;
         gid_t gid;          gid_t gid;
           int ch;
   
           ut = open(_PATH_UTMP, O_RDONLY);
           if (ut < 0) {
                   error("No utmp");
                   exit(1);
           }
   
         kd = kvm_openfiles(NULL, NULL, NULL, O_RDONLY, errbuf);          kd = kvm_openfiles(NULL, NULL, NULL, O_RDONLY, errbuf);
         if (kd == NULL) {          if (kd == NULL) {
                 error("%s", errbuf);                  error("%s", errbuf);
Line 157 
Line 164 
                 warnx("couldn't initialize display");                  warnx("couldn't initialize display");
                 die();                  die();
         }          }
         wload = newwin(1, 0, 3, 20);          wload = newwin(1, 0, 1, 20);
         if (wload == NULL) {          if (wload == NULL) {
                 warnx("couldn't set up load average window");                  warnx("couldn't set up load average window");
                 die();                  die();
Line 207 
Line 214 
 void  void
 labels(void)  labels(void)
 {  {
         if (curcmd->c_flags & CF_LOADAV) {          if (curcmd->c_flags & CF_LOADAV)
                 mvaddstr(2, 20,                  mvprintw(0, 2 + 4, "users    Load");
                     "/0   /1   /2   /3   /4   /5   /6   /7   /8   /9   /10");  
                 mvaddstr(3, 5, "Load Average");  
         }  
         (*curcmd->c_label)();          (*curcmd->c_label)();
 #ifdef notdef  #ifdef notdef
         mvprintw(21, 25, "CPU usage on %s", hostname);          mvprintw(21, 25, "CPU usage on %s", hostname);
Line 229 
Line 233 
 void  void
 display(void)  display(void)
 {  {
         int i, j;  
         chtype c;  
   
         /* Get the load average over the last minute. */          /* Get the load average over the last minute. */
         (void) getloadavg(avenrun, sizeof(avenrun) / sizeof(avenrun[0]));          (void) getloadavg(avenrun, sizeof(avenrun) / sizeof(avenrun[0]));
         (*curcmd->c_fetch)();          (*curcmd->c_fetch)();
         if (curcmd->c_flags & CF_LOADAV) {          if (curcmd->c_flags & CF_LOADAV) {
                 j = 5.0*avenrun[0] + 0.5;                  extern int ucount();
                 dellave -= avenrun[0];                  char tbuf[26];
                 if (dellave >= 0.0)                  time_t now;
                         c = '<';  
                 else {                  time(&now);
                         c = '>';                  strlcpy(tbuf, ctime(&now), sizeof tbuf);
                         dellave = -dellave;  
                 }                  putint(ucount(), 0, 2, 3);
                 if (dellave < 0.05)                  putfloat(avenrun[0], 0, 2 + 17, 6, 2, 0);
                         c = '|';                  putfloat(avenrun[1], 0, 2 + 23, 6, 2, 0);
                 dellave = avenrun[0];                  putfloat(avenrun[2], 0, 2 + 29, 6, 2, 0);
                 wmove(wload, 0, 0);                  mvaddstr(0, 2 + 53, tbuf);
                 wclrtoeol(wload);  
                 for (i = (j > 50) ? 50 : j; i > 0; i--)  
                         waddch(wload, c);  
                 if (j > 50)  
                         wprintw(wload, " %4.1f", avenrun[0]);  
         }          }
         (*curcmd->c_refresh)();          (*curcmd->c_refresh)();
         if (curcmd->c_flags & CF_LOADAV)          if (curcmd->c_flags & CF_LOADAV)
Line 352 
Line 348 
         refresh();          refresh();
         endwin();          endwin();
         exit(1);          exit(1);
   }
   
   /* calculate number of users on the system */
   int
   ucount(void)
   {
           int nusers = 0;
           struct  utmp utmp;
   
           if (ut < 0)
                   return (0);
           lseek(ut, (off_t)0, SEEK_SET);
           while (read(ut, &utmp, sizeof(utmp)))
                   if (utmp.ut_name[0] != '\0')
                           nusers++;
   
           return (nusers);
 }  }

Legend:
Removed from v.1.34  
changed lines
  Added in v.1.35