mirror of
https://github.com/munin-monitoring/contrib.git
synced 2018-11-08 00:59:34 +01:00
p/*1sec-c: improve error handling
This commit is contained in:
parent
52905275b8
commit
0a40358f9e
@ -95,7 +95,11 @@ int acquire() {
|
||||
/* fork ourselves if not asked otherwise */
|
||||
char* no_fork = getenv("no_fork");
|
||||
if (! no_fork || strcmp("1", no_fork)) {
|
||||
if (fork()) return 0;
|
||||
pid_t child_pid = fork();
|
||||
if (child_pid) {
|
||||
printf("# acquire() launched as PID %d\n", child_pid);
|
||||
return 0;
|
||||
}
|
||||
// we are the child, complete the daemonization
|
||||
|
||||
/* Close standard IO */
|
||||
@ -118,7 +122,7 @@ int acquire() {
|
||||
/* open the spoolfile */
|
||||
FILE* cache_file = fopen(cache_filename, "a");
|
||||
if (!cache_file) {
|
||||
return fail("cannot create cache_file");
|
||||
return acquire();
|
||||
}
|
||||
|
||||
int cache_file_fd = fileno(cache_file);
|
||||
@ -176,7 +180,7 @@ int acquire() {
|
||||
int fetch() {
|
||||
FILE* cache_file = fopen(cache_filename, "r+");
|
||||
if (!cache_file) {
|
||||
return fail("cannot read cache_file");
|
||||
return acquire();
|
||||
}
|
||||
|
||||
/* lock */
|
||||
|
@ -120,7 +120,12 @@ int acquire() {
|
||||
/* fork ourselves if not asked otherwise */
|
||||
char* no_fork = getenv("no_fork");
|
||||
if (! no_fork || strcmp("1", no_fork)) {
|
||||
if (fork()) return 0;
|
||||
pid_t child_pid = fork();
|
||||
if (child_pid) {
|
||||
printf("# acquire() launched as PID %d\n", child_pid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// we are the child, complete the daemonization
|
||||
|
||||
/* Close standard IO */
|
||||
@ -146,7 +151,7 @@ int acquire() {
|
||||
/* 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");
|
||||
return fail("# cannot open cache_file");
|
||||
}
|
||||
|
||||
/* loop each second */
|
||||
@ -220,7 +225,7 @@ int acquire() {
|
||||
int fetch() {
|
||||
FILE* cache_file = fopen(cache_filename, "r+");
|
||||
if ( !cache_file ) {
|
||||
return fail("cannot open cache file");
|
||||
return acquire();
|
||||
}
|
||||
|
||||
/* lock */
|
||||
|
Loading…
Reference in New Issue
Block a user