1999-09-18 Roland McGrath <roland@baalperazim.frob.com>

* sysdeps/mach/hurd/wait4.c (__wait4): When proc_wait returns EAGAIN,
	return zero to indicate no children died yet (assuming WNOHANG).

	* sysdeps/mach/hurd/setsid.c: #include <hurd/fd.h>.

1999-09-17  Roland McGrath  <roland@baalperazim.frob.com>

	* hurd/port2fd.c (_hurd_port2fd): Never change CTTYID port.

	* sysdeps/mach/hurd/setsid.c (__setsid): Fix return type -> pid_t.
	Return _hurd_pgrp instead of 0.
This commit is contained in:
Roland McGrath 1999-09-19 20:46:22 +00:00
parent 55ffcab7b6
commit 50b076f4dd
4 changed files with 79 additions and 51 deletions

View File

@ -1,3 +1,17 @@
1999-09-18 Roland McGrath <roland@baalperazim.frob.com>
* sysdeps/mach/hurd/wait4.c (__wait4): When proc_wait returns EAGAIN,
return zero to indicate no children died yet (assuming WNOHANG).
* sysdeps/mach/hurd/setsid.c: #include <hurd/fd.h>.
1999-09-17 Roland McGrath <roland@baalperazim.frob.com>
* hurd/port2fd.c (_hurd_port2fd): Never change CTTYID port.
* sysdeps/mach/hurd/setsid.c (__setsid): Fix return type -> pid_t.
Return _hurd_pgrp instead of 0.
1999-09-19 Roland McGrath <roland@baalperazim.frob.com>
* sysdeps/mach/hurd/brk.c (_hurd_set_brk): Deallocate and reallocate

View File

@ -27,46 +27,34 @@
D should be locked, and will not be unlocked. */
void
_hurd_port2fd (struct hurd_fd *d, io_t port, int flags)
_hurd_port2fd (struct hurd_fd *d, io_t dport, int flags)
{
io_t ctty;
mach_port_t cttyid;
int is_ctty = !(flags & O_IGNORE_CTTY) && ! __term_getctty (port, &cttyid);
io_t ctty = MACH_PORT_NULL;
if (is_ctty)
{
/* This port is capable of being a controlling tty.
Is it ours? */
struct hurd_port *const id = &_hurd_ports[INIT_PORT_CTTYID];
__spin_lock (&id->lock);
if (id->port == MACH_PORT_NULL)
/* We have no controlling tty, so make this one it. */
_hurd_port_locked_set (id, cttyid);
else
{
if (cttyid != id->port)
/* We have a controlling tty and this is not it. */
is_ctty = 0;
/* Either we don't want CTTYID, or ID->port already is it.
So we don't need to change ID->port, and we can release
the reference to CTTYID. */
__spin_unlock (&id->lock);
__mach_port_deallocate (__mach_task_self (), cttyid);
}
}
if (!is_ctty || __term_open_ctty (port, _hurd_pid, _hurd_pgrp, &ctty) != 0)
/* XXX if IS_CTTY, then this port is our ctty, but we are
not doing ctty style i/o because term_become_ctty barfed.
What to do? */
/* No ctty magic happening here. */
ctty = MACH_PORT_NULL;
if (!(flags & O_IGNORE_CTTY))
__USEPORT (CTTYID,
({
if (port != MACH_PORT_NULL && /* Do we have a ctty? */
! __term_getctty (dport, &cttyid)) /* Could this be it? */
{
__mach_port_deallocate (__mach_task_self (), cttyid);
/* This port is capable of being a controlling tty.
Is it ours? */
if (cttyid == port)
__term_open_ctty (dport, _hurd_pid, _hurd_pgrp, &ctty);
/* XXX if this port is our ctty, but we are not doing
ctty style i/o because term_become_ctty barfed,
what to do? */
}
0;
}));
/* Install PORT in the descriptor cell, leaving it locked. */
{
mach_port_t old
= _hurd_userlink_clear (&d->port.users) ? d->port.port : MACH_PORT_NULL;
d->port.port = port;
d->port.port = dport;
d->flags = 0;
if (old != MACH_PORT_NULL)
__mach_port_deallocate (__mach_task_self (), old);

View File

@ -1,4 +1,4 @@
/* Copyright (C) 1993, 1994, 1995, 1997 Free Software Foundation, Inc.
/* Copyright (C) 1993,94,95,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
@ -20,38 +20,51 @@
#include <unistd.h>
#include <hurd.h>
#include <hurd/port.h>
#include <hurd/fd.h>
/* Create a new session with the calling process as its leader.
The process group IDs of the session and the calling process
are set to the process ID of the calling process, which is returned. */
int
__setsid ()
pid_t
__setsid (void)
{
error_t err;
unsigned int stamp;
HURD_CRITICAL_BEGIN;
__mutex_lock (&_hurd_dtable_lock);
stamp = _hurd_pids_changed_stamp; /* Atomic fetch. */
/* Tell the proc server we want to start a new session. */
if (err = __USEPORT (PROC, __proc_setsid (port)))
return __hurd_fail (err);
err = __USEPORT (PROC, __proc_setsid (port));
if (!err)
/* Punt our current ctty. We hold the dtable lock from before the
proc_setsid call through clearing the cttyid port so that we can be
sure that it's been cleared by the time the signal thread attempts
to re-ctty the dtable in response to the pgrp change notification. */
_hurd_port_set (&_hurd_ports[INIT_PORT_CTTYID], MACH_PORT_NULL);
/* Punt our current ctty. */
_hurd_setcttyid (MACH_PORT_NULL);
__mutex_unlock (&_hurd_dtable_lock);
/* Synchronize with the signal thread to make sure we have
received and processed proc_newids before returning to the user. */
while (_hurd_pids_changed_stamp == stamp)
{
if (!err)
/* Synchronize with the signal thread to make sure we have
received and processed proc_newids before returning to the user.
This both updates _hurd_pgrp, and
*/
while (_hurd_pids_changed_stamp == stamp)
{
#ifdef noteven
/* XXX we have no need for a mutex, but cthreads demands one. */
__condition_wait (&_hurd_pids_changed_sync, NULL);
/* XXX we have no need for a mutex, but cthreads demands one. */
__condition_wait (&_hurd_pids_changed_sync, NULL);
#else
__swtch_pri(0);
__swtch_pri (0);
#endif
}
}
return 0;
HURD_CRITICAL_END;
return err ? __hurd_fail (err) : _hurd_pgrp;
}
weak_alias (__setsid, setsid)

View File

@ -1,4 +1,4 @@
/* Copyright (C) 1993, 94, 95, 96, 97, 98 Free Software Foundation, Inc.
/* Copyright (C) 1993,94,95,96,97,98,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
@ -35,8 +35,21 @@ __wait4 (pid_t pid, __WAIT_STATUS_DEFN stat_loc, int options,
err = __USEPORT (PROC, __proc_wait (port, pid, options,
stat_loc ?: &dummy, &sigcode,
usage ?: &ignored, &dead));
return err ? (pid_t) __hurd_fail (err) : dead;
switch (err)
{
case 0: /* Got a child. */
return dead;
case EAGAIN:
/* The RPC returns this error when the WNOHANG flag is set and no
selected children are dead (but some are living). In that
situation, our return value is zero. (The RPC can't return zero
for DEAD without also returning some garbage for the other out
parameters, so an error return is much more natural here. Hence
the difference between the RPC and the POSIX.1 interface. */
return (pid_t) 0;
default:
return (pid_t) __hurd_fail (err);
}
}
weak_alias (__wait4, wait4)