1
Subject: --pid <file> argument to create pid file for child process
2
This patch is being deployed by upstream and we want to keep
3
our changes compatible with upstream.
5
Origin: http://maradns.org
6
Last-Updated: 2011-06-13
7
Reviewed-by: Nicholas Bamber <nicholas@periapt.co.uk>
13
int stream1[2]; /* Used for piping */
14
+ int exec_argv_offset = 1; /* Also used to determine PID writing */
15
if(argv[0] == NULL || argv[1] == NULL) {
16
- printf("Usage: duende [program] [arguments]\n");
17
+ printf("Usage: duende (--pid=/path/to/file) [program] [arguments]\n");
20
+ if(!strncasecmp(argv[1],"--pid=",6)) {
21
+ if(argv[2] == NULL) {
23
+ "Usage: duende (--pid=/path/to/file) [program] [arguments]\n");
26
+ exec_argv_offset = 2;
29
/* Let children know that duende is running */
30
if(setenv("DUENDE_IS_RUNNING","1",0) != 0) {
32
/* The child becomes a full-fledged daemon */
33
setpgid(0,0); /* No longer visible in 'ps' without the 'auxw' argument */
35
+ /* Write our PID to a file if the user so desires us to */
36
+ if(exec_argv_offset == 2) {
37
+ FILE *fp_pid = fopen(argv[1] + 6,"w");
39
+ syslog(LOG_ALERT,"Fatal writing, to PID file, error\n");
42
+ unsigned int local_pid = getpid();
43
+ fprintf(fp_pid,"%u",local_pid);
47
/* Sysadmins expect HUP to reload, so we set that up */
48
signal(SIGHUP,handle_hup);
49
signal(SIGTERM,handle_term);
51
syslog(LOG_ALERT,"Fatal dup2 error 2");
55
- execvp(argv[1],argv + 1);
56
+ argv[0] = argv[exec_argv_offset];
57
+ execvp(argv[exec_argv_offset],argv + exec_argv_offset);
59
- printf("duende: %s: Command can't run, terminating\n",argv[1]);
60
+ printf("duende: %s: Command can't run, terminating\n",argv[exec_argv_offset]);
61
syslog(LOG_ALERT,"Command can't run, terminating\n");
66
if(log_pid == 0) { /* Child to syslog all of MaraDNS' output */
67
argv[0] = "duende-log-helper";
68
- log_helper(argv[1],stream1[0]);
69
+ log_helper(argv[exec_argv_offset],stream1[0]);
70
syslog(LOG_ALERT,"log_helper finished, terminating\n");