From 20ff7d9688c1fd56bee9effee135a5f7fe02c83c Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 3 May 2015 13:51:02 +0200 Subject: [PATCH] dns-manager: use nm_utils_kill_child_sync() to wait for netconfig to exit (cherry picked from commit 6b646a1e375261d88a6caebc0b81408dd0eac30c) Conflicts: src/dns-manager/nm-dns-manager.c --- src/dns-manager/nm-dns-manager.c | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/src/dns-manager/nm-dns-manager.c b/src/dns-manager/nm-dns-manager.c index fdcfc6d8a2..e0cbd9741e 100644 --- a/src/dns-manager/nm-dns-manager.c +++ b/src/dns-manager/nm-dns-manager.c @@ -257,7 +257,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, G_SPAWN_DO_NOT_REAP_CHILD, netconfig_child_setup, NULL, &pid, stdin_fd, NULL, NULL, error)) return -1; @@ -286,10 +286,10 @@ dispatch_netconfig (char **searches, char *str; GPid pid; gint fd; - int ret = 1; + int status; pid = run_netconfig (error, &fd); - if (pid < 0) + if (pid <= 0) return FALSE; /* NM is writing already-merged DNS information to netconfig, so it @@ -322,24 +322,15 @@ dispatch_netconfig (char **searches, close (fd); /* Wait until the process exits */ + if (!nm_utils_kill_child_sync (pid, 0, LOGD_DNS, "netconfig", &status, 1000, 0)) { + int errsv = errno; - again: - - if (waitpid (pid, NULL, 0) < 0) { - if (errno == EINTR) - goto again; - else if (errno == ECHILD) { - /* child already exited */ - ret = pid; - } else { - g_set_error (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_FAILED, - "Error waiting for netconfig to exit: %s", - strerror (errno)); - ret = 0; - } + g_set_error (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_FAILED, + "Error waiting for netconfig to exit: %s", + strerror (errsv)); + return FALSE; } - - return ret > 0; + return TRUE; } #endif