mirror of
https://github.com/munin-monitoring/contrib.git
synced 2025-07-22 14:16:00 +00:00
multicpu1sec-c: handle fork
This commit is contained in:
parent
b0e8dcea39
commit
16b017fcd7
1 changed files with 16 additions and 0 deletions
|
@ -1,6 +1,7 @@
|
|||
/*
|
||||
* multicpu1sec C plugin
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
@ -83,6 +84,21 @@ time_t wait_until_next_second() {
|
|||
|
||||
int acquire() {
|
||||
|
||||
/* fork ourselves if not asked otherwise */
|
||||
char* no_fork = getenv("no_fork");
|
||||
if (! no_fork || strcmp("1", no_fork)) {
|
||||
if (fork()) return;
|
||||
// we are the child, complete the daemonization
|
||||
|
||||
/* Close standard IO */
|
||||
fclose(stdin);
|
||||
fclose(stdout);
|
||||
fclose(stderr);
|
||||
|
||||
/* create new session and process group */
|
||||
setsid();
|
||||
}
|
||||
|
||||
/* write the pid */
|
||||
FILE* pid_file = fopen(pid_filename, "w");
|
||||
fprintf(pid_file, "%d\n", getpid());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue