hello,

this is again about the _thread_kern_pipe issue raised a few days ago.
thinking about it again, it's nonsense to create any pid-specific
workarounds by creating fake stdio. the solution is straightforward;
patch attached (completely untested).
note, that the open() wrapper (and other calls that create fds) need to
check, if the newly created fd is a stdio one and adjust
_pthread_stdio_flags - at least this is my understanding of this voodoo.
but then, i don't have the faintest idea of what i'm talking about. :)

greetings

ps: flames must be explicitly cc'd to me. >:)

-- 
Hi! I'm a .signature virus! Copy me into your ~/.signature, please!
--
The problem with making software idiot-proof is that idiots are so clever.
Index: uthread_init.c
===================================================================
RCS file: /home/ncvs/src/lib/libc_r/uthread/uthread_init.c,v
retrieving revision 1.38
diff -u -r1.38 uthread_init.c
--- uthread_init.c      19 Mar 2002 22:58:56 -0000      1.38
+++ uthread_init.c      20 Apr 2002 22:42:19 -0000
@@ -173,31 +173,6 @@
        if ((references[0] == NULL) || (libgcc_references[0] == NULL))
                PANIC("Failed loading mandatory references in _thread_init");
 
-       /*
-        * Check for the special case of this process running as
-        * or in place of init as pid = 1:
-        */
-       if (getpid() == 1) {
-               /*
-                * Setup a new session for this process which is
-                * assumed to be running as root.
-                */
-               if (setsid() == -1)
-                       PANIC("Can't set session ID");
-               if (revoke(_PATH_CONSOLE) != 0)
-                       PANIC("Can't revoke console");
-               if ((fd = __sys_open(_PATH_CONSOLE, O_RDWR)) < 0)
-                       PANIC("Can't open console");
-               if (setlogin("root") == -1)
-                       PANIC("Can't set login to root");
-               if (__sys_ioctl(fd,TIOCSCTTY, (char *) NULL) == -1)
-                       PANIC("Can't set controlling terminal");
-               if (__sys_dup2(fd,0) == -1 ||
-                   __sys_dup2(fd,1) == -1 ||
-                   __sys_dup2(fd,2) == -1)
-                       PANIC("Can't dup2");
-       }
-
        /* Get the standard I/O flags before messing with them : */
        for (i = 0; i < 3; i++)
                if (((_pthread_stdio_flags[i] =
@@ -213,6 +188,16 @@
                /* Cannot create pipe, so abort: */
                PANIC("Cannot create kernel pipe");
        }
+       /*
+        * Make sure the pipe does not get in the way of stdio:
+        */
+       for (i = 0; i < 2; i++)
+               if (_thread_kern_pipe[i] < 3) {
+                       if ((fd = __sys_fcntl(_thread_kern_pipe[i], F_DUPFD, 3)) == -1)
+                               PANIC("Cannot create kernel pipe");
+                       __sys_close(_thread_kern_pipe[i]);
+                       _thread_kern_pipe[i] = fd;
+               }
        /* Get the flags for the read pipe: */
        else if ((flags = __sys_fcntl(_thread_kern_pipe[0], F_GETFL, NULL)) == -1) {
                /* Abort this application: */

Reply via email to