From 37b47bd343100174ab09b0460502c01d96d73fd9 Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Thu, 8 May 2014 01:15:36 +0200 Subject: [PATCH] Let Probe compile again --- data/Probe.interface | 1 - src/damon.c | 61 +++++++++-------- src/probe.c | 156 ++++++++++++++++++++++--------------------- 3 files changed, 114 insertions(+), 104 deletions(-) diff --git a/data/Probe.interface b/data/Probe.interface index 7f5d7de..e678bd9 100644 --- a/data/Probe.interface +++ b/data/Probe.interface @@ -1,6 +1,5 @@ #$Id$ service=Probe -port=4243 [call::uptime] ret=UINT32 diff --git a/src/damon.c b/src/damon.c index e037dd7..a948879 100644 --- a/src/damon.c +++ b/src/damon.c @@ -1,5 +1,5 @@ /* $Id$ */ -/* Copyright (c) 2011 Pierre Pronchery */ +/* Copyright (c) 2005-2014 Pierre Pronchery */ /* This file is part of DeforaOS Network Probe */ /* This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -30,10 +30,16 @@ #include "../config.h" #ifndef PREFIX -# define PREFIX "/usr/local" +# define PREFIX "/usr/local" #endif -#ifndef ETCDIR -# define ETCDIR PREFIX "/etc" +#ifndef SYSCONFDIR +# define SYSCONFDIR PREFIX "/etc" +#endif +#ifndef PROGNAME +# define PROGNAME "DaMon" +#endif +#ifndef RRDTOOL +# define RRDTOOL "rrdtool" #endif @@ -63,7 +69,6 @@ struct _DaMon /* constants */ #define DAMON_DEFAULT_REFRESH 10 -#define DAMON_PROGNAME "DaMon" #define DAMON_SEP '/' @@ -84,7 +89,7 @@ static int _damon(char const * config) if(_damon_init(&damon, config) != 0) return 1; if(event_loop(damon.event) != 0) - error_print(DAMON_PROGNAME); + error_print(PROGNAME); _damon_destroy(&damon); return 1; } @@ -101,7 +106,7 @@ static int _damon_init(DaMon * damon, char const * filename) if(_init_config(damon, filename) != 0) return 1; if((damon->event = event_new()) == NULL) - return error_print(DAMON_PROGNAME); + return error_print(PROGNAME); _damon_refresh(damon); tv.tv_sec = damon->refresh; tv.tv_usec = 0; @@ -127,10 +132,10 @@ static int _init_config(DaMon * damon, char const * filename) damon->hosts = NULL; damon->hosts_cnt = 0; if(filename == NULL) - filename = ETCDIR "/" DAMON_PROGNAME ".conf"; + filename = SYSCONFDIR "/" PROGNAME ".conf"; if(config_load(config, filename) != 0) { - error_print(DAMON_PROGNAME); + error_print(PROGNAME); config_delete(config); return 1; } @@ -324,9 +329,9 @@ static AppClient * _refresh_connect(Host * host, Event * event) { if(setenv("APPSERVER_Probe", host->hostname, 1) != 0) return NULL; - if((host->appclient = appclient_new_event("Probe", event)) + if((host->appclient = appclient_new_event(NULL, "Probe", NULL, event)) == NULL) - error_print(DAMON_PROGNAME); + error_print(PROGNAME); return host->appclient; } @@ -335,8 +340,8 @@ static int _refresh_uptime(AppClient * ac, Host * host, char * rrd) { int32_t ret; - if(appclient_call(ac, &ret, "uptime") != 0) - return error_print(DAMON_PROGNAME); + if(appclient_call(ac, (void **)&ret, "uptime") != 0) + return error_print(PROGNAME); sprintf(rrd, "%s%c%s", host->hostname, DAMON_SEP, "uptime.rrd"); _rrd_update(host->damon, rrd, 1, ret); return 0; @@ -347,8 +352,9 @@ static int _refresh_load(AppClient * ac, Host * host, char * rrd) int32_t res; uint32_t load[3]; - if(appclient_call(ac, &res, "load", &load[0], &load[1], &load[2]) != 0) - return error_print(DAMON_PROGNAME); + if(appclient_call(ac, (void **)&res, "load", &load[0], &load[1], + &load[2]) != 0) + return error_print(PROGNAME); if(res != 0) return 0; sprintf(rrd, "%s%c%s", host->hostname, DAMON_SEP, "load.rrd"); @@ -360,7 +366,7 @@ static int _refresh_procs(AppClient * ac, Host * host, char * rrd) { int32_t res; - if(appclient_call(ac, &res, "procs") != 0) + if(appclient_call(ac, (void **)&res, "procs") != 0) return 1; sprintf(rrd, "%s%c%s", host->hostname, DAMON_SEP, "procs.rrd"); _rrd_update(host->damon, rrd, 1, res); @@ -372,8 +378,8 @@ static int _refresh_ram(AppClient * ac, Host * host, char * rrd) int32_t res; uint32_t ram[4]; - if(appclient_call(ac, &res, "ram", &ram[0], &ram[1], &ram[2], &ram[3]) - != 0) + if(appclient_call(ac, (void **)&res, "ram", &ram[0], &ram[1], &ram[2], + &ram[3]) != 0) return 1; sprintf(rrd, "%s%c%s", host->hostname, DAMON_SEP, "ram.rrd"); _rrd_update(host->damon, rrd, 4, ram[0], ram[1], ram[2], ram[3]); @@ -385,7 +391,7 @@ static int _refresh_swap(AppClient * ac, Host * host, char * rrd) int32_t res; uint32_t swap[2]; - if(appclient_call(ac, &res, "swap", &swap[0], &swap[1]) != 0) + if(appclient_call(ac, (void **)&res, "swap", &swap[0], &swap[1]) != 0) return 1; sprintf(rrd, "%s%c%s", host->hostname, DAMON_SEP, "swap.rrd"); _rrd_update(host->damon, rrd, 2, swap[0], swap[1]); @@ -396,7 +402,7 @@ static int _refresh_users(AppClient * ac, Host * host, char * rrd) { int32_t res; - if(appclient_call(ac, &res, "users") != 0) + if(appclient_call(ac, (void **)&res, "users") != 0) return 1; sprintf(rrd, "%s%c%s", host->hostname, DAMON_SEP, "users.rrd"); _rrd_update(host->damon, rrd, 1, res); @@ -422,8 +428,9 @@ static int _ifaces_if(AppClient * ac, Host * host, char * rrd, { int32_t res[2]; - if(appclient_call(ac, &res[0], "ifrxbytes", iface) != 0 - || appclient_call(ac, &res[1], "iftxbytes", iface) != 0) + if(appclient_call(ac, (void **)&res[0], "ifrxbytes", iface) != 0 + || appclient_call(ac, (void **)&res[1], "iftxbytes", + iface) != 0) return 1; sprintf(rrd, "%s%c%s%s", host->hostname, DAMON_SEP, iface, ".rrd"); _rrd_update(host->damon, rrd, 2, res[0], res[1]); @@ -447,8 +454,8 @@ static int _vols_vol(AppClient * ac, Host * host, char * rrd, char * vol) { int32_t res[2]; - if(appclient_call(ac, &res[0], "voltotal", vol) != 0 - || appclient_call(ac, &res[1], "volfree", vol) + if(appclient_call(ac, (void **)&res[0], "voltotal", vol) != 0 + || appclient_call(ac, (void **)&res[1], "volfree", vol) != 0) return 1; sprintf(rrd, "%s%s%s", host->hostname, vol, ".rrd"); /* FIXME */ @@ -459,7 +466,7 @@ static int _vols_vol(AppClient * ac, Host * host, char * rrd, char * vol) static int _exec(char * argv[]); static int _rrd_update(DaMon * damon, char const * filename, int args_cnt, ...) { - char * argv[] = { "rrdtool", "update", NULL, NULL, NULL }; + char * argv[] = { RRDTOOL, "update", NULL, NULL, NULL }; struct timeval tv; int pos; int i; @@ -514,7 +521,7 @@ static int _exec(char * argv[]) /* private */ static int _damon_perror(char const * message, int ret) { - return error_set_print(DAMON_PROGNAME, ret, "%s%s%s\n", + return error_set_print(PROGNAME, ret, "%s%s%s\n", message ? message : "", message ? ": " : "", strerror(errno)); } @@ -523,7 +530,7 @@ static int _damon_perror(char const * message, int ret) /* usage */ static int _usage(void) { - fputs("Usage: " DAMON_PROGNAME " [-f filename]\n" + fputs("Usage: " PROGNAME " [-f filename]\n" " -f\tConfiguration file to load\n", stderr); return 1; } diff --git a/src/probe.c b/src/probe.c index 704735c..0889c30 100644 --- a/src/probe.c +++ b/src/probe.c @@ -1,5 +1,5 @@ /* $Id$ */ -/* Copyright (c) 2011 Pierre Pronchery */ +/* Copyright (c) 2005-2014 Pierre Pronchery */ /* This file is part of DeforaOS Network Probe */ /* This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -29,6 +29,10 @@ #include "../data/Probe.h" #include "../config.h" +#ifndef PROGNAME +# define PROGNAME PACKAGE +#endif + #if defined(__linux__) # define _sysinfo_linux _sysinfo @@ -580,7 +584,7 @@ static int _volinfo_generic(struct volinfo ** dev) /* Probe */ /* private */ /* types */ -typedef struct _Probe +typedef struct _App { struct sysinfo sysinfo; unsigned int users; @@ -591,10 +595,6 @@ typedef struct _Probe } Probe; -/* variables */ -Probe probe; - - /* prototypes */ static int _probe_error(int ret); static int _probe_perror(char const * message, int ret); @@ -605,6 +605,7 @@ static int _probe_timeout(Probe * probe); /* probe */ static int _probe(AppServerOptions options) { + Probe probe; AppServer * appserver; Event * event; struct timeval tv; @@ -622,8 +623,8 @@ static int _probe(AppServerOptions options) free(probe.volinfo); return _probe_error(1); } - if((appserver = appserver_new_event("Probe", options, event)) - == NULL) + if((appserver = appserver_new_event(&probe, options, "Probe", NULL, + event)) == NULL) { free(probe.ifinfo); free(probe.volinfo); @@ -648,7 +649,7 @@ static int _probe(AppServerOptions options) /* probe_error */ static int _probe_error(int ret) { - error_print(PACKAGE); + error_print(PROGNAME); return ret; } @@ -656,7 +657,7 @@ static int _probe_error(int ret) /* probe_perror */ static int _probe_perror(char const * message, int ret) { - error_set_print(PACKAGE, ret, "%s%s%s", message ? message : "", + error_set_print(PROGNAME, ret, "%s%s%s", message ? message : "", message ? ": " : "", strerror(errno)); return ret; } @@ -689,156 +690,162 @@ static int _probe_timeout(Probe * probe) /* functions */ /* AppInterface */ /* Probe_uptime */ -uint32_t Probe_uptime(void) +uint32_t Probe_uptime(Probe * probe, AppServerClient * asc) { #if defined(DEBUG) - printf("%s%ld%s", "Uptime: ", probe.sysinfo.uptime, "\n"); + printf("%s%ld%s", "Uptime: ", probe->sysinfo.uptime, "\n"); #endif - return probe.sysinfo.uptime; + return probe->sysinfo.uptime; } /* Probe_load */ -int32_t Probe_load(uint32_t * load1, uint32_t * load5, uint32_t * load15) +int32_t Probe_load(Probe * probe, AppServerClient * asc, uint32_t * load1, + uint32_t * load5, uint32_t * load15) { #if defined(DEBUG) - printf("%s%lu%s%lu%s%lu%s", "Load 1: ", probe.sysinfo.loads[0], - ", Load 5: ", probe.sysinfo.loads[1], - ", Load 15: ", probe.sysinfo.loads[2], "\n"); + printf("%s%lu%s%lu%s%lu%s", "Load 1: ", probe->sysinfo.loads[0], + ", Load 5: ", probe->sysinfo.loads[1], + ", Load 15: ", probe->sysinfo.loads[2], "\n"); #endif - *load1 = probe.sysinfo.loads[0]; - *load5 = probe.sysinfo.loads[1]; - *load15 = probe.sysinfo.loads[2]; + *load1 = probe->sysinfo.loads[0]; + *load5 = probe->sysinfo.loads[1]; + *load15 = probe->sysinfo.loads[2]; return 0; } /* Probe_ram */ -int32_t Probe_ram(uint32_t * total, uint32_t * free, uint32_t * shared, - uint32_t * buffer) +int32_t Probe_ram(Probe * probe, AppServerClient * asc, uint32_t * total, + uint32_t * free, uint32_t * shared, uint32_t * buffer) { #if defined(DEBUG) printf("%s%lu%s%lu%s%lu%s%lu%s", - "Total RAM: ", probe.sysinfo.totalram, - ", Free RAM: ", probe.sysinfo.freeram, - ", Shared RAM: ", probe.sysinfo.sharedram, - ", Buffered RAM: ", probe.sysinfo.bufferram, "\n"); + "Total RAM: ", probe->sysinfo.totalram, + ", Free RAM: ", probe->sysinfo.freeram, + ", Shared RAM: ", probe->sysinfo.sharedram, + ", Buffered RAM: ", probe->sysinfo.bufferram, "\n"); #endif - *total = probe.sysinfo.totalram; - *free = probe.sysinfo.freeram; - *shared = probe.sysinfo.sharedram; - *buffer = probe.sysinfo.bufferram; + *total = probe->sysinfo.totalram; + *free = probe->sysinfo.freeram; + *shared = probe->sysinfo.sharedram; + *buffer = probe->sysinfo.bufferram; return 0; } /* Probe_swap */ -int32_t Probe_swap(uint32_t * total, uint32_t * free) +int32_t Probe_swap(Probe * probe, AppServerClient * asc, uint32_t * total, + uint32_t * free) { #if defined(DEBUG) - printf("%s%lu%s", "Total swap: ", probe.sysinfo.totalswap, "\n"); - printf("%s%lu%s", "Free swap: ", probe.sysinfo.freeswap, "\n"); + printf("%s%lu%s", "Total swap: ", probe->sysinfo.totalswap, "\n"); + printf("%s%lu%s", "Free swap: ", probe->sysinfo.freeswap, "\n"); #endif - *total = probe.sysinfo.totalswap; - *free = probe.sysinfo.freeswap; + *total = probe->sysinfo.totalswap; + *free = probe->sysinfo.freeswap; return 0; } /* Probe_procs */ -uint32_t Probe_procs(void) +uint32_t Probe_procs(Probe * probe, AppServerClient * asc) { #if defined(DEBUG) - printf("%s%u%s", "Procs: ", probe.sysinfo.procs, "\n"); + printf("%s%u%s", "Procs: ", probe->sysinfo.procs, "\n"); #endif - return probe.sysinfo.procs; + return probe->sysinfo.procs; } /* Probe_users */ -uint32_t Probe_users(void) +uint32_t Probe_users(Probe * probe, AppServerClient * asc) { #if defined(DEBUG) - printf("%s%u%s", "Users: ", probe.users, "\n"); + printf("%s%u%s", "Users: ", probe->users, "\n"); #endif - return probe.users; + return probe->users; } /* Probe_ifrxbytes */ -uint32_t Probe_ifrxbytes(String const * dev) +uint32_t Probe_ifrxbytes(Probe * probe, AppServerClient * asc, + String const * dev) { unsigned int i; - for(i = 0; i < probe.ifinfo_cnt - && string_compare(probe.ifinfo[i].name, dev) != 0; i++); - if(i == probe.ifinfo_cnt) + for(i = 0; i < probe->ifinfo_cnt + && string_compare(probe->ifinfo[i].name, dev) != 0; i++); + if(i == probe->ifinfo_cnt) return -1; #if defined(DEBUG) - printf("%s%s%s%u%s", "Interface ", probe.ifinfo[i].name, " RX: ", - probe.ifinfo[i].ibytes, "\n"); + printf("%s%s%s%u%s", "Interface ", probe->ifinfo[i].name, " RX: ", + probe->ifinfo[i].ibytes, "\n"); #endif - return probe.ifinfo[i].ibytes; + return probe->ifinfo[i].ibytes; } /* Probe_iftxbytes */ -uint32_t Probe_iftxbytes(String const * dev) +uint32_t Probe_iftxbytes(Probe * probe, AppServerClient * asc, + String const * dev) { unsigned int i; - for(i = 0; i < probe.ifinfo_cnt - && string_compare(probe.ifinfo[i].name, dev) != 0; i++); - if(i == probe.ifinfo_cnt) + for(i = 0; i < probe->ifinfo_cnt + && string_compare(probe->ifinfo[i].name, dev) != 0; i++); + if(i == probe->ifinfo_cnt) return -1; #if defined(DEBUG) - printf("%s%s%s%u%s", "Interface ", probe.ifinfo[i].name, " TX: ", - probe.ifinfo[i].obytes, "\n"); + printf("%s%s%s%u%s", "Interface ", probe->ifinfo[i].name, " TX: ", + probe->ifinfo[i].obytes, "\n"); #endif - return probe.ifinfo[i].obytes; + return probe->ifinfo[i].obytes; } /* Probe_voltotal */ -uint32_t Probe_voltotal(String const * volume) +uint32_t Probe_voltotal(Probe * probe, AppServerClient * asc, + String const * volume) { unsigned int i; - for(i = 0; i < probe.volinfo_cnt - && string_compare(probe.volinfo[i].name, volume) != 0; + for(i = 0; i < probe->volinfo_cnt + && string_compare(probe->volinfo[i].name, volume) != 0; i++); - if(i == probe.volinfo_cnt) + if(i == probe->volinfo_cnt) return -1; #if defined(DEBUG) - printf("%s%s%s%lu%s", "Volume ", probe.volinfo[i].name, " total: ", - probe.volinfo[i].total, "\n"); + printf("%s%s%s%lu%s", "Volume ", probe->volinfo[i].name, " total: ", + probe->volinfo[i].total, "\n"); #endif - return probe.volinfo[i].total * (probe.volinfo[i].block_size / 1024); + return probe->volinfo[i].total * (probe->volinfo[i].block_size / 1024); } /* Probe_volfree */ -uint32_t Probe_volfree(String const * volume) +uint32_t Probe_volfree(Probe * probe, AppServerClient * asc, + String const * volume) { unsigned int i; - for(i = 0; i < probe.volinfo_cnt - && string_compare(probe.volinfo[i].name, volume) != 0; + for(i = 0; i < probe->volinfo_cnt + && string_compare(probe->volinfo[i].name, volume) != 0; i++); - if(i == probe.volinfo_cnt) + if(i == probe->volinfo_cnt) return -1; #if defined(DEBUG) - printf("%s%s%s%lu%s", "Volume ", probe.volinfo[i].name, " free: ", - probe.volinfo[i].free, "\n"); + printf("%s%s%s%lu%s", "Volume ", probe->volinfo[i].name, " free: ", + probe->volinfo[i].free, "\n"); #endif - return probe.volinfo[i].free * (probe.volinfo[i].block_size / 1024); + return probe->volinfo[i].free * (probe->volinfo[i].block_size / 1024); } /* usage */ static int _usage(void) { - fputs("Usage: " PACKAGE " [-L|-R]\n", stderr); + fputs("Usage: " PROGNAME " [-R]\n", stderr); return 1; } @@ -847,16 +854,13 @@ static int _usage(void) int main(int argc, char * argv[]) { int o; - AppServerOptions options = ASO_LOCAL; + AppServerOptions options = 0; - while((o = getopt(argc, argv, "LR")) != -1) + while((o = getopt(argc, argv, "R")) != -1) switch(o) { - case 'L': - options = ASO_LOCAL; - break; case 'R': - options = ASO_REMOTE; + options = ASO_REGISTER; break; default: return _usage();