From 86e760a779b29116426a2d5fd38a955d47cfb046 Mon Sep 17 00:00:00 2001 From: Thomas Bushnell Date: Fri, 12 Mar 1999 20:28:52 +0000 Subject: 1999-03-11 Mark Kettenis * notify.c (do_mach_notify_dead_name): Remove unnecessary braces. * msg.c (S_proc_setmsgport): Remove unused variable FOO. (S_proc_getmsgport): Only check if the message port is still alive if it is not MACH_PORT_NULL. Use mach_port_type instead of mach_port_get_refs to check if the port is dead. * mgt.c (S_proc_reassign): Use mach_port_destroy to release the old task port. --- proc/msg.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'proc/msg.c') diff --git a/proc/msg.c b/proc/msg.c index 5a9d8919..eae1c603 100644 --- a/proc/msg.c +++ b/proc/msg.c @@ -50,7 +50,6 @@ S_proc_setmsgport (struct proc *p, mach_port_t *oldmsgport, mach_msg_type_name_t *oldmsgport_type) { - mach_port_t foo; if (!p) return EOPNOTSUPP; @@ -92,8 +91,6 @@ S_proc_getmsgport (struct proc *callerp, { int cancel; struct proc *p = pid_find_allow_zombie (pid); - error_t err; - mach_port_urefs_t refs; if (!callerp) return EOPNOTSUPP; @@ -116,19 +113,25 @@ restart: if (!p) return ESRCH; - err = mach_port_get_refs (mach_task_self (), p->p_msgport, - MACH_PORT_RIGHT_SEND, &refs); - if (err || !refs) + /* Only check if the message port passed away, if we know that it + was ever alive. */ + if (p->p_msgport != MACH_PORT_NULL) { - /* The port appears to be dead; throw it away. */ - mach_port_deallocate (mach_task_self (), p->p_msgport); - p->p_msgport = MACH_PORT_NULL; - p->p_deadmsg = 1; - goto restart; + mach_port_type_t type; + error_t err; + + err = mach_port_type (mach_task_self (), p->p_msgport, &type); + if (err || (type & MACH_PORT_TYPE_DEAD_NAME)) + { + /* The port appears to be dead; throw it away. */ + mach_port_deallocate (mach_task_self (), p->p_msgport); + p->p_msgport = MACH_PORT_NULL; + p->p_deadmsg = 1; + goto restart; + } } - + *msgport = p->p_msgport; return 0; } - -- cgit v1.2.3