]> git.saurik.com Git - apple/ipsec.git/blobdiff - ipsec-tools/racoon/session.c
ipsec-317.220.1.tar.gz
[apple/ipsec.git] / ipsec-tools / racoon / session.c
index 694ca2fab461251d38091e30b331dfcbabcb9195..208ff5dcb110e78d81555a8ed83cd8b0a062dd4e 100644 (file)
 #include <netinet/ip.h>
 #include <netinet/ip_icmp.h>
 
-#include <resolv.h>
 #include <TargetConditionals.h>
 #include <vproc_priv.h>
 #include <dispatch/dispatch.h>
+#include <xpc/xpc.h>
 
 #include "libpfkey.h"
 
@@ -114,7 +114,6 @@ extern int launchdlaunched;
 static void close_session (int);
 static int init_signal (void);
 static int set_signal (int sig, RETSIGTYPE (*func) (int, siginfo_t *, void *));
-static void check_sigreq (void);
 static void check_flushsa_stub (void *);
 static void check_flushsa (void);
 static void auto_exit_do (void *);
@@ -122,6 +121,7 @@ static int close_sockets (void);
 
 static volatile sig_atomic_t sigreq[NSIG + 1];
 int terminated = 0;
+int pending_signal_handle = 0;
 
 static int64_t racoon_keepalive = -1;
 
@@ -314,6 +314,9 @@ session(void)
                                "cannot open %s", pid_file);
                }
        }
+       
+       xpc_transaction_begin();
+       
 #if !TARGET_OS_EMBEDDED
        // enable keepalive for recovery (from crashes and bad exits... after init)
        (void)launchd_update_racoon_keepalive(true);
@@ -339,12 +342,14 @@ close_session(int error)
        ike_session_flush_all_phase1(false);
        close_sockets();
 
+       xpc_transaction_end();
+       
 #if !TARGET_OS_EMBEDDED
        // a clean exit, so disable launchd keepalive
        (void)launchd_update_racoon_keepalive(false);
 #endif // !TARGET_OS_EMBEDDED
 
-       plog(ASL_LEVEL_INFO, "racoon shutdown\n");
+       plog(ASL_LEVEL_NOTICE, "racoon shutdown\n");
        exit(0);
 }
 
@@ -430,7 +435,7 @@ check_flushsa()
 void
 auto_exit_do(void *p)
 {
-       plog(ASL_LEVEL_DEBUG, 
+       plog(ASL_LEVEL_NOTICE,
                                "performing auto exit\n");
 #if ENABLE_NO_SA_FLUSH
        close_session(0);
@@ -476,7 +481,7 @@ static int signals[] = {
 };
 
 
-static void
+void
 check_sigreq()
 {
        int sig;
@@ -550,7 +555,7 @@ check_sigreq()
                 
             case SIGINT:
             case SIGTERM:                      
-                plog(ASL_LEVEL_INFO
+                plog(ASL_LEVEL_NOTICE
                      "caught signal %d\n", sig);
 #if ENABLE_NO_SA_FLUSH
                 close_session(0);
@@ -569,7 +574,7 @@ check_sigreq()
                 break;
                 
             default:
-                plog(ASL_LEVEL_INFO
+                plog(ASL_LEVEL_NOTICE
                      "caught signal %d\n", sig);
                 break;
                }
@@ -585,7 +590,7 @@ RETSIGTYPE
 signal_handler(int sig, siginfo_t *sigi, void *ctx)
 {
 #if 0
-    plog(ASL_LEVEL_DEBUG, 
+    plog(ASL_LEVEL_NOTICE,
          "%s received signal %d from pid %d uid %d\n\n",
          __FUNCTION__, sig, sigi->si_pid, sigi->si_uid);
 #endif
@@ -597,9 +602,14 @@ signal_handler(int sig, siginfo_t *sigi, void *ctx)
     if ( sig == SIGTERM ){
         terminated = 1;
     }
+
+       pending_signal_handle = 1;
     dispatch_async(main_queue, 
                    ^{
-                        check_sigreq(); 
+                                               if (pending_signal_handle) {
+                                                       check_sigreq();
+                                                       pending_signal_handle = 0;
+                                               }
                    });
 }