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.13 by ats, Mon Nov 10 23:35:43 2003 UTC vs.
Revision 1.23 by ats, Sun Apr 4 21:59:16 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 346 | 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 358 | 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 430 | 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. */
467   void print_stat_value(const stat *s) {
468          void *v = s->stat;
469 +        long l;
470  
471          switch (s->type) {
472          case LONG_LONG:
# Line 443 | Line 474 | void print_stat_value(const stat *s) {
474                  break;
475          case TIME_T:
476                  /* FIXME option for formatted time? */
477 <                printf("%ld", *(time_t *)v);
477 >                l = *(time_t *)v;
478 >                printf("%ld", l);
479                  break;
480          case FLOAT:
481                  printf("%f", *(float *)v);
# Line 458 | Line 490 | void print_stat_value(const stat *s) {
490          case INT:
491                  printf("%d", *(int *)v);
492                  break;
493 +        case BOOL:
494 +                printf("%s", *(int *)v ? "true" : "false");
495 +                break;
496 +        case DUPLEX:
497 +                switch (*(statgrab_duplex *) v) {
498 +                case FULL_DUPLEX:
499 +                        printf("full");
500 +                        break;
501 +                case HALF_DUPLEX:
502 +                        printf("half");
503 +                        break;
504 +                default:
505 +                        printf("unknown");
506 +                        break;
507 +                }
508 +                break;
509          }
510   }
511  
# Line 500 | Line 548 | void print_stats(int argc, char **argv) {
548                          else
549                                  compare = stats_compare;
550  
551 <                        s = (const stat *)bsearch(&key, stats, num_stats,
552 <                                                  sizeof *stats, compare);
551 >                        if (stats == NULL) {
552 >                                s = NULL;
553 >                        } else {
554 >                                s = (const stat *)bsearch(&key, stats,
555 >                                                          num_stats,
556 >                                                          sizeof *stats,
557 >                                                          compare);
558 >                        }
559 >
560                          if (s == NULL) {
561                                  printf("Unknown stat %s\n", name);
562                                  continue;
# Line 608 | Line 663 | int main(int argc, char **argv) {
663          /* We don't care if statgrab_init fails, because we can just display
664             the statistics that can be read as non-root. */
665          statgrab_init();
666 < #ifdef ALLBSD
667 <        if (setegid(getgid()) != 0)
613 <                die("Failed to lose effective group");
614 < #endif
666 >        if (statgrab_drop_privileges() != 0)
667 >                die("Failed to drop setuid/setgid privileges");
668  
669          switch (repeat_mode) {
670          case REPEAT_NONE:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines