core: use nm_io_fcntl_setfl_update_nonblock() helper

This commit is contained in:
Thomas Haller
2023-04-03 17:52:37 +02:00
parent f4943e07f1
commit ce414933a7
2 changed files with 5 additions and 14 deletions

View File

@@ -5090,7 +5090,6 @@ nm_utils_spawn_helper(const char *const *args,
gs_free_error GError *error = NULL; gs_free_error GError *error = NULL;
gs_free char *commands = NULL; gs_free char *commands = NULL;
HelperInfo *info; HelperInfo *info;
int fd_flags;
const char *const *arg; const char *const *arg;
GMainContext *context; GMainContext *context;
gsize n; gsize n;
@@ -5162,13 +5161,9 @@ nm_utils_spawn_helper(const char *const *args,
nm_g_timeout_source_new_seconds(20, G_PRIORITY_DEFAULT, helper_timeout, info, NULL); nm_g_timeout_source_new_seconds(20, G_PRIORITY_DEFAULT, helper_timeout, info, NULL);
g_source_attach(info->timeout_source, context); g_source_attach(info->timeout_source, context);
/* Set file descriptors as non-blocking */ nm_io_fcntl_setfl_update_nonblock(info->child_stdin);
fd_flags = fcntl(info->child_stdin, F_GETFL, 0); nm_io_fcntl_setfl_update_nonblock(info->child_stdout);
fcntl(info->child_stdin, F_SETFL, fd_flags | O_NONBLOCK); nm_io_fcntl_setfl_update_nonblock(info->child_stderr);
fd_flags = fcntl(info->child_stdout, F_GETFL, 0);
fcntl(info->child_stdout, F_SETFL, fd_flags | O_NONBLOCK);
fd_flags = fcntl(info->child_stderr, F_GETFL, 0);
fcntl(info->child_stderr, F_SETFL, fd_flags | O_NONBLOCK);
/* Watch process stdin */ /* Watch process stdin */
for (n = 1, arg = args; *arg; arg++) for (n = 1, arg = args; *arg; arg++)

View File

@@ -499,7 +499,6 @@ out:
static void static void
begin_authentication(AuthRequest *request) begin_authentication(AuthRequest *request)
{ {
int fd_flags;
const char *helper_argv[] = { const char *helper_argv[] = {
POLKIT_AGENT_HELPER_1_PATH, POLKIT_AGENT_HELPER_1_PATH,
request->username, request->username,
@@ -534,11 +533,8 @@ begin_authentication(AuthRequest *request)
return; return;
} }
fd_flags = fcntl(request->child_stdin, F_GETFL, 0); nm_io_fcntl_setfl_update_nonblock(request->child_stdin);
fcntl(request->child_stdin, F_SETFL, fd_flags | O_NONBLOCK); nm_io_fcntl_setfl_update_nonblock(request->child_stdout);
fd_flags = fcntl(request->child_stdout, F_GETFL, 0);
fcntl(request->child_stdout, F_SETFL, fd_flags | O_NONBLOCK);
request->child_stdout_watch_source = nm_g_unix_fd_source_new(request->child_stdout, request->child_stdout_watch_source = nm_g_unix_fd_source_new(request->child_stdout,
G_IO_IN | G_IO_ERR | G_IO_HUP, G_IO_IN | G_IO_ERR | G_IO_HUP,