mirror of
https://github.com/munin-monitoring/contrib.git
synced 2025-07-22 02:51:03 +00:00
p/*1sec-c: improve error handling
This commit is contained in:
parent
52905275b8
commit
0a40358f9e
2 changed files with 15 additions and 6 deletions
|
@ -95,7 +95,11 @@ int acquire() {
|
||||||
/* fork ourselves if not asked otherwise */
|
/* fork ourselves if not asked otherwise */
|
||||||
char* no_fork = getenv("no_fork");
|
char* no_fork = getenv("no_fork");
|
||||||
if (! no_fork || strcmp("1", 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
|
// we are the child, complete the daemonization
|
||||||
|
|
||||||
/* Close standard IO */
|
/* Close standard IO */
|
||||||
|
@ -118,7 +122,7 @@ int acquire() {
|
||||||
/* open the spoolfile */
|
/* open the spoolfile */
|
||||||
FILE* cache_file = fopen(cache_filename, "a");
|
FILE* cache_file = fopen(cache_filename, "a");
|
||||||
if (!cache_file) {
|
if (!cache_file) {
|
||||||
return fail("cannot create cache_file");
|
return acquire();
|
||||||
}
|
}
|
||||||
|
|
||||||
int cache_file_fd = fileno(cache_file);
|
int cache_file_fd = fileno(cache_file);
|
||||||
|
@ -176,7 +180,7 @@ int acquire() {
|
||||||
int fetch() {
|
int fetch() {
|
||||||
FILE* cache_file = fopen(cache_filename, "r+");
|
FILE* cache_file = fopen(cache_filename, "r+");
|
||||||
if (!cache_file) {
|
if (!cache_file) {
|
||||||
return fail("cannot read cache_file");
|
return acquire();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* lock */
|
/* lock */
|
||||||
|
|
|
@ -120,7 +120,12 @@ int acquire() {
|
||||||
/* fork ourselves if not asked otherwise */
|
/* fork ourselves if not asked otherwise */
|
||||||
char* no_fork = getenv("no_fork");
|
char* no_fork = getenv("no_fork");
|
||||||
if (! no_fork || strcmp("1", 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
|
// we are the child, complete the daemonization
|
||||||
|
|
||||||
/* Close standard IO */
|
/* Close standard IO */
|
||||||
|
@ -146,7 +151,7 @@ int acquire() {
|
||||||
/* open the spoolfile */
|
/* open the spoolfile */
|
||||||
int cache_file = open(cache_filename, O_CREAT | O_APPEND | O_WRONLY, S_IRUSR | S_IWUSR);
|
int cache_file = open(cache_filename, O_CREAT | O_APPEND | O_WRONLY, S_IRUSR | S_IWUSR);
|
||||||
if ( cache_file == -1 ) {
|
if ( cache_file == -1 ) {
|
||||||
return fail("cannot open the spoolfile");
|
return fail("# cannot open cache_file");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* loop each second */
|
/* loop each second */
|
||||||
|
@ -220,7 +225,7 @@ int acquire() {
|
||||||
int fetch() {
|
int fetch() {
|
||||||
FILE* cache_file = fopen(cache_filename, "r+");
|
FILE* cache_file = fopen(cache_filename, "r+");
|
||||||
if ( !cache_file ) {
|
if ( !cache_file ) {
|
||||||
return fail("cannot open cache file");
|
return acquire();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* lock */
|
/* lock */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue