/[machmon]/machmon/bsd/source/sys.c
ViewVC logotype

Diff of /machmon/bsd/source/sys.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by pbastos, Tue Jul 2 21:52:23 2002 UTC revision 1.2 by pbastos, Mon Jul 8 01:26:09 2002 UTC
# Line 33  Line 33 
33  #ifdef OPENBSD  #ifdef OPENBSD
34    
35  #include <sys/utsname.h>  #include <sys/utsname.h>
36    #include <sys/param.h>
37    #include <sys/sysctl.h>
38    
39  #include <time.h>  #include <time.h>
40  #include <tzfile.h>  #include <tzfile.h>
# Line 58  Line 60 
60  #include <limits.h>  #include <limits.h>
61  #include <unistd.h>  #include <unistd.h>
62  #include <string.h>  #include <string.h>
63  #include <stdlib.h>   #include <stdlib.h>
64  #include <stdio.h>  #include <stdio.h>
65    
66  #include "lncurses.h"  #include "lncurses.h"
# Line 77  d_opsys(void) Line 79  d_opsys(void)
79  {  {
80          struct utsname uts;          struct utsname uts;
81    
82          output("~WSystem: ");          if (uname(&uts) == 0)
83                    {
84          if (uname(&uts) == 0) {                  output("~WSystem: ~w%s %s (%s)\n", uts.sysname, uts.release,
                 output("~w%s %s (%s)\n", uts.sysname, uts.release,  
85                      uts.machine);                      uts.machine);
86                  return (1);                  return (1);
87          } else {          } else {
88                  output("~RUnknown System");                  output("~WSystem: ~RUnknown System\n");
89                  return (0);                  return (0);
90          }          }
91  }  }
# Line 94  d_load(void) Line 95  d_load(void)
95  {  {
96          double load[3];          double load[3];
97    
         output("~WLoad: ");  
   
98          if (getloadavg(load, 3) != 3) {          if (getloadavg(load, 3) != 3) {
99                  output("~RCouldn't find out.");                  output("~WLoad: ~RCouldn't find out.");
100                  return (1);                  return (1);
101          }          }
102    
103          output("~w%.2f, %.2f, %.2f (avg. %.2f)\n", load[0], load[1], load[2],          output("~WLoad: ~w%.2f, %.2f, %.2f (avg. %.2f)\n", load[0], load[1],
104              (load[0] + load[1] + load[2]) / 3);              load[2], (load[0] + load[1] + load[2]) / 3);
105          load_ks(load, 3);          load_ks(load, 3);
106    
107          return (1);          return (1);
108  }  }
109    
110  int  void
111  d_htnm(void)  d_htnm(void)
112  {  {
113          char host[16], domain[16];          char host[16], domain[16];
114    
115          wmove(window[0], 0, 3);          twin = window[MAIN_WINDOW];
116            (void) wmove(twin, 0, 3);
117            
118          if (gethostname(host, sizeof host) == -1)          if (gethostname(host, sizeof host) == -1)
119                  return (-1);                  return;
120          if (getdomainname(domain, sizeof domain) == -1)          if (getdomainname(domain, sizeof domain) == -1)
121                  return (-1);                  return;
   
         if (host[0] != 0x0 || domain[0] != 0x0) {  
                 (void) wattrset(window[0], COLOR_PAIR(CYAN)|A_BOLD);  
                 (void) wprintw(window[0], "<");  
                 (void) mvwprintw(window[0], 0, 4 + strlen(host) +  
                     strlen(domain) + 1, ">");  
                 (void) wattrset(window[0], COLOR_PAIR(WHITE)|A_BOLD);  
                 (void) mvwprintw(window[0], 0, 4, "%s.%s", host, domain);  
                 (void) wattrset(window[0], COLOR_PAIR(WHITE));  
122    
123                  return (1);          if (host[0] != 0x0 && domain[0] != 0x0)
124          }                  output("~C<~W%s.%s~C>", host, domain);
125    
126          return (0);          twin = window[REAL_WINDOW];
127            return ;
128  }  }
129    
130  int  int
# Line 153  d_users(void) Line 145  d_users(void)
145    
146          while (fread((char *) &utmp_str, sizeof(utmp_str), 1, utmp_file) == 1) {          while (fread((char *) &utmp_str, sizeof(utmp_str), 1, utmp_file) == 1) {
147                  if (*utmp_str.ut_name && *utmp_str.ut_line)  {                  if (*utmp_str.ut_name && *utmp_str.ut_line)  {
148                          output("~w\n%s\ton %s", utmp_str.ut_name,                          output("~w\n%s\ton %-6s", utmp_str.ut_name,
149                              utmp_str.ut_line);                              utmp_str.ut_line);
150    
151                          if (!*utmp_str.ut_host)                          if (!*utmp_str.ut_host)
152                                  output(" from (local) ");                                  output("%-16s", " (local) ");
153                          else                          else
154                                  output(" from ~G%s~w ", utmp_str.ut_host);                                  output(" from ~G%-16s~w ", utmp_str.ut_host);
155    
156                          tm = *localtime(&utmp_str.ut_time);                          tm = *localtime(&utmp_str.ut_time);
157                          (void) strftime(buf, sizeof buf, "%H:%M, %d/%m", &tm);                          (void) strftime(buf, sizeof buf, "%H:%M, %d/%m", &tm);
# Line 168  d_users(void) Line 160  d_users(void)
160                          tmp = (diff / SECSPERDAY);                          tmp = (diff / SECSPERDAY);
161    
162                          if (tmp) {                          if (tmp) {
163                                  output("%d day%s", tmp, plural((int)tmp));                                  output("%-4d day%s", tmp, plural((int)tmp));
164                                  f++;                                  f++;
165                          } else {                          } else {
166                                  f = 0;                                  f = 0;
# Line 178  d_users(void) Line 170  d_users(void)
170                          tmp = (diff / SECSPERHOUR);                          tmp = (diff / SECSPERHOUR);
171    
172                          if (tmp) {                          if (tmp) {
173                                  output("%s%d hour%s", and(f), tmp,                                  output("%s%-2d hour%s", and(f), tmp,
174                                  plural((int)tmp));                                  plural((int)tmp));
175                                  f++;                                  f++;
176                          } else {                          } else {
# Line 189  d_users(void) Line 181  d_users(void)
181                          tmp = (diff / SECSPERMIN);                          tmp = (diff / SECSPERMIN);
182    
183                          if (tmp) {                          if (tmp) {
184                                  output("%s%d minute%s", and(f), tmp,                                  output("%s%-2d minute%s", and(f), tmp,
185                                  plural((int)tmp));                                  plural((int)tmp));
186                                  f++;                                  f++;
187                          } else {                          } else {
# Line 201  d_users(void) Line 193  d_users(void)
193                  }                  }
194          }          }
195    
196          output("\n");          output("\n~W%d~w user%s logged on.\n", nusers, plural(nusers));
         output("~W%d~w users logged on.\n", nusers);  
197          (void) fclose(utmp_file);          (void) fclose(utmp_file);
198    
199          return (1);          return (1);

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26