]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/mach/hurd/setsid.c
Update.
[thirdparty/glibc.git] / sysdeps / mach / hurd / setsid.c
CommitLineData
50b076f4 1/* Copyright (C) 1993,94,95,97,99 Free Software Foundation, Inc.
ebbad4cc 2 This file is part of the GNU C Library.
28f540f4 3
ebbad4cc
UD
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
28f540f4 8
ebbad4cc
UD
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
28f540f4 13
ebbad4cc
UD
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If not,
16 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. */
28f540f4 18
28f540f4
RM
19#include <errno.h>
20#include <unistd.h>
21#include <hurd.h>
22#include <hurd/port.h>
50b076f4 23#include <hurd/fd.h>
28f540f4 24
28f540f4
RM
25/* Create a new session with the calling process as its leader.
26 The process group IDs of the session and the calling process
27 are set to the process ID of the calling process, which is returned. */
50b076f4
RM
28pid_t
29__setsid (void)
28f540f4
RM
30{
31 error_t err;
32 unsigned int stamp;
33
50b076f4
RM
34 HURD_CRITICAL_BEGIN;
35 __mutex_lock (&_hurd_dtable_lock);
36
28f540f4
RM
37 stamp = _hurd_pids_changed_stamp; /* Atomic fetch. */
38
39 /* Tell the proc server we want to start a new session. */
50b076f4 40 err = __USEPORT (PROC, __proc_setsid (port));
72e1a750
RM
41 if (err)
42 __mutex_unlock (&_hurd_dtable_lock);
43 else
44 {
45 /* Punt our current ctty, and update the dtable accordingly. We hold
46 the dtable lock from before the proc_setsid call through clearing
47 the cttyid port and processing the dtable, so that we can be sure
48 that it's all done by the time the signal thread processes the
49 pgrp change notification. */
50 _hurd_locked_install_cttyid (MACH_PORT_NULL);
28f540f4 51
72e1a750
RM
52 /* Synchronize with the signal thread to make sure we have received
53 and processed proc_newids before returning to the user.
54 This is necessary to ensure that _hurd_pgrp (and thus the value
55 returned by `getpgrp ()' in other threads) has been updated before
56 we return. */
57 while (_hurd_pids_changed_stamp == stamp)
58 {
28f540f4 59#ifdef noteven
72e1a750
RM
60 /* XXX we have no need for a mutex, but cthreads demands one. */
61 __condition_wait (&_hurd_pids_changed_sync, NULL);
28f540f4 62#else
72e1a750 63 __swtch_pri (0);
28f540f4 64#endif
72e1a750
RM
65 }
66 }
50b076f4
RM
67
68 HURD_CRITICAL_END;
28f540f4 69
50b076f4 70 return err ? __hurd_fail (err) : _hurd_pgrp;
28f540f4
RM
71}
72
73weak_alias (__setsid, setsid)