mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-06-02 02:40:07 +02:00
gspawn: use g_close()
g_close() now is async-signal-safe, as long as we don't request a GError and pass a valid file descriptor. Update "gspawn.c" to drop its safe_close() function and use g_close() instead.
This commit is contained in:
parent
3ed7f4d1ed
commit
d6790aecca
@ -162,8 +162,6 @@ extern char **environ;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
static void safe_close (gint fd);
|
|
||||||
|
|
||||||
static gint g_execute (const gchar *file,
|
static gint g_execute (const gchar *file,
|
||||||
gchar **argv,
|
gchar **argv,
|
||||||
gchar **argv_buffer,
|
gchar **argv_buffer,
|
||||||
@ -267,12 +265,10 @@ close_and_invalidate (gint *fd)
|
|||||||
{
|
{
|
||||||
if (*fd < 0)
|
if (*fd < 0)
|
||||||
return;
|
return;
|
||||||
else
|
|
||||||
{
|
g_close (*fd, NULL);
|
||||||
safe_close (*fd);
|
|
||||||
*fd = -1;
|
*fd = -1;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* Some versions of OS X define READ_OK in public headers */
|
/* Some versions of OS X define READ_OK in public headers */
|
||||||
#undef READ_OK
|
#undef READ_OK
|
||||||
@ -1338,32 +1334,13 @@ dupfd_cloexec (int old_fd, int new_fd_min)
|
|||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This function is called between fork() and exec() and hence must be
|
|
||||||
* async-signal-safe (see signal-safety(7)). */
|
|
||||||
static void
|
|
||||||
safe_close (gint fd)
|
|
||||||
{
|
|
||||||
/* Note that this function is (also) called after fork(), so it cannot use
|
|
||||||
* g_close().
|
|
||||||
* Note that it is however called both from the parent and the child
|
|
||||||
* process.
|
|
||||||
*
|
|
||||||
* This function returns no error, because there is nothing what the caller
|
|
||||||
* could do with that information. That is even the case for EINTR. See
|
|
||||||
* g_close() about the specialty of EINTR and why that is correct.
|
|
||||||
* If g_close() ever gets extended to handle EINTR specially, then this place
|
|
||||||
* and all other direct calls to close() need updating.
|
|
||||||
*/
|
|
||||||
close (fd);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 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)). */
|
||||||
G_GNUC_UNUSED static int
|
G_GNUC_UNUSED static int
|
||||||
close_func (void *data, int fd)
|
close_func (void *data, int fd)
|
||||||
{
|
{
|
||||||
if (fd >= GPOINTER_TO_INT (data))
|
if (fd >= GPOINTER_TO_INT (data))
|
||||||
safe_close (fd);
|
g_close (fd, NULL);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -1458,7 +1435,7 @@ safe_fdwalk (int (*cb)(void *data, int fd), void *data)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
safe_close (dir_fd);
|
g_close (dir_fd, NULL);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user