Update copyright notices with scripts/update-copyrights
[glibc.git] / hurd / hurdid.c
blobc4086aa07860109d39d53271c43de1407ca54656
1 /* Copyright (C) 1993-2014 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, see
16 <http://www.gnu.org/licenses/>. */
18 #include <hurd.h>
19 #include <hurd/id.h>
21 struct hurd_id_data _hurd_id;
24 /* Check that _hurd_id.{gen,aux} are valid and update them if not.
25 Expects _hurd_id.lock to be held and does not release it. */
27 error_t
28 _hurd_check_ids (void)
30 if (! _hurd_id.valid)
32 inline void dealloc (__typeof (_hurd_id.gen) *p)
34 if (p->uids)
36 __vm_deallocate (__mach_task_self (),
37 (vm_address_t) p->uids,
38 p->nuids * sizeof (uid_t));
39 p->uids = NULL;
41 p->nuids = 0;
42 if (p->gids)
44 __vm_deallocate (__mach_task_self (),
45 (vm_address_t) p->gids,
46 p->ngids * sizeof (gid_t));
47 p->gids = NULL;
49 p->ngids = 0;
52 error_t err;
54 dealloc (&_hurd_id.gen);
55 dealloc (&_hurd_id.aux);
57 if (_hurd_id.rid_auth != MACH_PORT_NULL)
59 __mach_port_deallocate (__mach_task_self (), _hurd_id.rid_auth);
60 _hurd_id.rid_auth = MACH_PORT_NULL;
63 if (err = __USEPORT (AUTH, __auth_getids
64 (port,
65 &_hurd_id.gen.uids, &_hurd_id.gen.nuids,
66 &_hurd_id.aux.uids, &_hurd_id.aux.nuids,
67 &_hurd_id.gen.gids, &_hurd_id.gen.ngids,
68 &_hurd_id.aux.gids, &_hurd_id.aux.ngids)))
69 return err;
71 _hurd_id.valid = 1;
74 return 0;
77 static void
78 init_id (void)
80 __mutex_init (&_hurd_id.lock);
81 _hurd_id.valid = 0;
82 _hurd_id.rid_auth = MACH_PORT_NULL;
83 _hurd_id.gen.uids = _hurd_id.aux.uids = NULL;
84 _hurd_id.gen.nuids = _hurd_id.aux.nuids = 0;
85 _hurd_id.gen.gids = _hurd_id.aux.gids = NULL;
86 _hurd_id.gen.ngids = _hurd_id.aux.ngids = 0;
88 (void) &init_id; /* Avoid "defined but not used" warning. */
90 text_set_element (_hurd_preinit_hook, init_id);