Commit 57f3a1f100 for strongswan.org

commit 57f3a1f1002cab865331f05dbf5aa010e1e35b60
Author: Tobias Brunner <tobias@strongswan.org>
Date:   Wed Dec 2 14:22:55 2026 +0100

    charon-nm: Block SIGINT and SIGTERM before GLib/GDBus spawns threads

    During the initialization of the VPN plugin and the creation of the
    GInitable object via `nm_backend_init()` and `nm_strongswan_plugin_new()`,
    GLib/GDBus can spawn threads.  If we don't set the signal mask before
    that, the signal might later be delivered to one of those threads instead
    of our main thread waiting in `sigwaitinfo()`, causing the daemon not to
    shut down.

    Closes strongswan/strongswan#3202

diff --git a/src/charon-nm/charon-nm.c b/src/charon-nm/charon-nm.c
index 9dbc907888..77ca660fc1 100644
--- a/src/charon-nm/charon-nm.c
+++ b/src/charon-nm/charon-nm.c
@@ -241,6 +241,16 @@ int main(int argc, char *argv[])
 	/* register NM backend to be loaded with plugins */
 	nm_backend_register();

+	/* INT and TERM are handled by sigwaitinfo() in run() so we mask them in
+	 * all threads, including the ones spawned by GLib when the VPN plugin is
+	 * initialized */
+	action.sa_flags = 0;
+	sigemptyset(&action.sa_mask);
+	sigaddset(&action.sa_mask, SIGINT);
+	sigaddset(&action.sa_mask, SIGTERM);
+
+	pthread_sigmask(SIG_SETMASK, &action.sa_mask, NULL);
+
 	/* initialize daemon */
 	if (!charon->initialize(charon,
 			lib->settings->get_str(lib->settings, "charon-nm.load", PLUGINS)))
@@ -256,13 +266,6 @@ int main(int argc, char *argv[])
 		goto deinit;
 	}

-	/* add handler for fatal signals,
-	 * INT and TERM are handled by sigwaitinfo() in run() */
-	action.sa_flags = 0;
-	sigemptyset(&action.sa_mask);
-	sigaddset(&action.sa_mask, SIGINT);
-	sigaddset(&action.sa_mask, SIGTERM);
-
 	/* optionally let the external system handle fatal signals */
 #ifndef DISABLE_SIGNAL_HANDLER
 	action.sa_handler = segv_handler;
@@ -274,8 +277,6 @@ int main(int argc, char *argv[])
 	action.sa_handler = SIG_IGN;
 	sigaction(SIGPIPE, &action, NULL);

-	pthread_sigmask(SIG_SETMASK, &action.sa_mask, NULL);
-
 	/* start daemon (i.e. the threads in the thread-pool) */
 	charon->start(charon);