Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 21 Apr 2002 00:42:29 +0200
From:      Oswald Buddenhagen <ossi@kde.org>
To:        current@freebsd.org
Subject:   uthread_init.c again
Message-ID:  <20020420224229.GA13290@ugly.homeip.net>

next in thread | raw e-mail | index | archive | help

--liOOAslEiF7prFVr
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

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.

--liOOAslEiF7prFVr
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="uthread_init.c.diff"

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: */

--liOOAslEiF7prFVr--

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020420224229.GA13290>