summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Bugaev <bugaevc@gmail.com>2021-05-26 16:40:47 +0300
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2022-08-10 22:12:30 +0200
commit111e1a54234613eb5055903cffa20d1f1e6a659e (patch)
tree9613e1deb5199ee8299bf668e997a2ed91ecfe0b
parent2c6c2b011eda70abac23c6ff9702917485f9ed3b (diff)
proc: Use ports_request_dead_name_notification ()
-rw-r--r--proc/host.c12
-rw-r--r--proc/mgt.c10
-rw-r--r--proc/notify.c39
3 files changed, 17 insertions, 44 deletions
diff --git a/proc/host.c b/proc/host.c
index 991d1335..4cfd710e 100644
--- a/proc/host.c
+++ b/proc/host.c
@@ -184,9 +184,9 @@ S_proc_execdata_notify (struct proc *p,
mach_port_t notify)
{
struct execdata_notify *n;
- mach_port_t foo;
- /* No need to check P here; we don't use it. */
+ if (!p)
+ return EOPNOTSUPP;
n = malloc (sizeof (struct execdata_notify));
if (! n)
@@ -196,13 +196,7 @@ S_proc_execdata_notify (struct proc *p,
n->next = execdata_notifys;
execdata_notifys = n;
- mach_port_request_notification (mach_task_self (), notify,
- MACH_NOTIFY_DEAD_NAME, 1,
- generic_port, MACH_MSG_TYPE_MAKE_SEND_ONCE,
- &foo);
-
- if (foo)
- mach_port_deallocate (mach_task_self (), foo);
+ ports_request_dead_name_notification (p, notify, NULL);
if (std_port_array)
exec_setexecdata (n->notify_port, std_port_array, MACH_MSG_TYPE_COPY_SEND,
diff --git a/proc/mgt.c b/proc/mgt.c
index 929712f8..a833a849 100644
--- a/proc/mgt.c
+++ b/proc/mgt.c
@@ -662,17 +662,9 @@ void
proc_death_notify (struct proc *p)
{
error_t err;
- mach_port_t old;
- err = mach_port_request_notification (mach_task_self (), p->p_task,
- MACH_NOTIFY_DEAD_NAME, 1,
- p->p_pi.port_right,
- MACH_MSG_TYPE_MAKE_SEND_ONCE,
- &old);
+ err = ports_request_dead_name_notification (p, p->p_task, NULL);
assert_perror_backtrace (err);
-
- if (old != MACH_PORT_NULL)
- mach_port_deallocate (mach_task_self (), old);
}
/* Complete a new process that has been allocated but not entirely initialized.
diff --git a/proc/notify.c b/proc/notify.c
index 8d694458..41a34112 100644
--- a/proc/notify.c
+++ b/proc/notify.c
@@ -1,5 +1,6 @@
/* Handle notifications
- Copyright (C) 1992, 1993, 1994, 1996, 1999 Free Software Foundation, Inc.
+ Copyright (C) 1992, 1993, 1994, 1996, 1999, 2021
+ Free Software Foundation, Inc.
This file is part of the GNU Hurd.
@@ -17,7 +18,7 @@
along with the GNU Hurd; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
-/* Written by Michael I. Bushnell. */
+/* Written by Michael I. Bushnell and Sergey Bugaev. */
#include <mach.h>
#include <sys/types.h>
@@ -33,40 +34,26 @@
#include "notify_S.h"
/* We ask for dead name notifications to detect when tasks and
- message ports die. Both notifications get sent to the process
- port. */
+ message ports die. All notifications get sent to the notify
+ port. */
kern_return_t
do_mach_notify_dead_name (struct port_info *pi,
- mach_port_t deadport)
+ mach_port_t dead_name)
{
struct proc *p;
- if (!pi)
+ if (!pi || !ports_port_is_notify (pi))
return EOPNOTSUPP;
- if (pi->port_right == generic_port)
- {
- check_dead_execdata_notify (deadport);
- mach_port_deallocate (mach_task_self (), deadport);
- return 0;
- }
+ check_dead_execdata_notify (dead_name);
- p = (struct proc *) pi;
+ p = task_find_nocreate (dead_name);
+ if (p)
+ process_has_exited (p);
- if (p->p_pi.bucket != proc_bucket
- || p->p_pi.class != proc_class)
- return EOPNOTSUPP;
+ mach_port_deallocate (mach_task_self (), dead_name);
- if (p->p_task == deadport)
- {
- process_has_exited (p);
- mach_port_deallocate (mach_task_self (), deadport);
- return 0;
- }
- else
- {
- return EINVAL;
- }
+ return 0;
}
/* We get no-senders notifications on exception ports that we