hurdpid.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /* Copyright (C) 1991-2026 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, see
  13. <https://www.gnu.org/licenses/>. */
  14. #include <hurd.h>
  15. #include <lowlevellock.h>
  16. #include "set-hooks.h"
  17. pid_t _hurd_pid, _hurd_ppid, _hurd_pgrp;
  18. int _hurd_orphaned;
  19. static void attribute_used_retain
  20. init_pids (void)
  21. {
  22. __USEPORT (PROC,
  23. ({
  24. __proc_getpids (port, &_hurd_pid, &_hurd_ppid, &_hurd_orphaned);
  25. __proc_getpgrp (port, _hurd_pid, &_hurd_pgrp);
  26. }));
  27. }
  28. SET_RELHOOK (_hurd_proc_subinit, init_pids);
  29. #include <hurd/msg_server.h>
  30. #include "set-hooks.h"
  31. DEFINE_HOOK (_hurd_pgrp_changed_hook, (pid_t));
  32. /* These let user threads synchronize with an operation which changes ids. */
  33. unsigned int _hurd_pids_changed_stamp;
  34. kern_return_t
  35. _S_msg_proc_newids (mach_port_t me,
  36. task_t task,
  37. pid_t ppid, pid_t pgrp, int orphaned)
  38. {
  39. int pgrp_changed;
  40. if (task != __mach_task_self ())
  41. return EPERM;
  42. __mach_port_deallocate (__mach_task_self (), task);
  43. pgrp_changed = pgrp != _hurd_pgrp;
  44. _hurd_ppid = ppid;
  45. _hurd_pgrp = pgrp;
  46. _hurd_orphaned = orphaned;
  47. if (pgrp_changed)
  48. /* Run things that want notification of a pgrp change. */
  49. RUN_HOOK (_hurd_pgrp_changed_hook, (pgrp));
  50. /* Notify any waiting user threads that the id change as been completed. */
  51. ++_hurd_pids_changed_stamp;
  52. lll_wake (_hurd_pids_changed_stamp, GSYNC_BROADCAST);
  53. return 0;
  54. }