diff --git a/plugins/network/if1sec-c.c b/plugins/network/if1sec-c.c index 47f7842d..b7ec5bfc 100644 --- a/plugins/network/if1sec-c.c +++ b/plugins/network/if1sec-c.c @@ -38,8 +38,8 @@ char* get_ifname_from_procstatline(char* line) { int config() { /* Get the number of if */ - int f; - if ( !(f=open(PROC_STAT, O_RDONLY)) ) { + int f = open(PROC_STAT, O_RDONLY); + if ( f == -1 ) { return fail("cannot open " PROC_STAT); } @@ -120,7 +120,7 @@ int acquire() { /* fork ourselves if not asked otherwise */ char* no_fork = getenv("no_fork"); if (! no_fork || strcmp("1", no_fork)) { - if (fork()) return; + if (fork()) return 0; // we are the child, complete the daemonization /* Close standard IO */ @@ -139,9 +139,15 @@ int acquire() { /* Reading /proc/stat */ int f = open(PROC_STAT, O_RDONLY); + if ( f == -1 ) { + return fail("cannot open " PROC_STAT); + } /* open the spoolfile */ int cache_file = open(cache_filename, O_CREAT | O_APPEND | O_WRONLY, S_IRUSR | S_IWUSR); + if ( cache_file == -1 ) { + return fail("cannot open the spoolfile"); + } /* loop each second */ while (1) { @@ -213,6 +219,9 @@ int acquire() { int fetch() { FILE* cache_file = fopen(cache_filename, "r+"); + if ( !cache_file ) { + return fail("cannot open cache file"); + } /* lock */ flock(fileno(cache_file), LOCK_EX);