mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-09 12:25:48 +01:00
gspawn: Simplify set_cloexec
The copy of this function that moved to glib-unix.c still needs to implement the fdwalk-style interface, but this copy does not, allowing us to turn it into a very simple syscall wrapper. Its remaining callers never check for errors, and it never failed anyway, so remove the returned value. Signed-off-by: Simon McVittie <smcv@collabora.com>
This commit is contained in:
parent
69c1a05ede
commit
a7d5a6b69a
@ -1194,13 +1194,10 @@ write_err_and_exit (gint fd, gint msg)
|
|||||||
|
|
||||||
/* This function is called between fork() and exec() and hence must be
|
/* This function is called between fork() and exec() and hence must be
|
||||||
* async-signal-safe (see signal-safety(7)). */
|
* async-signal-safe (see signal-safety(7)). */
|
||||||
static int
|
static void
|
||||||
set_cloexec (void *data, gint fd)
|
set_cloexec (int fd)
|
||||||
{
|
{
|
||||||
if (fd >= GPOINTER_TO_INT (data))
|
fcntl (fd, F_SETFD, FD_CLOEXEC);
|
||||||
fcntl (fd, F_SETFD, FD_CLOEXEC);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This function is called between fork() and exec() and hence must be
|
/* This function is called between fork() and exec() and hence must be
|
||||||
@ -1396,7 +1393,7 @@ do_exec (gint child_err_report_fd,
|
|||||||
write_err_and_exit (child_err_report_fd,
|
write_err_and_exit (child_err_report_fd,
|
||||||
CHILD_DUPFD_FAILED);
|
CHILD_DUPFD_FAILED);
|
||||||
|
|
||||||
set_cloexec (GINT_TO_POINTER(0), stdin_fd);
|
set_cloexec (stdin_fd);
|
||||||
}
|
}
|
||||||
else if (!child_inherits_stdin)
|
else if (!child_inherits_stdin)
|
||||||
{
|
{
|
||||||
@ -1434,7 +1431,7 @@ do_exec (gint child_err_report_fd,
|
|||||||
write_err_and_exit (child_err_report_fd,
|
write_err_and_exit (child_err_report_fd,
|
||||||
CHILD_DUPFD_FAILED);
|
CHILD_DUPFD_FAILED);
|
||||||
|
|
||||||
set_cloexec (GINT_TO_POINTER(0), stdout_fd);
|
set_cloexec (stdout_fd);
|
||||||
}
|
}
|
||||||
else if (stdout_to_null)
|
else if (stdout_to_null)
|
||||||
{
|
{
|
||||||
@ -1466,7 +1463,7 @@ do_exec (gint child_err_report_fd,
|
|||||||
write_err_and_exit (child_err_report_fd,
|
write_err_and_exit (child_err_report_fd,
|
||||||
CHILD_DUPFD_FAILED);
|
CHILD_DUPFD_FAILED);
|
||||||
|
|
||||||
set_cloexec (GINT_TO_POINTER(0), stderr_fd);
|
set_cloexec (stderr_fd);
|
||||||
}
|
}
|
||||||
else if (stderr_to_null)
|
else if (stderr_to_null)
|
||||||
{
|
{
|
||||||
@ -1491,7 +1488,7 @@ do_exec (gint child_err_report_fd,
|
|||||||
{
|
{
|
||||||
if (safe_dup2 (child_err_report_fd, 3) < 0)
|
if (safe_dup2 (child_err_report_fd, 3) < 0)
|
||||||
write_err_and_exit (child_err_report_fd, CHILD_DUPFD_FAILED);
|
write_err_and_exit (child_err_report_fd, CHILD_DUPFD_FAILED);
|
||||||
set_cloexec (GINT_TO_POINTER (0), 3);
|
set_cloexec (3);
|
||||||
if (g_closefrom (4) < 0)
|
if (g_closefrom (4) < 0)
|
||||||
write_err_and_exit (child_err_report_fd, CHILD_CLOSE_FAILED);
|
write_err_and_exit (child_err_report_fd, CHILD_CLOSE_FAILED);
|
||||||
child_err_report_fd = 3;
|
child_err_report_fd = 3;
|
||||||
@ -1505,7 +1502,7 @@ do_exec (gint child_err_report_fd,
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* We need to do child_err_report_fd anyway */
|
/* We need to do child_err_report_fd anyway */
|
||||||
set_cloexec (GINT_TO_POINTER (0), child_err_report_fd);
|
set_cloexec (child_err_report_fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user