- Add ca905744.patch: Revert "Handling collision between standard i/o file descriptors and newly created ones". The user-visible problem this solves is gnome-keyring-daemon eating 100% CPU. OBS-URL: https://build.opensuse.org/request/show/1032475 OBS-URL: https://build.opensuse.org/package/show/GNOME:Factory/glib2?expand=0&rev=495
119 lines
3.4 KiB
Diff
119 lines
3.4 KiB
Diff
From ca905744dffb844663b5bd6b42f33e2d44f9b4cd Mon Sep 17 00:00:00 2001
|
|
From: Ray Strode <rstrode@redhat.com>
|
|
Date: Fri, 28 Oct 2022 11:21:04 -0400
|
|
Subject: [PATCH] Revert "Handling collision between standard i/o file
|
|
descriptors and newly created ones"
|
|
|
|
g_unix_open_pipe tries to avoid the standard io fd range
|
|
when getting pipe fds. This turns out to be a bad idea because
|
|
certain buggy programs rely on it using that range.
|
|
|
|
This reverts commit d9ba6150909818beb05573f54f26232063492c5b
|
|
and adds a test to ensure we don't inadvertently do it again later.
|
|
|
|
Closes: https://gitlab.gnome.org/GNOME/glib/-/issues/2795
|
|
---
|
|
glib/glib-unix.c | 24 ------------------------
|
|
glib/tests/unix.c | 29 +++++++++++++++++++++++++++++
|
|
2 files changed, 29 insertions(+), 24 deletions(-)
|
|
|
|
diff --git a/glib/glib-unix.c b/glib/glib-unix.c
|
|
index 4710c51168..bc152d7663 100644
|
|
--- a/glib/glib-unix.c
|
|
+++ b/glib/glib-unix.c
|
|
@@ -108,17 +108,6 @@ g_unix_open_pipe (int *fds,
|
|
ecode = pipe2 (fds, pipe2_flags);
|
|
if (ecode == -1 && errno != ENOSYS)
|
|
return g_unix_set_error_from_errno (error, errno);
|
|
- /* Don't reassign pipes to stdin, stdout, stderr if closed meanwhile */
|
|
- else if (fds[0] < 3 || fds[1] < 3)
|
|
- {
|
|
- int old_fds[2] = { fds[0], fds[1] };
|
|
- gboolean result = g_unix_open_pipe (fds, flags, error);
|
|
- close (old_fds[0]);
|
|
- close (old_fds[1]);
|
|
-
|
|
- if (!result)
|
|
- g_unix_set_error_from_errno (error, errno);
|
|
- }
|
|
else if (ecode == 0)
|
|
return TRUE;
|
|
/* Fall through on -ENOSYS, we must be running on an old kernel */
|
|
@@ -127,19 +116,6 @@ g_unix_open_pipe (int *fds,
|
|
ecode = pipe (fds);
|
|
if (ecode == -1)
|
|
return g_unix_set_error_from_errno (error, errno);
|
|
- /* Don't reassign pipes to stdin, stdout, stderr if closed meanwhile */
|
|
- else if (fds[0] < 3 || fds[1] < 3)
|
|
- {
|
|
- int old_fds[2] = { fds[0], fds[1] };
|
|
- gboolean result = g_unix_open_pipe (fds, flags, error);
|
|
- close (old_fds[0]);
|
|
- close (old_fds[1]);
|
|
-
|
|
- if (!result)
|
|
- g_unix_set_error_from_errno (error, errno);
|
|
-
|
|
- return result;
|
|
- }
|
|
|
|
if (flags == 0)
|
|
return TRUE;
|
|
diff --git a/glib/tests/unix.c b/glib/tests/unix.c
|
|
index 2112cab6bf..5dde2b52cc 100644
|
|
--- a/glib/tests/unix.c
|
|
+++ b/glib/tests/unix.c
|
|
@@ -26,6 +26,7 @@
|
|
#include "glib-unix.h"
|
|
#include <string.h>
|
|
#include <pwd.h>
|
|
+#include <unistd.h>
|
|
|
|
static void
|
|
test_pipe (void)
|
|
@@ -52,6 +53,33 @@ test_pipe (void)
|
|
g_assert (g_str_has_prefix (buf, "hello"));
|
|
}
|
|
|
|
+static void
|
|
+test_pipe_stdio_overwrite (void)
|
|
+{
|
|
+ GError *error = NULL;
|
|
+ int pipefd[2], ret;
|
|
+ gboolean res;
|
|
+ int stderr_fd;
|
|
+
|
|
+ stderr_fd = dup (STDERR_FILENO);
|
|
+ g_assert_cmpint (stderr_fd, >, 0);
|
|
+ close (STDERR_FILENO);
|
|
+
|
|
+ res = g_unix_open_pipe (pipefd, FD_CLOEXEC, &error);
|
|
+ g_assert (res);
|
|
+ g_assert_no_error (error);
|
|
+
|
|
+ g_assert_cmpint (pipefd[0], ==, STDERR_FILENO);
|
|
+
|
|
+ close (pipefd[0]);
|
|
+ close (pipefd[1]);
|
|
+
|
|
+ ret = dup2 (stderr_fd, STDERR_FILENO);
|
|
+ g_assert_cmpint (ret, >=, 0);
|
|
+
|
|
+ close (stderr_fd);
|
|
+}
|
|
+
|
|
static void
|
|
test_error (void)
|
|
{
|
|
@@ -337,6 +365,7 @@ main (int argc,
|
|
g_test_init (&argc, &argv, NULL);
|
|
|
|
g_test_add_func ("/glib-unix/pipe", test_pipe);
|
|
+ g_test_add_func ("/glib-unix/pipe-stdio-overwrite", test_pipe_stdio_overwrite);
|
|
g_test_add_func ("/glib-unix/error", test_error);
|
|
g_test_add_func ("/glib-unix/nonblocking", test_nonblocking);
|
|
g_test_add_func ("/glib-unix/sighup", test_sighup);
|
|
--
|
|
GitLab
|
|
|