glib/win32: replace reopen_noninherited()

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
This commit is contained in:
Marc-André Lureau 2022-04-07 17:56:01 +04:00
parent c984db650f
commit c43472060b
2 changed files with 15 additions and 18 deletions

View File

@ -39,6 +39,7 @@
#include "glib.h"
#define GSPAWN_HELPER
#include "gspawn-win32.c" /* For shared definitions */
#include "glib/glib-private.h"
static void
@ -295,7 +296,8 @@ main (int ignored_argc, char **ignored_argv)
/* GUI application do not necessarily have a stderr */
if (_fileno (stderr) == 2)
{
saved_stderr_fd = reopen_noninherited (dup (2), _O_WRONLY);
saved_stderr_fd = GLIB_PRIVATE_CALL (g_win32_reopen_noninherited) (
dup (2), _O_WRONLY, NULL);
if (saved_stderr_fd == -1)
write_err_and_exit (child_err_report_fd, CHILD_DUP_FAILED);
}
@ -403,8 +405,10 @@ main (int ignored_argc, char **ignored_argv)
/* We don't want our child to inherit the error report and
* helper sync fds.
*/
child_err_report_fd = reopen_noninherited (child_err_report_fd, _O_WRONLY);
helper_sync_fd = reopen_noninherited (helper_sync_fd, _O_RDONLY);
child_err_report_fd = GLIB_PRIVATE_CALL (g_win32_reopen_noninherited) (
child_err_report_fd, _O_WRONLY, NULL);
helper_sync_fd = GLIB_PRIVATE_CALL (g_win32_reopen_noninherited) (
helper_sync_fd, _O_RDONLY, NULL);
if (helper_sync_fd == -1)
write_err_and_exit (child_err_report_fd, CHILD_DUP_FAILED);

View File

@ -107,19 +107,6 @@ enum {
ARG_COUNT = ARG_PROGRAM
};
static int
reopen_noninherited (int fd,
int mode)
{
HANDLE filehandle;
DuplicateHandle (GetCurrentProcess (), (LPHANDLE) _get_osfhandle (fd),
GetCurrentProcess (), &filehandle,
0, FALSE, DUPLICATE_SAME_ACCESS);
close (fd);
return _open_osfhandle ((gintptr) filehandle, mode | _O_NOINHERIT);
}
#ifndef GSPAWN_HELPER
#ifdef _WIN64
@ -684,7 +671,10 @@ fork_exec (gint *exit_status,
* helper process, and the started actual user process. As such that
* shouldn't harm, but it is unnecessary.
*/
child_err_report_pipe[0] = reopen_noninherited (child_err_report_pipe[0], _O_RDONLY);
child_err_report_pipe[0] = g_win32_reopen_noninherited (
child_err_report_pipe[0], _O_RDONLY, error);
if (child_err_report_pipe[0] == -1)
goto cleanup_and_fail;
if (flags & G_SPAWN_FILE_AND_ARGV_ZERO)
{
@ -703,7 +693,10 @@ fork_exec (gint *exit_status,
* process won't read but won't get any EOF either, as it has the
* write end open itself.
*/
helper_sync_pipe[1] = reopen_noninherited (helper_sync_pipe[1], _O_WRONLY);
helper_sync_pipe[1] = g_win32_reopen_noninherited (
helper_sync_pipe[1], _O_WRONLY, error);
if (helper_sync_pipe[1] == -1)
goto cleanup_and_fail;
if (stdin_fd != -1)
{