summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Winship <danw@redhat.com>2015-01-19 11:50:15 -0500
committerDan Winship <danw@redhat.com>2015-01-19 11:50:15 -0500
commit1970f59b6f463be559c47fe944efd560a4629c88 (patch)
tree28fa91046c8e23a7a28eafea44393a1530072e69
parent1c435dc87478d0bd917f555d16f1ad7dbf6c1e96 (diff)
parentfb792af7cb5dde72b05e2312c2ce7d92aa29f34d (diff)
downloadNetworkManager-1970f59b6f463be559c47fe944efd560a4629c88.tar.gz
core: merge branch 'danw/signals-bgo743052'
https://bugzilla.gnome.org/show_bug.cgi?id=743052
-rw-r--r--callouts/nm-dispatcher.c11
-rw-r--r--src/Makefile.am4
-rw-r--r--src/NetworkManagerUtils.c21
-rw-r--r--src/NetworkManagerUtils.h2
-rw-r--r--src/devices/nm-device.c37
-rw-r--r--src/devices/team/nm-device-team.c22
-rw-r--r--src/dhcp-manager/nm-dhcp-dhclient.c17
-rw-r--r--src/dhcp-manager/nm-dhcp-dhcpcd.c17
-rw-r--r--src/dns-manager/nm-dns-manager.c16
-rw-r--r--src/dns-manager/nm-dns-plugin.c19
-rw-r--r--src/dnsmasq-manager/nm-dnsmasq-manager.c21
-rw-r--r--src/main-utils.c114
-rw-r--r--src/main-utils.h2
-rw-r--r--src/main.c9
-rw-r--r--src/nm-activation-request.c13
-rw-r--r--src/nm-dcb.c3
-rw-r--r--src/nm-iface-helper.c22
-rw-r--r--src/nm-posix-signals.c62
-rw-r--r--src/nm-posix-signals.h36
-rw-r--r--src/ppp-manager/nm-ppp-manager.c19
-rw-r--r--src/settings/plugins/ibft/reader.c19
-rw-r--r--src/settings/plugins/ifcfg-rh/reader.c1
-rw-r--r--src/vpn-manager/nm-vpn-service.c17
23 files changed, 87 insertions, 417 deletions
diff --git a/callouts/nm-dispatcher.c b/callouts/nm-dispatcher.c
index 0cd2531dda..6fb40cf9f3 100644
--- a/callouts/nm-dispatcher.c
+++ b/callouts/nm-dispatcher.c
@@ -361,15 +361,6 @@ check_filename (const char *file_name)
return TRUE;
}
-static void
-child_setup (gpointer user_data G_GNUC_UNUSED)
-{
- /* We are in the child process at this point */
- /* Give child a different process group to ensure signal separation. */
- pid_t pid = getpid ();
- setpgid (pid, pid);
-}
-
#define SCRIPT_TIMEOUT 600 /* 10 minutes */
static void
@@ -387,7 +378,7 @@ dispatch_one_script (Request *request)
if (request->debug)
g_message ("Running script '%s'", script->script);
- if (g_spawn_async ("/", argv, request->envp, G_SPAWN_DO_NOT_REAP_CHILD, child_setup, request, &script->pid, &error)) {
+ if (g_spawn_async ("/", argv, request->envp, G_SPAWN_DO_NOT_REAP_CHILD, NULL, request, &script->pid, &error)) {
request->script_watch_id = g_child_watch_add (script->pid, (GChildWatchFunc) script_watch_cb, script);
request->script_timeout_id = g_timeout_add_seconds (SCRIPT_TIMEOUT, script_timeout_cb, script);
} else {
diff --git a/src/Makefile.am b/src/Makefile.am
index e9cedd9d67..b8e4c36b38 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -320,8 +320,6 @@ nm_sources = \
nm-manager.h \
nm-policy.c \
nm-policy.h \
- nm-posix-signals.c \
- nm-posix-signals.h \
nm-properties-changed-signal.c \
nm-properties-changed-signal.h \
nm-rfkill-manager.c \
@@ -481,8 +479,6 @@ libnm_iface_helper_la_SOURCES = \
nm-enum-types.h \
nm-logging.c \
nm-logging.h \
- nm-posix-signals.c \
- nm-posix-signals.h \
NetworkManagerUtils.c \
NetworkManagerUtils.h
diff --git a/src/NetworkManagerUtils.c b/src/NetworkManagerUtils.c
index abd4e140a5..268abb84a8 100644
--- a/src/NetworkManagerUtils.c
+++ b/src/NetworkManagerUtils.c
@@ -47,7 +47,6 @@
#include "nm-setting-wireless.h"
#include "nm-setting-wireless-security.h"
#include "nm-auth-utils.h"
-#include "nm-posix-signals.h"
#include "nm-dbus-glib-types.h"
/*
@@ -167,7 +166,7 @@ nm_spawn_process (const char *args)
return -1;
}
- if (!g_spawn_sync ("/", argv, NULL, 0, nm_unblock_posix_signals, NULL, NULL, NULL, &status, &error)) {
+ if (!g_spawn_sync ("/", argv, NULL, 0, NULL, NULL, NULL, NULL, &status, &error)) {
nm_log_warn (LOGD_CORE, "could not spawn process '%s': %s", args, error->message);
g_error_free (error);
}
@@ -2547,3 +2546,21 @@ nm_utils_ip6_routes_from_gvalue (const GValue *value)
return g_slist_reverse (list);
}
+
+/**
+ * nm_utils_setpgid:
+ * @unused: unused
+ *
+ * This can be passed as a child setup function to the g_spawn*() family
+ * of functions, to ensure that the child is in its own process group
+ * (and thus, in some situations, will not be killed when NetworkManager
+ * is killed).
+ */
+void
+nm_utils_setpgid (gpointer unused G_GNUC_UNUSED)
+{
+ pid_t pid;
+
+ pid = getpid ();
+ setpgid (pid, pid);
+}
diff --git a/src/NetworkManagerUtils.h b/src/NetworkManagerUtils.h
index 40315c6efc..99543df314 100644
--- a/src/NetworkManagerUtils.h
+++ b/src/NetworkManagerUtils.h
@@ -210,4 +210,6 @@ GHashTable *nm_utils_connection_dict_to_hash (GVariant *dict);
GSList *nm_utils_ip4_routes_from_gvalue (const GValue *value);
GSList *nm_utils_ip6_routes_from_gvalue (const GValue *value);
+void nm_utils_setpgid (gpointer unused);
+
#endif /* __NETWORKMANAGER_UTILS_H__ */
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c
index 119d4a85c1..0ad774d29b 100644
--- a/src/devices/nm-device.c
+++ b/src/devices/nm-device.c
@@ -62,7 +62,6 @@
#include "nm-enum-types.h"
#include "nm-settings-connection.h"
#include "nm-connection-provider.h"
-#include "nm-posix-signals.h"
#include "nm-auth-utils.h"
#include "nm-dbus-glib-types.h"
#include "nm-dispatcher.h"
@@ -2717,23 +2716,6 @@ aipd_timeout_cb (gpointer user_data)
return FALSE;
}
-static void
-aipd_child_setup (gpointer user_data G_GNUC_UNUSED)
-{
- /* We are in the child process at this point.
- * Give child it's own program group for signal
- * separation.
- */
- pid_t pid = getpid ();
- setpgid (pid, pid);
-
- /*
- * We blocked signals in main(). We need to restore original signal
- * mask for avahi-autoipd here so that it can receive signals.
- */
- nm_unblock_posix_signals (NULL);
-}
-
/* default to installed helper, but can be modified for testing */
const char *nm_device_autoipd_helper_path = LIBEXECDIR "/nm-avahi-autoipd.action";
@@ -2773,7 +2755,7 @@ aipd_start (NMDevice *self, NMDeviceStateReason *reason)
g_free (cmdline);
if (!g_spawn_async ("/", (char **) argv, NULL, G_SPAWN_DO_NOT_REAP_CHILD,
- &aipd_child_setup, NULL, &(priv->aipd_pid), &error)) {
+ nm_utils_setpgid, NULL, &(priv->aipd_pid), &error)) {
_LOGW (LOGD_DEVICE | LOGD_AUTOIP4,
"Activation: Stage 3 of 5 (IP Configure Start) failed"
" to start avahi-autoipd: %s",
@@ -4949,16 +4931,6 @@ nm_device_activate_schedule_ip6_config_timeout (NMDevice *self)
"Activation: Stage 4 of 5 (IPv6 Configure Timeout) scheduled...");
}
-static void
-share_child_setup (gpointer user_data G_GNUC_UNUSED)
-{
- /* We are in the child process at this point */
- pid_t pid = getpid ();
- setpgid (pid, pid);
-
- nm_unblock_posix_signals (NULL);
-}
-
static gboolean
share_init (void)
{
@@ -4988,7 +4960,7 @@ share_init (void)
GError *error = NULL;
if (!g_spawn_sync ("/", argv, envp, G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL,
- share_child_setup, NULL, NULL, NULL, &status, &error)) {
+ NULL, NULL, NULL, NULL, &status, &error)) {
nm_log_err (LOGD_SHARING, "share: error loading NAT module %s: (%d) %s",
*iter, error ? error->code : 0,
(error && error->message) ? error->message : "unknown");
@@ -5113,8 +5085,7 @@ send_arps (NMDevice *self, const char *mode_arg)
"arping: run %s", (tmp_str = g_strjoinv (" ", (char **) argv)));
success = g_spawn_async (NULL, (char **) argv, NULL,
G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL,
- nm_unblock_posix_signals,
- NULL, NULL, &error);
+ NULL, NULL, NULL, &error);
if (!success) {
_LOGW (LOGD_DEVICE | LOGD_IP4,
"arping: could not send ARP for local address %s: %s",
@@ -6149,7 +6120,7 @@ spawn_ping (NMDevice *self,
(gchar **) args,
NULL,
G_SPAWN_DO_NOT_REAP_CHILD,
- nm_unblock_posix_signals,
+ NULL,
NULL,
&priv->gw_ping.pid,
&error);
diff --git a/src/devices/team/nm-device-team.c b/src/devices/team/nm-device-team.c
index 2933fee976..a03ad3f98b 100644
--- a/src/devices/team/nm-device-team.c
+++ b/src/devices/team/nm-device-team.c
@@ -39,7 +39,6 @@
#include "nm-dbus-manager.h"
#include "nm-enum-types.h"
#include "nm-team-enum-types.h"
-#include "nm-posix-signals.h"
#include "nm-core-internal.h"
#include "nm-device-team-glue.h"
@@ -384,23 +383,6 @@ teamd_process_watch_cb (GPid pid, gint status, gpointer user_data)
}
static void
-teamd_child_setup (gpointer user_data G_GNUC_UNUSED)
-{
- /* We are in the child process at this point.
- * Give child it's own program group for signal
- * separation.
- */
- pid_t pid = getpid ();
- setpgid (pid, pid);
-
- /*
- * We blocked signals in main(). We need to restore original signal
- * mask for avahi-autoipd here so that it can receive signals.
- */
- nm_unblock_posix_signals (NULL);
-}
-
-static void
nm_device_team_watch_dbus (NMDeviceTeam *self)
{
NMDeviceTeamPrivate *priv = NM_DEVICE_TEAM_GET_PRIVATE (self);
@@ -461,7 +443,7 @@ teamd_start (NMDevice *device, NMSettingTeam *s_team)
(tmp_str = g_strjoinv (" ", (gchar **) argv->pdata)));
g_clear_pointer (&tmp_str, g_free);
- ret = g_spawn_sync ("/", (char **) argv->pdata, NULL, 0, nm_unblock_posix_signals, NULL, NULL, NULL, &status, &error);
+ ret = g_spawn_sync ("/", (char **) argv->pdata, NULL, 0, NULL, NULL, NULL, NULL, &status, &error);
g_ptr_array_free (argv, TRUE);
/* Start teamd now */
@@ -493,7 +475,7 @@ teamd_start (NMDevice *device, NMSettingTeam *s_team)
priv->teamd_timeout = g_timeout_add_seconds (5, teamd_timeout_cb, device);
ret = g_spawn_async ("/", (char **) argv->pdata, NULL, G_SPAWN_DO_NOT_REAP_CHILD,
- &teamd_child_setup, NULL, &priv->teamd_pid, &error);
+ nm_utils_setpgid, NULL, &priv->teamd_pid, &error);
g_ptr_array_free (argv, TRUE);
if (!ret) {
_LOGW (LOGD_TEAM, "Activation: (team) failed to start teamd: %s", error->message);
diff --git a/src/dhcp-manager/nm-dhcp-dhclient.c b/src/dhcp-manager/nm-dhcp-dhclient.c
index 504e8d5d17..91515ddac1 100644
--- a/src/dhcp-manager/nm-dhcp-dhclient.c
+++ b/src/dhcp-manager/nm-dhcp-dhclient.c
@@ -41,7 +41,6 @@
#include "nm-logging.h"
#include "nm-dhcp-dhclient-utils.h"
#include "nm-dhcp-manager.h"
-#include "nm-posix-signals.h"
#include "NetworkManagerUtils.h"
#include "nm-dhcp-listener.h"
#include "gsystem-local-alloc.h"
@@ -301,20 +300,6 @@ create_dhclient_config (const char *iface,
}
-static void
-dhclient_child_setup (gpointer user_data G_GNUC_UNUSED)
-{
- /* We are in the child process at this point */
- pid_t pid = getpid ();
- setpgid (pid, pid);
-
- /*
- * We blocked signals in main(). We need to restore original signal
- * mask for dhclient here so that it can receive signals.
- */
- nm_unblock_posix_signals (NULL);
-}
-
static gboolean
dhclient_start (NMDhcpClient *client,
const char *mode_opt,
@@ -457,7 +442,7 @@ dhclient_start (NMDhcpClient *client,
if (g_spawn_async (NULL, (char **) argv->pdata, NULL,
G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL,
- &dhclient_child_setup, NULL, &pid, &error)) {
+ nm_utils_setpgid, NULL, &pid, &error)) {
g_assert (pid > 0);
nm_log_info (log_domain, "dhclient started with pid %d", pid);
if (release == FALSE)
diff --git a/src/dhcp-manager/nm-dhcp-dhcpcd.c b/src/dhcp-manager/nm-dhcp-dhcpcd.c
index e5a40c2fba..86aba4dac1 100644
--- a/src/dhcp-manager/nm-dhcp-dhcpcd.c
+++ b/src/dhcp-manager/nm-dhcp-dhcpcd.c
@@ -37,7 +37,6 @@
#include "nm-dhcp-manager.h"
#include "nm-utils.h"
#include "nm-logging.h"
-#include "nm-posix-signals.h"
#include "NetworkManagerUtils.h"
#include "nm-dhcp-listener.h"
@@ -59,20 +58,6 @@ nm_dhcp_dhcpcd_get_path (void)
return path;
}
-static void
-dhcpcd_child_setup (gpointer user_data G_GNUC_UNUSED)
-{
- /* We are in the child process at this point */
- pid_t pid = getpid ();
- setpgid (pid, pid);
-
- /*
- * We blocked signals in main(). We need to restore original signal
- * mask for dhcpcd here so that it can receive signals.
- */
- nm_unblock_posix_signals (NULL);
-}
-
static gboolean
ip4_start (NMDhcpClient *client, const char *dhcp_anycast_addr, const char *last_ip4_address)
{
@@ -143,7 +128,7 @@ ip4_start (NMDhcpClient *client, const char *dhcp_anycast_addr, const char *last
if (g_spawn_async (NULL, (char **) argv->pdata, NULL,
G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL,
- &dhcpcd_child_setup, NULL, &pid, &error)) {
+ nm_utils_setpgid, NULL, &pid, &error)) {
g_assert (pid > 0);
nm_log_info (LOGD_DHCP4, "dhcpcd started with pid %d", pid);
nm_dhcp_client_watch_child (client, pid);
diff --git a/src/dns-manager/nm-dns-manager.c b/src/dns-manager/nm-dns-manager.c
index 39ef99bda5..47e3f123f1 100644
--- a/src/dns-manager/nm-dns-manager.c
+++ b/src/dns-manager/nm-dns-manager.c
@@ -42,7 +42,6 @@
#include "nm-ip6-config.h"
#include "nm-logging.h"
#include "NetworkManagerUtils.h"
-#include "nm-posix-signals.h"
#include "nm-config.h"
#include "nm-dns-plugin.h"
@@ -224,19 +223,6 @@ merge_one_ip6_config (NMResolvConfData *rc, NMIP6Config *src)
/**********************************/
/* SUSE */
-static void
-netconfig_child_setup (gpointer user_data G_GNUC_UNUSED)
-{
- pid_t pid = getpid ();
- setpgid (pid, pid);
-
- /*
- * We blocked signals in main(). We need to restore original signal
- * mask for netconfig here so that it can receive signals.
- */
- nm_unblock_posix_signals (NULL);
-}
-
static GPid
run_netconfig (GError **error, gint *stdin_fd)
{
@@ -254,7 +240,7 @@ run_netconfig (GError **error, gint *stdin_fd)
nm_log_dbg (LOGD_DNS, "spawning '%s'", tmp);
g_free (tmp);
- if (!g_spawn_async_with_pipes (NULL, argv, NULL, 0, netconfig_child_setup,
+ if (!g_spawn_async_with_pipes (NULL, argv, NULL, 0, NULL,
NULL, &pid, stdin_fd, NULL, NULL, error))
return -1;
diff --git a/src/dns-manager/nm-dns-plugin.c b/src/dns-manager/nm-dns-plugin.c
index b083b1058e..3d593cce8d 100644
--- a/src/dns-manager/nm-dns-plugin.c
+++ b/src/dns-manager/nm-dns-plugin.c
@@ -28,7 +28,6 @@
#include "nm-dns-plugin.h"
#include "nm-logging.h"
-#include "nm-posix-signals.h"
#include "NetworkManagerUtils.h"
typedef struct {
@@ -136,20 +135,6 @@ watch_cb (GPid pid, gint status, gpointer user_data)
g_signal_emit (self, signals[CHILD_QUIT], 0, status);
}
-static void
-child_setup (gpointer user_data G_GNUC_UNUSED)
-{
- /* We are in the child process at this point */
- pid_t pid = getpid ();
- setpgid (pid, pid);
-
- /*
- * We blocked signals in main(). We need to restore original signal
- * mask for DNS plugin here so that it can receive signals.
- */
- nm_unblock_posix_signals (NULL);
-}
-
GPid
nm_dns_plugin_child_spawn (NMDnsPlugin *self,
const char **argv,
@@ -183,8 +168,8 @@ nm_dns_plugin_child_spawn (NMDnsPlugin *self,
priv->pid = 0;
if (g_spawn_async (NULL, (char **) argv, NULL,
G_SPAWN_DO_NOT_REAP_CHILD,
- child_setup,
- NULL, &priv->pid,
+ nm_utils_setpgid, NULL,
+ &priv->pid,
&error)) {
nm_log_dbg (LOGD_DNS, "%s started with pid %d", priv->progname, priv->pid);
priv->watch_id = g_child_watch_add (priv->pid, (GChildWatchFunc) watch_cb, self);
diff --git a/src/dnsmasq-manager/nm-dnsmasq-manager.c b/src/dnsmasq-manager/nm-dnsmasq-manager.c
index 2f38ea7104..a85631bcb1 100644
--- a/src/dnsmasq-manager/nm-dnsmasq-manager.c
+++ b/src/dnsmasq-manager/nm-dnsmasq-manager.c
@@ -32,7 +32,6 @@
#include "nm-dnsmasq-utils.h"
#include "nm-logging.h"
#include "nm-glib-compat.h"
-#include "nm-posix-signals.h"
#include "nm-utils.h"
#include "NetworkManagerUtils.h"
@@ -297,20 +296,6 @@ create_dm_cmd_line (const char *iface,
}
static void
-dm_child_setup (gpointer user_data G_GNUC_UNUSED)
-{
- /* We are in the child process at this point */
- pid_t pid = getpid ();
- setpgid (pid, pid);
-
- /*
- * We blocked signals in main(). We need to restore original signal
- * mask for dnsmasq here so that it can receive signals.
- */
- nm_unblock_posix_signals (NULL);
-}
-
-static void
kill_existing_for_iface (const char *iface, const char *pidfile)
{
char *contents = NULL;
@@ -374,9 +359,9 @@ nm_dnsmasq_manager_start (NMDnsMasqManager *manager,
priv->pid = 0;
if (!g_spawn_async (NULL, (char **) dm_cmd->array->pdata, NULL,
- G_SPAWN_DO_NOT_REAP_CHILD,
- dm_child_setup,
- NULL, &priv->pid, error)) {
+ G_SPAWN_DO_NOT_REAP_CHILD,
+ nm_utils_setpgid, NULL,
+ &priv->pid, error)) {
goto out;
}
diff --git a/src/main-utils.c b/src/main-utils.c
index 0fa3644f3e..0825a7f01d 100644
--- a/src/main-utils.c
+++ b/src/main-utils.c
@@ -31,101 +31,59 @@
#include <glib.h>
#include <glib/gi18n.h>
+#include <glib-unix.h>
#include <gmodule.h>
#include "main-utils.h"
-#include "nm-posix-signals.h"
#include "nm-logging.h"
-static sigset_t signal_set;
-static gboolean *quit_early = NULL;
+static gboolean
+sighup_handler (gpointer user_data)
+{
+ /* Reread config stuff like system config files, VPN service files, etc */
+ nm_log_info (LOGD_CORE, "caught SIGHUP, not supported yet.");
-/*
- * Thread function waiting for signals and processing them.
- * Wait for signals in signal set. The semantics of sigwait() require that all
- * threads (including the thread calling sigwait()) have the signal masked, for
- * reliable operation. Otherwise, a signal that arrives while this thread is
- * not blocked in sigwait() might be delivered to another thread.
- */
-static void *
-signal_handling_thread (void *arg)
+ return G_SOURCE_CONTINUE;
+}
+
+static gboolean
+sigint_handler (gpointer user_data)
{
- GMainLoop *main_loop = arg;
- int signo;
-
- while (1) {
- sigwait (&signal_set, &signo);
-
- switch (signo) {
- case SIGINT:
- case SIGTERM:
- nm_log_info (LOGD_CORE, "caught signal %d, shutting down normally.", signo);
- *quit_early = TRUE; /* for quitting before entering the main loop */
- g_main_loop_quit (main_loop);
- break;
- case SIGHUP:
- /* Reread config stuff like system config files, VPN service files, etc */
- nm_log_info (LOGD_CORE, "caught signal %d, not supported yet.", signo);
- break;
- case SIGPIPE:
- /* silently ignore signal */
- break;
- default:
- nm_log_err (LOGD_CORE, "caught unexpected signal %d", signo);
- break;
- }
- }
- return NULL;
+ GMainLoop *main_loop = user_data;
+
+ nm_log_info (LOGD_CORE, "caught SIGINT, shutting down normally.");
+ g_main_loop_quit (main_loop);
+
+ return G_SOURCE_REMOVE;
+}
+
+static gboolean
+sigterm_handler (gpointer user_data)
+{
+ GMainLoop *main_loop = user_data;
+
+ nm_log_info (LOGD_CORE, "caught SIGTERM, shutting down normally.");
+ g_main_loop_quit (main_loop);
+
+ return G_SOURCE_REMOVE;
}
/**
* nm_main_utils_setup_signals:
* @main_loop: the #GMainLoop to quit when SIGINT or SIGTERM is received
- * @quit_early: location of a variable that will be set to TRUE when
- * SIGINT or SIGTERM is received
- *
- * Mask the signals we are interested in and create a signal handling thread.
- * Because all threads inherit the signal mask from their creator, all threads
- * in the process will have the signals masked. That's why setup_signals() has
- * to be called before creating other threads.
*
- * Returns: %TRUE on success
+ * Sets up signal handling for NetworkManager.
*/
-gboolean
-nm_main_utils_setup_signals (GMainLoop *main_loop, gboolean *quit_early_ptr)
+void
+nm_main_utils_setup_signals (GMainLoop *main_loop)
{
- pthread_t signal_thread_id;
- sigset_t old_sig_mask;
- int status;
-
- g_return_val_if_fail (main_loop != NULL, FALSE);
- g_return_val_if_fail (quit_early_ptr != NULL, FALSE);
-
- quit_early = quit_early_ptr;
-
- sigemptyset (&signal_set);
- sigaddset (&signal_set, SIGHUP);
- sigaddset (&signal_set, SIGINT);
- sigaddset (&signal_set, SIGTERM);
- sigaddset (&signal_set, SIGPIPE);
+ g_return_if_fail (main_loop != NULL);
- /* Block all signals of interest. */
- status = pthread_sigmask (SIG_BLOCK, &signal_set, &old_sig_mask);
- if (status != 0) {
- fprintf (stderr, _("Failed to set signal mask: %d"), status);
- return FALSE;
- }
- /* Save original mask so that we could use it for child processes. */
- nm_save_original_signal_mask (old_sig_mask);
-
- /* Create the signal handling thread. */
- status = pthread_create (&signal_thread_id, NULL, signal_handling_thread, main_loop);
- if (status != 0) {
- fprintf (stderr, _("Failed to create signal handling thread: %d"), status);
- return FALSE;
- }
+ signal (SIGPIPE, SIG_IGN);
- return TRUE;
+ g_unix_signal_add (SIGHUP, sighup_handler, NULL);
+ g_unix_signal_add (SIGINT, sigint_handler, main_loop);
+ g_unix_signal_add (SIGTERM, sigterm_handler, main_loop);
}
gboolean
diff --git a/src/main-utils.h b/src/main-utils.h
index 472fa5e70e..30c8213ed3 100644
--- a/src/main-utils.h
+++ b/src/main-utils.h
@@ -23,7 +23,7 @@
#include <glib.h>
-gboolean nm_main_utils_setup_signals (GMainLoop *main_loop, gboolean *quit_early_ptr);
+void nm_main_utils_setup_signals (GMainLoop *main_loop);
gboolean nm_main_utils_write_pidfile (const char *pidfile);
diff --git a/src/main.c b/src/main.c
index 0901747989..2d6af01594 100644
--- a/src/main.c
+++ b/src/main.c
@@ -51,7 +51,6 @@
#include "nm-dhcp-manager.h"
#include "nm-logging.h"
#include "nm-config.h"
-#include "nm-posix-signals.h"
#include "nm-session-monitor.h"
#include "nm-dispatcher.h"
#include "nm-settings.h"
@@ -205,7 +204,6 @@ main (int argc, char *argv[])
GError *error = NULL;
gboolean wrote_pidfile = FALSE;
char *bad_domains = NULL;
- gboolean quit_early = FALSE;
GOptionEntry options[] = {
{ "version", 'V', 0, G_OPTION_ARG_NONE, &show_version, N_("Print NetworkManager version and exit"), NULL },
@@ -345,8 +343,7 @@ main (int argc, char *argv[])
_init_nm_debug (nm_config_get_debug (config));
/* Set up unix signal handling - before creating threads, but after daemonizing! */
- if (!nm_main_utils_setup_signals (main_loop, &quit_early))
- exit (1);
+ nm_main_utils_setup_signals (main_loop);
if (g_fatal_warnings) {
GLogLevelFlags fatal_mask;
@@ -442,9 +439,7 @@ main (int argc, char *argv[])
success = TRUE;
- /* Told to quit before getting to the mainloop by the signal handler */
- if (!quit_early)
- g_main_loop_run (main_loop);
+ g_main_loop_run (main_loop);
nm_manager_stop (manager);
diff --git a/src/nm-activation-request.c b/src/nm-activation-request.c
index 30ce751522..2c084b874e 100644
--- a/src/nm-activation-request.c
+++ b/src/nm-activation-request.c
@@ -35,7 +35,6 @@
#include "nm-device.h"
#include "nm-active-connection.h"
#include "nm-settings-connection.h"
-#include "nm-posix-signals.h"
#include "nm-auth-subject.h"
G_DEFINE_TYPE (NMActRequest, nm_act_request, NM_TYPE_ACTIVE_CONNECTION)
@@ -196,16 +195,6 @@ clear_share_rules (NMActRequest *req)
priv->share_rules = NULL;
}
-static void
-share_child_setup (gpointer user_data G_GNUC_UNUSED)
-{
- /* We are in the child process at this point */
- pid_t pid = getpid ();
- setpgid (pid, pid);
-
- nm_unblock_posix_signals (NULL);
-}
-
void
nm_act_request_set_shared (NMActRequest *req, gboolean shared)
{
@@ -243,7 +232,7 @@ nm_act_request_set_shared (NMActRequest *req, gboolean shared)
nm_log_info (LOGD_SHARING, "Executing: %s", cmd);
if (!g_spawn_sync ("/", argv, envp, G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL,
- share_child_setup, NULL, NULL, NULL, &status, &error)) {
+ NULL, NULL, NULL, NULL, &status, &error)) {
nm_log_warn (LOGD_SHARING, "Error executing command: (%d) %s",
error ? error->code : -1,
(error && error->message) ? error->message : "(unknown)");
diff --git a/src/nm-dcb.c b/src/nm-dcb.c
index 6faec5c532..0b18ca7f2b 100644
--- a/src/nm-dcb.c
+++ b/src/nm-dcb.c
@@ -27,7 +27,6 @@
#include "nm-dcb.h"
#include "nm-platform.h"
#include "NetworkManagerUtils.h"
-#include "nm-posix-signals.h"
#include "nm-logging.h"
static const char *helper_names[] = { "dcbtool", "fcoeadm" };
@@ -305,7 +304,7 @@ run_helper (char **argv, guint which, gpointer user_data, GError **error)
nm_log_dbg (LOGD_DCB, "%s", cmdline);
success = g_spawn_sync ("/", argv, NULL, 0 /*G_SPAWN_DEFAULT*/,
- nm_unblock_posix_signals, NULL,
+ NULL, NULL,
&outmsg, &errmsg, &exit_status, error);
/* Log any stderr output */
if (success && WIFEXITED (exit_status) && WEXITSTATUS (exit_status) && (errmsg || outmsg)) {
diff --git a/src/nm-iface-helper.c b/src/nm-iface-helper.c
index 910c804711..2d3768beb6 100644
--- a/src/nm-iface-helper.c
+++ b/src/nm-iface-helper.c
@@ -248,24 +248,16 @@ rdisc_ra_timeout (NMRDisc *rdisc, gpointer user_data)
static gboolean
quit_handler (gpointer user_data)
{
- gboolean *quit_early_ptr = user_data;
-
- *quit_early_ptr = TRUE;
g_main_loop_quit (main_loop);
- return G_SOURCE_CONTINUE;
+ return G_SOURCE_REMOVE;
}
static void
-setup_signals (gboolean *quit_early_ptr)
+setup_signals (void)
{
- sigset_t sigmask;
-
- sigemptyset (&sigmask);
- pthread_sigmask (SIG_SETMASK, &sigmask, NULL);
-
signal (SIGPIPE, SIG_IGN);
- g_unix_signal_add (SIGINT, quit_handler, quit_early_ptr);
- g_unix_signal_add (SIGTERM, quit_handler, quit_early_ptr);
+ g_unix_signal_add (SIGINT, quit_handler, NULL);
+ g_unix_signal_add (SIGTERM, quit_handler, NULL);
}
int
@@ -280,7 +272,6 @@ main (int argc, char *argv[])
GError *error = NULL;
gboolean wrote_pidfile = FALSE;
gs_free char *pidfile = NULL;
- gboolean quit_early = FALSE;
gs_unref_object NMDhcpClient *dhcp4_client = NULL;
gs_unref_object NMRDisc *rdisc = NULL;
GByteArray *hwaddr = NULL;
@@ -375,7 +366,7 @@ main (int argc, char *argv[])
/* Set up unix signal handling - before creating threads, but after daemonizing! */
main_loop = g_main_loop_new (NULL, FALSE);
- setup_signals (&quit_early);
+ setup_signals ();
if (g_fatal_warnings) {
GLogLevelFlags fatal_mask;
@@ -473,8 +464,7 @@ main (int argc, char *argv[])
nm_rdisc_start (rdisc);
}
- if (!quit_early)
- g_main_loop_run (main_loop);
+ g_main_loop_run (main_loop);
g_clear_pointer (&hwaddr, g_byte_array_unref);
diff --git a/src/nm-posix-signals.c b/src/nm-posix-signals.c
deleted file mode 100644
index 22fed83103..0000000000
--- a/src/nm-posix-signals.c
+++ /dev/null
@@ -1,62 +0,0 @@
-/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
-/* NetworkManager -- Network link manager
- *
- * 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
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Copyright (C) 2012 Red Hat, Inc.
- */
-
-#include "config.h"
-
-#include <signal.h>
-
-#include "nm-posix-signals.h"
-
-
-/* Stores the original signal mask of NetworkManager process */
-static sigset_t nm_original_signal_mask;
-
-void
-nm_save_original_signal_mask (sigset_t sig_mask)
-{
- nm_original_signal_mask = sig_mask;
-}
-
-const sigset_t *
-nm_get_original_signal_mask (void)
-{
- return &nm_original_signal_mask;
-}
-
-/*
- * Unblock signals.
- * If a signal set is passed, those signals are unblocked. If user_data is NULL
- * the process' signal mask is set to the saved original mask.
- * Note: This function can be used in g_spawn_* as GSpawnChildSetupFunc()
- * callback.
- */
-void
-nm_unblock_posix_signals (gpointer user_data)
-{
- sigset_t *user_sigset = (sigset_t *) user_data;
-
- if (user_sigset != NULL) {
- pthread_sigmask (SIG_UNBLOCK, user_sigset, NULL);
- } else {
- const sigset_t *orig_sig_mask = nm_get_original_signal_mask ();
- pthread_sigmask (SIG_SETMASK, orig_sig_mask, NULL);
- }
-}
-
diff --git a/src/nm-posix-signals.h b/src/nm-posix-signals.h
deleted file mode 100644
index e2af559bab..0000000000
--- a/src/nm-posix-signals.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
-/* NetworkManager -- Network link manager
- *
- * 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
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Copyright (C) 2012 Red Hat, Inc.
- */
-
-#ifndef __NETWORKMANAGER_POSIX_SIGNALS_H__
-#define __NETWORKMANAGER_POSIX_SIGNALS_H__
-
-#include <glib.h>
-#include <signal.h>
-
-/*
- * This function can be used in g_spawn_* as GSpawnChildSetupFunc()
- * callback.
- */
-void nm_unblock_posix_signals (gpointer user_data);
-
-void nm_save_original_signal_mask (sigset_t sig_mask);
-const sigset_t *nm_get_original_signal_mask (void);
-
-#endif /* __NETWORKMANAGER_POSIX_SIGNALS_H__ */
diff --git a/src/ppp-manager/nm-ppp-manager.c b/src/ppp-manager/nm-ppp-manager.c
index 4fac96dcd2..5d22f52557 100644
--- a/src/ppp-manager/nm-ppp-manager.c
+++ b/src/ppp-manager/nm-ppp-manager.c
@@ -46,7 +46,6 @@
#include "nm-ppp-manager.h"
#include "nm-dbus-manager.h"
#include "nm-logging.h"
-#include "nm-posix-signals.h"
#include "nm-platform.h"
#include "nm-core-internal.h"
@@ -1027,20 +1026,6 @@ create_pppd_cmd_line (NMPPPManager *self,
}
static void
-pppd_child_setup (gpointer user_data G_GNUC_UNUSED)
-{
- /* We are in the child process at this point */
- pid_t pid = getpid ();
- setpgid (pid, pid);
-
- /*
- * We blocked signals in main(). We need to restore original signal
- * mask for pppd here so that it can receive signals.
- */
- nm_unblock_posix_signals (NULL);
-}
-
-static void
pppoe_fill_defaults (NMSettingPpp *setting)
{
if (!nm_setting_ppp_get_mtu (setting))
@@ -1138,8 +1123,8 @@ nm_ppp_manager_start (NMPPPManager *manager,
priv->pid = 0;
if (!g_spawn_async (NULL, (char **) ppp_cmd->array->pdata, NULL,
G_SPAWN_DO_NOT_REAP_CHILD,
- pppd_child_setup,
- NULL, &priv->pid, err)) {
+ nm_utils_setpgid, NULL,
+ &priv->pid, err)) {
goto out;
}
diff --git a/src/settings/plugins/ibft/reader.c b/src/settings/plugins/ibft/reader.c
index 066a79f25e..0d77871f42 100644
--- a/src/settings/plugins/ibft/reader.c
+++ b/src/settings/plugins/ibft/reader.c
@@ -36,7 +36,6 @@
#include "nm-core-internal.h"
#include "nm-platform.h"
-#include "nm-posix-signals.h"
#include "NetworkManagerUtils.h"
#include "nm-logging.h"
@@ -44,22 +43,6 @@
#define PARSE_WARNING(msg...) nm_log_warn (LOGD_SETTINGS, " " msg)
-static void
-iscsiadm_child_setup (gpointer user_data G_GNUC_UNUSED)
-{
- /* We are in the child process here; set a different process group to
- * ensure signal isolation between child and parent.
- */
- pid_t pid = getpid ();
- setpgid (pid, pid);
-
- /*
- * We blocked signals in main(). We need to restore original signal
- * mask for iscsiadm here so that it can receive signals.
- */
- nm_unblock_posix_signals (NULL);
-}
-
/* Removes trailing whitespace and whitespace before and immediately after the '=' */
static char *
remove_most_whitespace (const char *src)
@@ -126,7 +109,7 @@ read_ibft_blocks (const char *iscsiadm_path,
g_return_val_if_fail (out_blocks != NULL && *out_blocks == NULL, FALSE);
if (!g_spawn_sync ("/", (char **) argv, (char **) envp, 0,
- iscsiadm_child_setup, NULL, &out, &err, &status, error))
+ NULL, NULL, &out, &err, &status, error))
goto done;
if (!WIFEXITED (status)) {
diff --git a/src/settings/plugins/ifcfg-rh/reader.c b/src/settings/plugins/ifcfg-rh/reader.c
index da10afdc4a..2ce9e05217 100644
--- a/src/settings/plugins/ifcfg-rh/reader.c
+++ b/src/settings/plugins/ifcfg-rh/reader.c
@@ -53,7 +53,6 @@
#include <nm-utils.h>
#include "nm-platform.h"
-#include "nm-posix-signals.h"
#include "NetworkManagerUtils.h"
#include "nm-logging.h"
diff --git a/src/vpn-manager/nm-vpn-service.c b/src/vpn-manager/nm-vpn-service.c
index b46d13ecf7..77220dd2ea 100644
--- a/src/vpn-manager/nm-vpn-service.c
+++ b/src/vpn-manager/nm-vpn-service.c
@@ -31,7 +31,6 @@
#include "nm-vpn-service.h"
#include "nm-dbus-manager.h"
#include "nm-logging.h"
-#include "nm-posix-signals.h"
#include "nm-vpn-manager.h"
#include "nm-glib-compat.h"
@@ -167,20 +166,6 @@ nm_vpn_service_stop_connections (NMVpnService *service,
g_clear_pointer (&priv->pending, g_slist_free);
}
-static void
-_daemon_setup (gpointer user_data G_GNUC_UNUSED)
-{
- /* We are in the child process at this point */
- pid_t pid = getpid ();
- setpgid (pid, pid);
-
- /*
- * We blocked signals in main(). We need to restore original signal
- * mask for VPN service here so that it can receive signals.
- */
- nm_unblock_posix_signals (NULL);
-}
-
static gboolean
_daemon_exec_timeout (gpointer data)
{
@@ -207,7 +192,7 @@ nm_vpn_service_daemon_exec (NMVpnService *service, GError **error)
vpn_argv[0] = priv->program;
vpn_argv[1] = NULL;
- success = g_spawn_async (NULL, vpn_argv, NULL, 0, _daemon_setup, NULL, &pid, &spawn_error);
+ success = g_spawn_async (NULL, vpn_argv, NULL, 0, nm_utils_setpgid, NULL, &pid, &spawn_error);
if (success) {
nm_log_info (LOGD_VPN, "VPN service '%s' started (%s), PID %ld",
priv->name, priv->dbus_service, (long int) pid);