Change the multibyte character set support so that
[kai/samba.git] / source3 / nmbd / asyncdns.c
index e0d262f72ca4a681c5f37f2dcd54dc3de378b098..3fb16a08e94497993f4742e1a08d4bd14e205816 100644 (file)
@@ -1,7 +1,7 @@
 /*
    Unix SMB/Netbios implementation.
    a async DNS handler
-   Copyright (C) Andrew Tridgell 1997
+   Copyright (C) Andrew Tridgell 1997-1998
    
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -103,7 +103,8 @@ static void asyncdns_process(void)
 }
 
 /**************************************************************************** **
-  catch a sigterm
+  catch a sigterm (in the child process - the parent has a different handler
+  see nmbd.c for details).
   We need a separate term handler here so we don't release any 
   names that our parent is going to release, or overwrite a 
   WINS db that our parent is going to write.
@@ -116,6 +117,17 @@ static int sig_term()
   return 0;
 }
 
+/***************************************************************************
+ Called by the parent process when it receives a SIGTERM - also kills the
+ child so we don't get child async dns processes lying around, causing trouble.
+  ****************************************************************************/
+
+void kill_async_dns_child()
+{
+  if(child_pid != 0 && child_pid != -1)
+    kill(child_pid, SIGTERM);
+}
+
 /***************************************************************************
   create a child process to handle DNS lookups
   ****************************************************************************/
@@ -187,6 +199,9 @@ void run_dns_queue(void)
        if (fd_in == -1)
                return;
 
+        /* Allow SIGTERM to kill us. */
+        BlockSignals(False, SIGTERM);
+
        if (!process_exists(child_pid)) {
                close(fd_in);
                start_async_dns();
@@ -197,9 +212,12 @@ void run_dns_queue(void)
                        DEBUG(0,("Incomplete DNS answer from child!\n"));
                        fd_in = -1;
                }
+                BlockSignals(True, SIGTERM);
                return;
        }
 
+        BlockSignals(True, SIGTERM);
+
        namerec = add_dns_result(&r.name, r.result);
 
        if (dns_current) {
@@ -305,8 +323,14 @@ BOOL queue_dns_query(struct packet_struct *p,struct nmb_name *question,
 
        DEBUG(3,("DNS search for %s - ", namestr(question)));
 
+        /* Unblock TERM signal so we can be killed in DNS lookup. */
+        BlockSignals(False, SIGTERM);
+
        dns_ip.s_addr = interpret_addr(qname);
 
+        /* Re-block TERM signal. */
+        BlockSignals(True, SIGTERM);
+
        *n = add_dns_result(question, dns_ip);
         if(*n == NULL)
           send_wins_name_query_response(NAM_ERR, p, NULL);
@@ -314,4 +338,12 @@ BOOL queue_dns_query(struct packet_struct *p,struct nmb_name *question,
           send_wins_name_query_response(0, p, *n);
        return False;
 }
+
+/***************************************************************************
+ With sync dns there is no child to kill on SIGTERM.
+  ****************************************************************************/
+void kill_async_dns_child()
+{
+  return;
+}
 #endif