--- projects/libstatgrab/src/statgrab/statgrab.c 2003/08/31 13:23:19 1.9 +++ projects/libstatgrab/src/statgrab/statgrab.c 2004/01/16 15:54:56 1.16 @@ -1,7 +1,7 @@ /* * i-scream central monitoring system * http://www.i-scream.org - * Copyright (C) 2000-2003 i-scream + * Copyright (C) 2000-2004 i-scream * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -268,13 +268,24 @@ void populate_fs() { if (disk != NULL) { for (i = 0; i < n; i++) { /* FIXME it'd be nicer if libstatgrab did this */ - const char *name = disk[i].device_name, - *p = strrchr(name, '/'); - if (p != NULL) - name = p + 1; - if (*name == '\0') - name = "root"; - + char *buf, *name, *p; + const char *device = disk[i].device_name; + + if (strcmp(device, "/") == 0) + device = "root"; + + buf = strdup(device); + if (buf == NULL) + die("out of memory"); + + name = buf; + if (strlen(name) == 2 && name[1] == ':') + name[1] = '\0'; + if (strncmp(name, "/dev/", 5) == 0) + name += 5; + while ((p = strchr(name, '/')) != NULL) + *p = '_'; + add_stat(STRING, &disk[i].device_name, "fs", name, "device_name", NULL); add_stat(STRING, &disk[i].fs_type, @@ -293,6 +304,8 @@ void populate_fs() { "fs", name, "used_inodes", NULL); add_stat(LONG_LONG, &disk[i].free_inodes, "fs", name, "free_inodes", NULL); + + free(buf); } } } @@ -358,7 +371,7 @@ void populate_page() { if (page != NULL) { add_stat(LONG_LONG, &page->pages_pagein, "page", "in", NULL); add_stat(LONG_LONG, &page->pages_pageout, "page", "out", NULL); - add_stat(LONG_LONG, &page->systime, "page", "systime", NULL); + add_stat(TIME_T, &page->systime, "page", "systime", NULL); } } @@ -591,6 +604,12 @@ int main(int argc, char **argv) { use_diffs = 1; select_interesting(argc - optind, &argv[optind]); + + /* We don't care if statgrab_init fails, because we can just display + the statistics that can be read as non-root. */ + statgrab_init(); + if (statgrab_drop_privileges() != 0) + die("Failed to drop setuid/setgid privileges"); switch (repeat_mode) { case REPEAT_NONE: