--- projects/libstatgrab/examples/process_stats.c 2003/08/24 20:24:09 1.2 +++ projects/libstatgrab/examples/process_stats.c 2004/01/16 15:54:52 1.6 @@ -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 @@ -24,22 +24,31 @@ #include int main(int argc, char **argv){ - + extern char *optarg; - extern int optind; - int c; + extern int optind; + int c; int delay = 1; process_stat_t *process_stat; - while ((c = getopt(argc, argv, "d:")) != EOF){ - switch (c){ - case 'd': - delay = atoi(optarg); - break; + while ((c = getopt(argc, argv, "d:")) != -1){ + switch (c){ + case 'd': + delay = atoi(optarg); + break; } } + /* Initialise statgrab */ + statgrab_init(); + + /* Drop setuid/setgid privileges. */ + if (statgrab_drop_privileges() != 0) { + perror("Error. Failed to drop privileges"); + return 1; + } + while( (process_stat = get_process_stats()) != NULL){ printf("Running:%3d \t", process_stat->running); printf("Sleeping:%5d \t",process_stat->sleeping); @@ -51,6 +60,3 @@ int main(int argc, char **argv){ exit(0); } - - -