Support binutils 2.20.
[plash-glibc.git] / hurd / hurdid.c
blob36e44ddc20334db0353a76c9fc536a541f003928
1 /* Copyright (C) 1993, 1994, 1995, 1997 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
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.
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.
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. */
19 #include <hurd.h>
20 #include <hurd/id.h>
22 struct hurd_id_data _hurd_id;
25 /* Check that _hurd_id.{gen,aux} are valid and update them if not.
26 Expects _hurd_id.lock to be held and does not release it. */
28 error_t
29 _hurd_check_ids (void)
31 if (! _hurd_id.valid)
33 inline void dealloc (__typeof (_hurd_id.gen) *p)
35 if (p->uids)
37 __vm_deallocate (__mach_task_self (),
38 (vm_address_t) p->uids,
39 p->nuids * sizeof (uid_t));
40 p->uids = NULL;
42 p->nuids = 0;
43 if (p->gids)
45 __vm_deallocate (__mach_task_self (),
46 (vm_address_t) p->gids,
47 p->ngids * sizeof (gid_t));
48 p->gids = NULL;
50 p->ngids = 0;
53 error_t err;
55 dealloc (&_hurd_id.gen);
56 dealloc (&_hurd_id.aux);
58 if (_hurd_id.rid_auth != MACH_PORT_NULL)
60 __mach_port_deallocate (__mach_task_self (), _hurd_id.rid_auth);
61 _hurd_id.rid_auth = MACH_PORT_NULL;
64 if (err = __USEPORT (AUTH, __auth_getids
65 (port,
66 &_hurd_id.gen.uids, &_hurd_id.gen.nuids,
67 &_hurd_id.aux.uids, &_hurd_id.aux.nuids,
68 &_hurd_id.gen.gids, &_hurd_id.gen.ngids,
69 &_hurd_id.aux.gids, &_hurd_id.aux.ngids)))
70 return err;
72 _hurd_id.valid = 1;
75 return 0;
78 static void
79 init_id (void)
81 __mutex_init (&_hurd_id.lock);
82 _hurd_id.valid = 0;
83 _hurd_id.rid_auth = MACH_PORT_NULL;
84 _hurd_id.gen.uids = _hurd_id.aux.uids = NULL;
85 _hurd_id.gen.nuids = _hurd_id.aux.nuids = 0;
86 _hurd_id.gen.gids = _hurd_id.aux.gids = NULL;
87 _hurd_id.gen.ngids = _hurd_id.aux.ngids = 0;
89 (void) &init_id; /* Avoid "defined but not used" warning. */
91 text_set_element (_hurd_preinit_hook, init_id);