~ubuntu-branches/ubuntu/raring/maradns/raring

« back to all changes in this revision

Viewing changes to debian/patches/duende_pid.patch

  • Committer: Bazaar Package Importer
  • Author(s): Nicholas Bamber
  • Date: 2011-07-18 12:57:54 UTC
  • mfrom: (10.1.9 sid)
  • Revision ID: james.westby@ubuntu.com-20110718125754-7x4bp0qvs8q60s4n
Tags: 1.4.06-3
* Made duende more generic and Debian compatible
  - Added patch to use argp to parse arguments
  - Added support for --pid, --uid, --chroot, --ident, --restart_on,
    and --gid arguments
  - Put log helper process in chroot
  - Write pid of log helper process to syslog
  - Consolidated waitpid calls so to avoid race condition allowing zombies
  - Adjusted section and priority, cf. #632337
  - Added example to show how to use duende generically
  - Added patch to man page documenting changes to duende
* Rewrote maradns init script to use new duende features
  - Init script now relatively standard apart from use of duende and 
    support for multiple servers
  - Reload action in maradns script now sends signal to duende which
    restarts maradns process (Closes: #484466)
  - Added Recommends clause for maradns-zoneserver
* Added comment about #621833 in postrm script and ensured complete removal
  of /etc/maradns directory
* Added maradns-zoneserver package (Closes: #582069)
  - Note that the reload action is not supported for zoneserver
* Updated python support
* Updated TODO.Debian

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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.
 
4
Author: Yarin
 
5
Origin: http://maradns.org
 
6
Last-Updated: 2011-06-13
 
7
Reviewed-by: Nicholas Bamber <nicholas@periapt.co.uk>
 
8
--- a/tools/duende.c
 
9
+++ b/tools/duende.c
 
10
@@ -146,10 +146,19 @@
 
11
     int exit_status;
 
12
     pid_t pid, log_pid;
 
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");
 
18
         exit(1);
 
19
         }
 
20
+    if(!strncasecmp(argv[1],"--pid=",6)) {
 
21
+        if(argv[2] == NULL) {
 
22
+            printf(
 
23
+               "Usage: duende (--pid=/path/to/file) [program] [arguments]\n");
 
24
+            exit(1);
 
25
+            }
 
26
+        exec_argv_offset = 2;
 
27
+        }
 
28
 
 
29
     /* Let children know that duende is running */
 
30
     if(setenv("DUENDE_IS_RUNNING","1",0) != 0) {
 
31
@@ -164,6 +173,18 @@
 
32
     /* The child becomes a full-fledged daemon */
 
33
     setpgid(0,0); /* No longer visible in 'ps' without the 'auxw' argument */
 
34
 
 
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");
 
38
+        if(!fp_pid) {
 
39
+            syslog(LOG_ALERT,"Fatal writing, to PID file, error\n");
 
40
+            exit(1);
 
41
+            }
 
42
+        unsigned int local_pid = getpid();
 
43
+        fprintf(fp_pid,"%u",local_pid);
 
44
+        fclose(fp_pid);
 
45
+        }
 
46
+
 
47
     /* Sysadmins expect HUP to reload, so we set that up */
 
48
     signal(SIGHUP,handle_hup);
 
49
     signal(SIGTERM,handle_term);
 
50
@@ -193,10 +214,10 @@
 
51
                 syslog(LOG_ALERT,"Fatal dup2 error 2");
 
52
                 exit(5);
 
53
                 }
 
54
-            argv[0] = argv[1];
 
55
-            execvp(argv[1],argv + 1);
 
56
+            argv[0] = argv[exec_argv_offset];
 
57
+            execvp(argv[exec_argv_offset],argv + exec_argv_offset);
 
58
             /* OK, not found */
 
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");
 
62
             exit(1);
 
63
             }
 
64
@@ -206,7 +227,7 @@
 
65
         log_pid = fork();
 
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");
 
71
             exit(1);
 
72
             }