Date: Fri, 20 Jan 2006 14:59:20 GMT From: Todd Miller <millert@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 90004 for review Message-ID: <200601201459.k0KExKjl073137@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=90004 Change 90004 by millert@millert_ibook on 2006/01/20 14:58:35 No longer need to include mac.h Remove useless local variable that shadows one in enclosing scope Deal with waitpid() returning 0. Code adapted from launchd's bootstrap.c which already deals with this case. Affected files ... .. //depot/projects/trustedbsd/sedarwin7/src/darwin/system_cmds/mach_init.tproj/bootstrap.c#7 edit Differences ... ==== //depot/projects/trustedbsd/sedarwin7/src/darwin/system_cmds/mach_init.tproj/bootstrap.c#7 (text+ko) ==== @@ -43,7 +43,6 @@ #include <mach/host_info.h> #include <mach/mach_host.h> #include <mach/exception.h> -#include <sys/mac.h> #import <sys/ioctl.h> #import <sys/types.h> @@ -584,8 +583,9 @@ reap_server(server_t *serverp) { kern_return_t result; - pid_t presult; - int wstatus; + mach_port_t old_port; + pid_t presult; + int wstatus; /* * Reap our children. @@ -593,9 +593,44 @@ do { presult = waitpid(serverp->pid, &wstatus, WNOHANG); } while (presult == -1 && errno == EINTR); - if (presult != serverp->pid) { - unix_error("waitpid: cmd = %s", serverp->cmd); - } else if (wstatus) { + switch (presult) { + case -1: + unix_error("waitpid: cmd = %s, pid = %d", serverp->cmd, + serverp->pid); + break; + + case 0: + /* process must have switched mach tasks */ + old_port = serverp->task_port; + mach_port_deallocate(mach_task_self(), old_port); + serverp->task_port = MACH_PORT_NULL; + + result = task_for_pid(mach_task_self(), serverp->pid, + &serverp->task_port); + if (result != KERN_SUCCESS) { + kern_error(result, + "race getting new server task port for pid[%d]", + serverp->pid); + break; + } + + /* Request dead name notification to tell when new task dies */ + result = mach_port_request_notification( + mach_task_self(), + serverp->task_port, + MACH_NOTIFY_DEAD_NAME, + 0, + notify_port, + MACH_MSG_TYPE_MAKE_SEND_ONCE, + &old_port); + if (result != KERN_SUCCESS) { + kern_error(result, "race setting up notification for " + "new server task port for pid[%d]", serverp->pid); + break; + } + return; + + default: notice("Server %x in bootstrap %x uid %d: \"%s\": %s %d [pid %d]", serverp->port, serverp->bootstrap->bootstrap_port, serverp->uid, serverp->cmd, @@ -604,6 +639,7 @@ "exited as a result of signal"), ((WIFEXITED(wstatus)) ? WEXITSTATUS(wstatus) : WTERMSIG(wstatus)), serverp->pid); + break; } serverp->pid = 0; @@ -1105,7 +1141,7 @@ np = ((mach_port_destroyed_notification_t *)Request)->not_port.name; servicep = lookup_service_by_port(np); if (servicep != NULL) { - server_t *serverp = servicep->server; + serverp = servicep->server; switch (Request->msgh_id) {
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200601201459.k0KExKjl073137>