mirror of
https://github.com/munin-monitoring/contrib.git
synced 2018-11-08 00:59:34 +01:00
p/if1sec-c: handle absence of state file
This commit is contained in:
parent
c81c20ab3b
commit
cc0b094938
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user