Back to index

glibc  2.9
hurdpid.c
Go to the documentation of this file.
00001 /* Copyright (C) 1991, 92, 93, 94, 95, 97 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003 
00004    The GNU C Library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Lesser General Public
00006    License as published by the Free Software Foundation; either
00007    version 2.1 of the License, or (at your option) any later version.
00008 
00009    The GNU C Library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Lesser General Public License for more details.
00013 
00014    You should have received a copy of the GNU Lesser General Public
00015    License along with the GNU C Library; if not, write to the Free
00016    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00017    02111-1307 USA.  */
00018 
00019 #include <hurd.h>
00020 pid_t _hurd_pid, _hurd_ppid, _hurd_pgrp;
00021 int _hurd_orphaned;
00022 
00023 static void
00024 init_pids (void)
00025 {
00026   __USEPORT (PROC,
00027             ({
00028               __proc_getpids (port, &_hurd_pid, &_hurd_ppid, &_hurd_orphaned);
00029               __proc_getpgrp (port, _hurd_pid, &_hurd_pgrp);
00030             }));
00031 
00032   (void) &init_pids;        /* Avoid "defined but not used" warning.  */
00033 }
00034 
00035 text_set_element (_hurd_proc_subinit, init_pids);
00036 
00037 #include <hurd/msg_server.h>
00038 #include "set-hooks.h"
00039 #include <cthreads.h>
00040 
00041 DEFINE_HOOK (_hurd_pgrp_changed_hook, (pid_t));
00042 
00043 /* These let user threads synchronize with an operation which changes ids.  */
00044 unsigned int _hurd_pids_changed_stamp;
00045 struct condition _hurd_pids_changed_sync;
00046 
00047 kern_return_t
00048 _S_msg_proc_newids (mach_port_t me,
00049                   task_t task,
00050                   pid_t ppid, pid_t pgrp, int orphaned)
00051 {
00052   int pgrp_changed;
00053 
00054   if (task != __mach_task_self ())
00055     return EPERM;
00056 
00057   __mach_port_deallocate (__mach_task_self (), task);
00058 
00059   pgrp_changed = pgrp != _hurd_pgrp;
00060   _hurd_ppid = ppid;
00061   _hurd_pgrp = pgrp;
00062   _hurd_orphaned = orphaned;
00063 
00064   if (pgrp_changed)
00065     /* Run things that want notification of a pgrp change.  */
00066     RUN_HOOK (_hurd_pgrp_changed_hook, (pgrp));
00067 
00068   /* Notify any waiting user threads that the id change as been completed.  */
00069   ++_hurd_pids_changed_stamp;
00070 
00071   return 0;
00072 }