mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-10 17:10:25 +01:00
core: merge branch 'th/waitpid-bgo748885'
https://bugzilla.gnome.org/show_bug.cgi?id=748885
This commit is contained in:
commit
4d4f5fff5c
3 changed files with 27 additions and 23 deletions
|
|
@ -294,9 +294,12 @@ script_timeout_cb (gpointer user_data)
|
|||
|
||||
g_warning ("Script '%s' took too long; killing it.", script->script);
|
||||
|
||||
if (kill (script->pid, 0) == 0)
|
||||
kill (script->pid, SIGKILL);
|
||||
(void) waitpid (script->pid, NULL, 0);
|
||||
kill (script->pid, SIGKILL);
|
||||
again:
|
||||
if (waitpid (script->pid, NULL, 0) == -1) {
|
||||
if (errno == EINTR)
|
||||
goto again;
|
||||
}
|
||||
|
||||
script->error = g_strdup_printf ("Script '%s' timed out.", script->script);
|
||||
script->result = DISPATCH_RESULT_TIMEOUT;
|
||||
|
|
|
|||
|
|
@ -624,13 +624,15 @@ _sleep_duration_convert_ms_to_us (guint32 sleep_duration_msec)
|
|||
* sent unless the child already exited. If the child does not exit within @wait_before_kill_msec milliseconds,
|
||||
* the function will send %SIGKILL and waits for the child indefinitly. If @wait_before_kill_msec is zero, no
|
||||
* %SIGKILL signal will be sent.
|
||||
*
|
||||
* In case of error, errno is preserved to contain the last reason of failure.
|
||||
**/
|
||||
gboolean
|
||||
nm_utils_kill_child_sync (pid_t pid, int sig, guint64 log_domain, const char *log_name,
|
||||
int *child_status, guint32 wait_before_kill_msec,
|
||||
guint32 sleep_duration_msec)
|
||||
{
|
||||
int status = 0, errsv;
|
||||
int status = 0, errsv = 0;
|
||||
pid_t ret;
|
||||
gboolean success = FALSE;
|
||||
gboolean was_waiting = FALSE, send_kill = FALSE;
|
||||
|
|
@ -776,6 +778,7 @@ nm_utils_kill_child_sync (pid_t pid, int sig, guint64 log_domain, const char *lo
|
|||
out:
|
||||
if (child_status)
|
||||
*child_status = success ? status : -1;
|
||||
errno = success ? 0 : errsv;
|
||||
return success;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -254,7 +254,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, NULL,
|
||||
if (!g_spawn_async_with_pipes (NULL, argv, NULL, G_SPAWN_DO_NOT_REAP_CHILD, NULL,
|
||||
NULL, &pid, stdin_fd, NULL, NULL, error))
|
||||
return -1;
|
||||
|
||||
|
|
@ -283,10 +283,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
|
||||
|
|
@ -319,24 +319,22 @@ 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;
|
||||
if (!WIFEXITED (status) || WEXITSTATUS (status) != EXIT_SUCCESS) {
|
||||
g_set_error (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_FAILED,
|
||||
"Error calling netconfig: %s %d",
|
||||
WIFEXITED (status) ? "exited with status" : (WIFSIGNALED (status) ? "exited with signal" : "exited with unknown reason"),
|
||||
WIFEXITED (status) ? WEXITSTATUS (status) : (WIFSIGNALED (status) ? WTERMSIG (status) : status));
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue