mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-12 15:36:17 +01:00
Merge branch 'valgrind-fd-fun' into 'main'
gspawn: Ignore invalid FDs when using safe_fdwalk() See merge request GNOME/glib!3076
This commit is contained in:
commit
78d0ac4237
@ -1343,21 +1343,6 @@ dupfd_cloexec (int old_fd, int new_fd_min)
|
|||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* fdwalk()-compatible callback to close a valid fd.
|
|
||||||
* It is an error to pass an invalid fd (causing EBADF) to this function.
|
|
||||||
*
|
|
||||||
* This function is called between fork() and exec() and hence must be
|
|
||||||
* async-signal-safe (see signal-safety(7)).
|
|
||||||
*/
|
|
||||||
G_GNUC_UNUSED static int
|
|
||||||
close_func (void *data, int fd)
|
|
||||||
{
|
|
||||||
if (fd >= GPOINTER_TO_INT (data))
|
|
||||||
g_close (fd, NULL);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* fdwalk()-compatible callback to close a fd for non-compliant
|
/* fdwalk()-compatible callback to close a fd for non-compliant
|
||||||
* implementations of fdwalk() that potentially pass already
|
* implementations of fdwalk() that potentially pass already
|
||||||
* closed fds.
|
* closed fds.
|
||||||
@ -1427,6 +1412,8 @@ filename_to_fd (const char *p)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static int safe_fdwalk_with_invalid_fds (int (*cb)(void *data, int fd), void *data);
|
||||||
|
|
||||||
/* 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 int
|
||||||
@ -1508,8 +1495,7 @@ safe_fdwalk (int (*cb)(void *data, int fd), void *data)
|
|||||||
return res;
|
return res;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
errno = ENOSYS;
|
return safe_fdwalk_with_invalid_fds (cb, data);
|
||||||
return -1;
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1620,9 +1606,6 @@ safe_fdwalk_set_cloexec (int lowfd)
|
|||||||
|
|
||||||
ret = safe_fdwalk (set_cloexec, GINT_TO_POINTER (lowfd));
|
ret = safe_fdwalk (set_cloexec, GINT_TO_POINTER (lowfd));
|
||||||
|
|
||||||
if (ret < 0 && errno == ENOSYS)
|
|
||||||
ret = safe_fdwalk_with_invalid_fds (set_cloexec, GINT_TO_POINTER (lowfd));
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1678,10 +1661,7 @@ safe_closefrom (int lowfd)
|
|||||||
if (ret == 0 || errno != ENOSYS)
|
if (ret == 0 || errno != ENOSYS)
|
||||||
return ret;
|
return ret;
|
||||||
#endif /* HAVE_CLOSE_RANGE */
|
#endif /* HAVE_CLOSE_RANGE */
|
||||||
ret = safe_fdwalk (close_func, GINT_TO_POINTER (lowfd));
|
ret = safe_fdwalk (close_func_with_invalid_fds, GINT_TO_POINTER (lowfd));
|
||||||
|
|
||||||
if (ret < 0 && errno == ENOSYS)
|
|
||||||
ret = safe_fdwalk_with_invalid_fds (close_func_with_invalid_fds, GINT_TO_POINTER (lowfd));
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user