aboutsummaryrefslogtreecommitdiffstats
path: root/src/frontends/osx
diff options
context:
space:
mode:
authorMartin Willi <martin@revosec.ch>2013-05-02 14:40:23 +0200
committerMartin Willi <martin@revosec.ch>2013-07-18 12:17:55 +0200
commita0c125eacb612ecb0e30b1f8335dc6ab3e378c0c (patch)
tree1bdb4c7466def60db5abeaadbfc9cf771ad3e168 /src/frontends/osx
parent6aae6268d7b3ff57cea3e453756080b99c176702 (diff)
downloadstrongswan-a0c125eacb612ecb0e30b1f8335dc6ab3e378c0c.tar.bz2
strongswan-a0c125eacb612ecb0e30b1f8335dc6ab3e378c0c.tar.xz
xpc: terminate daemon when last XPC connection to App gone
Diffstat (limited to 'src/frontends/osx')
-rw-r--r--src/frontends/osx/charon-xpc/xpc_dispatch.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/frontends/osx/charon-xpc/xpc_dispatch.c b/src/frontends/osx/charon-xpc/xpc_dispatch.c
index 1f636bc43..1ef77bfa1 100644
--- a/src/frontends/osx/charon-xpc/xpc_dispatch.c
+++ b/src/frontends/osx/charon-xpc/xpc_dispatch.c
@@ -17,6 +17,8 @@
#include "xpc_channels.h"
#include <xpc/xpc.h>
+#include <signal.h>
+#include <unistd.h>
#include <daemon.h>
#include <processing/jobs/callback_job.h>
@@ -47,6 +49,16 @@ struct private_xpc_dispatch_t {
* GCD queue for XPC events
*/
dispatch_queue_t queue;
+
+ /**
+ * Number of active App connections
+ */
+ refcount_t refcount;
+
+ /**
+ * PID of main thread
+ */
+ pid_t pid;
};
/**
@@ -258,6 +270,18 @@ static void handle(private_xpc_dispatch_t *this, xpc_object_t request)
}
/**
+ * Finalizer for client connections
+ */
+static void cleanup_connection(private_xpc_dispatch_t *this)
+{
+ if (ref_put(&this->refcount))
+ {
+ DBG1(DBG_CFG, "no XPC connections, raising SIGTERM");
+ kill(this->pid, SIGTERM);
+ }
+}
+
+/**
* Set up GCD handler for XPC events
*/
static void set_handler(private_xpc_dispatch_t *this)
@@ -271,6 +295,9 @@ static void set_handler(private_xpc_dispatch_t *this)
handle(this, event);
}
});
+ ref_get(&this->refcount);
+ xpc_connection_set_context(conn, this);
+ xpc_connection_set_finalizer_f(conn, (void*)cleanup_connection);
xpc_connection_resume(conn);
});
xpc_connection_resume(this->service);
@@ -303,6 +330,7 @@ xpc_dispatch_t *xpc_dispatch_create()
.channels = xpc_channels_create(),
.queue = dispatch_queue_create("org.strongswan.charon-xpc.q",
DISPATCH_QUEUE_CONCURRENT),
+ .pid = getpid(),
);
charon->bus->add_listener(charon->bus, &this->channels->listener);