diff options
author | Stef Walter <stef@memberwebs.com> | 2008-06-09 15:44:02 +0000 |
---|---|---|
committer | Stef Walter <stef@memberwebs.com> | 2008-06-09 15:44:02 +0000 |
commit | 3add3c0e19b659427a2624ec85daf67019b8ed7f (patch) | |
tree | d838130f55963af53920646a37b4f1004208b586 /plugin | |
parent | abb82291887b6784a13a7fcf719fa1d463781007 (diff) |
Lots of bug fixes, changes.
Diffstat (limited to 'plugin')
-rw-r--r-- | plugin/Makefile.am | 2 | ||||
-rw-r--r-- | plugin/slapi-dnsnotify.c | 76 |
2 files changed, 58 insertions, 20 deletions
diff --git a/plugin/Makefile.am b/plugin/Makefile.am index d1887a3..9b8f4de 100644 --- a/plugin/Makefile.am +++ b/plugin/Makefile.am @@ -2,7 +2,7 @@ INCLUDES = \ -I$(top_srcdir) \ -DSTRSET_CUSTMEM=1 \ - -DDNS_NOTIFY_PATH=\"$(bindir)/notify-slaves\" + -DDNS_NOTIFY_PATH=\"$(bindir)/notify-dns-slaves\" lib_LTLIBRARIES = slapi-dnsnotify.la diff --git a/plugin/slapi-dnsnotify.c b/plugin/slapi-dnsnotify.c index b871c86..329b913 100644 --- a/plugin/slapi-dnsnotify.c +++ b/plugin/slapi-dnsnotify.c @@ -190,13 +190,32 @@ load_soa_ns_attributes (const char *dn, char **soa_result, char ***ns_result) return 0; } +static void +kill_notify_process (void) +{ + int status; + + if (dnsnotify_pipe != -1) + close (dnsnotify_pipe); + dnsnotify_pipe = -1; + + if (dnsnotify_pid != -1) { + if (waitpid (dnsnotify_pid, &status, WNOHANG) == 0) { + /* We can play rough, because we know process can take it */ + if (kill (dnsnotify_pid, SIGKILL) >= 0) + waitpid (dnsnotify_pid, &status, 0); + } + dnsnotify_pid = -1; + } +} + static int fork_notify_process (void) { - pid_t pid; - int status; + int open_max, fd; int commpipe[2]; char *args[3]; + pid_t pid; if (pipe (commpipe) < 0) { log_plugin ("couldn't create communication pipe for child process: %s", strerror (errno)); @@ -221,18 +240,11 @@ fork_notify_process (void) /* close read end */ close (commpipe[0]); - /* hang onto write end */ - if (dnsnotify_pipe != -1) - close (dnsnotify_pipe); - dnsnotify_pipe = commpipe[1]; + /* Kill any previous process */ + kill_notify_process (); - if (dnsnotify_pid != -1) { - if (waitpid (dnsnotify_pid, &status, WNOHANG) == 0) { - /* We can play rough, because we know process can take it */ - if (kill (dnsnotify_pid, SIGKILL) >= 0) - waitpid (dnsnotify_pid, &status, 0); - } - } + /* hang onto write end, and new pid */ + dnsnotify_pipe = commpipe[1]; dnsnotify_pid = pid; return 0; @@ -245,6 +257,11 @@ fork_notify_process (void) if (dup2 (commpipe[0], 0) < 0) log_plugin ("couldn't setup stdin on notify child process: %s", strerror (errno)); + /* Close all other file descriptors */ + open_max = sysconf (_SC_OPEN_MAX); + for (fd = 3; fd < open_max; ++fd) + close (fd); + args[0] = DNS_NOTIFY_PATH; args[1] = "-s"; args[2] = NULL; @@ -285,7 +302,7 @@ prep_soa_domain (char *soa) /* Find the first space in the SOA and cut it off there */ while (soa[0] && isspace (soa[0])) ++soa; - at = strspn (soa, " \t\n\r\v"); + at = strcspn (soa, " \t\n\r\v"); if (at == 0) { log_plugin ("invalid SOA present"); return NULL; @@ -334,11 +351,11 @@ notify_dns_slaves (char *soa, char **ns) if (!n[0]) continue; - if (write_all (dnsnotify_pipe, "NOTIFY: ", 5) < 0 || + if (write_all (dnsnotify_pipe, "NOTIFY: ", 8) < 0 || write_all (dnsnotify_pipe, soa, strlen (soa)) < 0 || write_all (dnsnotify_pipe, " ", 1) < 0 || - write_all (dnsnotify_pipe, *ns, strlen (soa)) < 0 || - write_all (dnsnotify_pipe, "\n", 2) < 0) { + write_all (dnsnotify_pipe, *ns, strlen (*ns)) < 0 || + write_all (dnsnotify_pipe, "\n", 1) < 0) { if (errno == EPIPE) { complete = 0; break; @@ -363,6 +380,8 @@ slapi_dnsnotify_modify (Slapi_PBlock *pb) return_val_if_fail (pb, -1); + trace ("detect modify"); + /* Make sure it was successful, don't process errors */ rc = slapi_pblock_get (pb, SLAPI_RESULT_CODE, &code); return_val_if_fail (rc >= 0, -1); @@ -380,6 +399,7 @@ slapi_dnsnotify_modify (Slapi_PBlock *pb) for (m = mods; *m; ++m) { mod = *m; + trace (mod->mod_type); if (strcmp (mod->mod_type, dnsnotify_soa_attribute) == 0) { if (load_soa_ns_attributes (dn, &soa, &ns)) { notify_dns_slaves (soa, ns); @@ -432,8 +452,25 @@ static Slapi_PluginDesc plugin_description = { "Notify's DNS slaves when SOA change is made" /* plug-in description */ }; +static int +plugin_destroy (Slapi_PBlock *pb) +{ + if (dnsnotify_mutex) + slapi_lock_mutex (dnsnotify_mutex); + + kill_notify_process (); + + if (dnsnotify_mutex) { + slapi_unlock_mutex (dnsnotify_mutex); + slapi_destroy_mutex (dnsnotify_mutex); + dnsnotify_mutex = NULL; + } + + return 0; +} + int -plugin_init (Slapi_PBlock* pb) +plugin_init (Slapi_PBlock *pb) { char **argv = NULL; int argc = 0; @@ -464,7 +501,8 @@ plugin_init (Slapi_PBlock* pb) } if (slapi_pblock_set (pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_03) != 0 || - slapi_pblock_set (pb, SLAPI_PLUGIN_DESCRIPTION, &plugin_description) != 0) { + slapi_pblock_set (pb, SLAPI_PLUGIN_DESCRIPTION, &plugin_description) != 0 || + slapi_pblock_set (pb, SLAPI_PLUGIN_DESTROY_FN, plugin_destroy)) { log_plugin ("error registring plugin"); return -1; } |