Update to LGPL v2.1.
[platform/upstream/glibc.git] / hurd / privports.c
1 /* Copyright (C) 1993,94,97,2001 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
3
4    The GNU C Library is free software; you can redistribute it and/or
5    modify it under the terms of the GNU Lesser General Public
6    License as published by the Free Software Foundation; either
7    version 2.1 of the License, or (at your option) any later version.
8
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    Lesser General Public License for more details.
13
14    You should have received a copy of the GNU Lesser General Public
15    License along with the GNU C Library; if not, write to the Free
16    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17    02111-1307 USA.  */
18
19 #include <hurd.h>
20
21 /* The program might set these if it is the initial task
22    bootstrapped by the microkernel.  */
23
24 mach_port_t _hurd_host_priv, _hurd_device_master;
25
26
27 kern_return_t
28 __get_privileged_ports (host_priv_t *host_priv_ptr,
29                         device_t *device_master_ptr)
30 {
31   if (! _hurd_host_priv)
32     {
33       error_t err;
34
35       if (_hurd_ports)
36         /* We have gotten some initial ports, so perhaps
37            we have a proc server to talk to.  */
38         err = __USEPORT (PROC, __proc_getprivports (port,
39                                                     &_hurd_host_priv,
40                                                     &_hurd_device_master));
41       else
42         return MACH_SEND_INVALID_DEST;
43
44       if (err)
45         return err;
46     }
47
48   if (host_priv_ptr)
49     {
50       __mach_port_mod_refs (mach_task_self (),
51                             _hurd_host_priv, MACH_PORT_RIGHT_SEND, 1);
52       *host_priv_ptr = _hurd_host_priv;
53     }
54   if (device_master_ptr)
55     {
56       __mach_port_mod_refs (mach_task_self (),
57                             _hurd_device_master, MACH_PORT_RIGHT_SEND, 1);
58       *device_master_ptr = _hurd_device_master;
59     }
60   return KERN_SUCCESS;
61 }
62 weak_alias (__get_privileged_ports, get_privileged_ports)