[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#45104: setsid() breakage



   Date: Fri, 24 Sep 1999 19:57:19 +0200
   From: Marcus Brinkmann <Marcus.Brinkmann@ruhr-uni-bochum.de>

I believe the appended libc change is necessary.  However this is not
enough to fix screen.  For some perverse reason (probably to work
around a bug on some old BSD systems) screen does a TIOCSTTY ioctl
right after the setsid call in brktty in the generated tty.c file.
This TIOCSTTY should be harmless, since a tty can only be the
controlling terminal for one session, so it fails in the new session
just created by setsid().  However on the Hurd this `one session per
controlling tty'-rule is not implemented.  There actually is an entry
in the TODO file that mentions this.  Unfortunately this is not
something that can easily be fixed, and needs some real thinking first.

So Marcus, you'll probably want to make sure that this TIOCSTTY ioctl
isn't compiled in right now, by adding

   && !defined(__GNU__)

after the

   # if defined(BSD) && defined(TIOCSCTTY)

for example.  With this fix (and undefining HAVE_SETEUID in the
generated config.h) screen seems to be working fine on my system.

Mark


1999-09-25  Mark Kettenis  <kettenis@gnu.org>

	* hurd/dtable.c (rectty_dtable): Renamed from ctty_new_pgrp.  Deal
	with case where we have no controlling tty at all.  This happens
	if the process group change happened as a result of a call to
	setsid.


Index: libc-2.1/hurd/dtable.c
===================================================================
RCS file: /var/cvsroot/libc/hurd/dtable.c,v
retrieving revision 1.1.2.1
diff -u -r1.1.2.1 dtable.c
--- libc-2.1/hurd/dtable.c	1999/07/21 17:59:41	1.1.2.1
+++ libc-2.1/hurd/dtable.c	1999/09/25 20:39:29
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991, 92, 93, 94, 95, 96, 97 Free Software Foundation, Inc.
+/* Copyright (C) 1991,92,93,94,95,96,97,99 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -167,52 +167,54 @@
 text_set_element (_hurd_fork_child_hook, fork_child_dtable);
 
 /* Called when our process group has changed.  */
-
 static void
-ctty_new_pgrp (void)
+rectty_dtable (void)
 {
+  struct hurd_userlink ulink;
+  mach_port_t cttyid;
   int i;
 
   HURD_CRITICAL_BEGIN;
   __mutex_lock (&_hurd_dtable_lock);
 
+  cttyid = _hurd_port_get (&_hurd_ports[INIT_PORT_CTTYID], &ulink);
+
   for (i = 0; i < _hurd_dtablesize; ++i)
     {
       struct hurd_fd *const d = _hurd_dtable[i];
-      struct hurd_userlink ulink, ctty_ulink;
-      io_t port, ctty;
+      mach_port_t newctty;
 
       if (d == NULL)
 	/* Nothing to do for an unused descriptor cell.  */
 	continue;
 
-      port = _hurd_port_get (&d->port, &ulink);
-      ctty = _hurd_port_get (&d->ctty, &ctty_ulink);
-
-      if (ctty != MACH_PORT_NULL)
-	{
-	  /* This fd has a ctty-special port.  We need a new one, to tell
-             the io server of our different process group.  */
-	  io_t new;
-	  if (__term_open_ctty (port, _hurd_pid, _hurd_pgrp, &new))
-	    new = MACH_PORT_NULL;
-	  _hurd_port_set (&d->ctty, new);
-	}
+      if (cttyid == MACH_PORT_NULL)
+	/* We now have no controlling tty at all.  */
+	newctty = MACH_PORT_NULL;
+      else
+	HURD_PORT_USE (&d->port,
+		       ({
+			 if (__term_open_ctty (port, _hurd_pid, _hurd_pgrp,
+					       &newctty))
+			   newctty = MACH_PORT_NULL;
+			 0;
+		       }));
 
-      _hurd_port_free (&d->port, &ulink, port);
-      _hurd_port_free (&d->ctty, &ctty_ulink, ctty);
+      /* Install the new ctty port.  */
+      _hurd_port_set (&d->ctty, newctty);
     }
 
+  _hurd_port_free (&_hurd_ports[INIT_PORT_CTTYID], &ulink, cttyid);
+
   __mutex_unlock (&_hurd_dtable_lock);
   HURD_CRITICAL_END;
 
-  (void) &ctty_new_pgrp;	/* Avoid "defined but not used" warning.  */
+  (void) &rectty_dtable;	/* Avoid "defined but not used" warning.  */
 }
 
-text_set_element (_hurd_pgrp_changed_hook, ctty_new_pgrp);
+text_set_element (_hurd_pgrp_changed_hook, rectty_dtable);
 
 /* Called to reauthenticate the dtable when the auth port changes.  */
-
 static void
 reauth_dtable (void)
 {


Reply to: