From owner-p4-projects@FreeBSD.ORG Fri Jan 20 14:59:21 2006 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 59D6416A422; Fri, 20 Jan 2006 14:59:21 +0000 (GMT) X-Original-To: perforce@freebsd.org Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 01B3416A41F for ; Fri, 20 Jan 2006 14:59:21 +0000 (GMT) (envelope-from millert@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id A775243D46 for ; Fri, 20 Jan 2006 14:59:20 +0000 (GMT) (envelope-from millert@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.1/8.13.1) with ESMTP id k0KExKtP073140 for ; Fri, 20 Jan 2006 14:59:20 GMT (envelope-from millert@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.1/8.13.1/Submit) id k0KExKjl073137 for perforce@freebsd.org; Fri, 20 Jan 2006 14:59:20 GMT (envelope-from millert@freebsd.org) Date: Fri, 20 Jan 2006 14:59:20 GMT Message-Id: <200601201459.k0KExKjl073137@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to millert@freebsd.org using -f From: Todd Miller To: Perforce Change Reviews Cc: Subject: PERFORCE change 90004 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 20 Jan 2006 14:59:22 -0000 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 #include #include -#include #import #import @@ -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) {