ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/libstatgrab/src/statgrab/statgrab.c
(Generate patch)

Comparing projects/libstatgrab/src/statgrab/statgrab.c (file contents):
Revision 1.12 by ats, Mon Oct 20 22:18:21 2003 UTC vs.
Revision 1.22 by ats, Sat Mar 6 22:34:36 2004 UTC

# Line 1 | Line 1
1   /*
2   * i-scream central monitoring system
3   * http://www.i-scream.org
4 < * Copyright (C) 2000-2003 i-scream
4 > * Copyright (C) 2000-2004 i-scream
5   *
6   * This program is free software; you can redistribute it and/or
7   * modify it under the terms of the GNU General Public License
# Line 16 | Line 16
16   * You should have received a copy of the GNU General Public License
17   * along with this program; if not, write to the Free Software
18   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19 + *
20 + * $Id$
21   */
22  
23   #ifdef HAVE_CONFIG_H
# Line 35 | Line 37 | typedef enum {
37          FLOAT,
38          DOUBLE,
39          STRING,
40 <        INT
40 >        INT,
41 >        BOOL,
42 >        DUPLEX
43   } stat_type;
44  
45   typedef enum {
# Line 279 | Line 283 | void populate_fs() {
283                                  die("out of memory");
284  
285                          name = buf;
286 +                        if (strlen(name) == 2 && name[1] == ':')
287 +                                name[1] = '\0';
288                          if (strncmp(name, "/dev/", 5) == 0)
289                                  name += 5;
290                          while ((p = strchr(name, '/')) != NULL)
# Line 344 | Line 350 | void populate_proc() {
350   void populate_net() {
351          int n, i;
352          network_stat_t *net;
353 +        network_iface_stat_t *iface;
354  
355          net = use_diffs ? get_network_stats_diff(&n) : get_network_stats(&n);
356          if (net != NULL) {
# Line 356 | Line 363 | void populate_net() {
363                                   "net", name, "tx", NULL);
364                          add_stat(LONG_LONG, &net[i].rx,
365                                   "net", name, "rx", NULL);
366 +                        add_stat(LONG_LONG, &net[i].ipackets,
367 +                                 "net", name, "ipackets", NULL);
368 +                        add_stat(LONG_LONG, &net[i].opackets,
369 +                                 "net", name, "opackets", NULL);
370 +                        add_stat(LONG_LONG, &net[i].ierrors,
371 +                                 "net", name, "ierrors", NULL);
372 +                        add_stat(LONG_LONG, &net[i].oerrors,
373 +                                 "net", name, "oerrors", NULL);
374 +                        add_stat(LONG_LONG, &net[i].collisions,
375 +                                 "net", name, "collisions", NULL);
376                          add_stat(TIME_T, &net[i].systime,
377                                   "net", name, "systime", NULL);
378                  }
379          }
380 +
381 +        iface = get_network_iface_stats(&n);
382 +        if (iface != NULL) {
383 +                for (i = 0; i < n; i++) {
384 +                        const char *name = iface[i].interface_name;
385 +
386 +                        add_stat(INT, &iface[i].speed,
387 +                                 "net", name, "speed", NULL);
388 +                        add_stat(BOOL, &iface[i].up,
389 +                                 "net", name, "up", NULL);
390 +                        add_stat(DUPLEX, &iface[i].dup,
391 +                                 "net", name, "duplex", NULL);
392 +                }
393 +        }
394   }
395  
396   void populate_page() {
# Line 428 | Line 459 | void get_stats() {
459                          t->populate();
460          }
461  
462 <        qsort(stats, num_stats, sizeof *stats, stats_compare);
462 >        if (stats != NULL)
463 >                qsort(stats, num_stats, sizeof *stats, stats_compare);
464   }
465  
466   /* Print the value of a stat. */
# Line 456 | Line 488 | void print_stat_value(const stat *s) {
488          case INT:
489                  printf("%d", *(int *)v);
490                  break;
491 +        case BOOL:
492 +                printf("%s", *(int *)v ? "true" : "false");
493 +                break;
494 +        case DUPLEX:
495 +                switch (*(statgrab_duplex *) v) {
496 +                case FULL_DUPLEX:
497 +                        printf("full");
498 +                        break;
499 +                case HALF_DUPLEX:
500 +                        printf("half");
501 +                        break;
502 +                default:
503 +                        printf("unknown");
504 +                        break;
505 +                }
506 +                break;
507          }
508   }
509  
# Line 498 | Line 546 | void print_stats(int argc, char **argv) {
546                          else
547                                  compare = stats_compare;
548  
549 <                        s = (const stat *)bsearch(&key, stats, num_stats,
550 <                                                  sizeof *stats, compare);
549 >                        if (stats == NULL) {
550 >                                s = NULL;
551 >                        } else {
552 >                                s = (const stat *)bsearch(&key, stats,
553 >                                                          num_stats,
554 >                                                          sizeof *stats,
555 >                                                          compare);
556 >                        }
557 >
558                          if (s == NULL) {
559                                  printf("Unknown stat %s\n", name);
560                                  continue;
# Line 606 | Line 661 | int main(int argc, char **argv) {
661          /* We don't care if statgrab_init fails, because we can just display
662             the statistics that can be read as non-root. */
663          statgrab_init();
664 < #ifdef ALLBSD
665 <        if (setegid(getgid()) != 0)
611 <                die("Failed to lose effective group");
612 < #endif
664 >        if (statgrab_drop_privileges() != 0)
665 >                die("Failed to drop setuid/setgid privileges");
666  
667          switch (repeat_mode) {
668          case REPEAT_NONE:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines