From owner-p4-projects@FreeBSD.ORG Thu Jul 14 18:00:40 2005 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 B742616A420; Thu, 14 Jul 2005 18:00:39 +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 8BEB016A41C for ; Thu, 14 Jul 2005 18:00:39 +0000 (GMT) (envelope-from soc-tyler@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id 3D3B243D49 for ; Thu, 14 Jul 2005 18:00:39 +0000 (GMT) (envelope-from soc-tyler@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 j6EI0d7u000342 for ; Thu, 14 Jul 2005 18:00:39 GMT (envelope-from soc-tyler@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.1/8.13.1/Submit) id j6EI0cIH000329 for perforce@freebsd.org; Thu, 14 Jul 2005 18:00:38 GMT (envelope-from soc-tyler@freebsd.org) Date: Thu, 14 Jul 2005 18:00:38 GMT Message-Id: <200507141800.j6EI0cIH000329@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to soc-tyler@freebsd.org using -f From: soc-tyler To: Perforce Change Reviews Cc: Subject: PERFORCE change 80195 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: Thu, 14 Jul 2005 18:00:40 -0000 http://perforce.freebsd.org/chv.cgi?CH=80195 Change 80195 by soc-tyler@soc-tyler_launchd on 2005/07/14 17:59:44 Restart from scratch with launchd.c, start #ifdef'ing Darwin specific nonsense out here and there. Add a few comments from zarzycki@'s explaination of pid1_magic_init() Affected files ... .. //depot/projects/soc2005/launchd/includes/launchd.h#3 edit .. //depot/projects/soc2005/launchd/launchd.c#3 edit Differences ... ==== //depot/projects/soc2005/launchd/includes/launchd.h#3 (text+ko) ==== @@ -28,8 +28,9 @@ typedef void (*kq_callback)(void *, struct kevent *); extern kq_callback kqsimple_zombie_reaper; -/* Mac OS/NeXT specific */ -//extern mach_port_t launchd_bootstrap_port; +#ifdef _BUILD_MACOS +extern mach_port_t launchd_bootstrap_port; +#endif extern sigset_t blocked_signals; #ifdef PID1_REAP_ADOPTED_CHILDREN @@ -47,4 +48,9 @@ void catatonia(void); void death(void); +// on Darwin-based systems, LOG_LAUNCHD is defined for syslog() +#ifndef _BUILD_MACOS +#define LOG_LAUNCHD LOG_DAEMON +#endif + #endif ==== //depot/projects/soc2005/launchd/launchd.c#3 (text+ko) ==== @@ -47,10 +47,8 @@ * * @APPLE_LICENSE_HEADER_END@ */ - -/* Mac OS specific frameworks (and NeXT-specific for that matter) - * XXX: these need to be implemented or worked around in another manner --------------------------------------------------------------------------------- + +#ifdef _BUILD_MACOS #include #include #include @@ -58,26 +56,26 @@ #include #include #endif --------------------------------------------------------------------------------- - */ +#endif + #include #include #include #include -/* sys/param.h defines NGROUPS which is necessary for sys/ucred.h */ #include #include #include #include #include #include +#include #include -#include #include #include #include #include #include +#include #include #include #include @@ -90,6 +88,7 @@ #include #include #include +#include #include #include #include @@ -101,21 +100,21 @@ #include "launch_priv.h" #include "launchd.h" -/* Another mach/Mac OS specific header that's been stripped out for FreeBSD - * related work, similar items on FreeBSD might be related to init(8) +#ifdef _BUILD_MACOS #include "bootstrap_internal.h" - */ +#endif #define LAUNCHD_MIN_JOB_RUN_TIME 10 #define LAUNCHD_REWARD_JOB_RUN_TIME 60 #define LAUNCHD_FAILED_EXITS_THRESHOLD 10 #define PID1LAUNCHD_CONF "/etc/launchd.conf" #define LAUNCHD_CONF ".launchd.conf" -#define LAUNCHCTL_PATH "/bin/launchctl" -/* Mac OS specific +#define LAUNCHCTL_PATH "/sbin/launchctl" + +#ifdef _BUILD_MACOS #define SECURITY_LIB "/System/Library/Frameworks/Security.framework/Versions/A/Security" #define VOLFSDIR "/.vol" - */ +#endif extern char **environ; @@ -220,18 +219,20 @@ static pid_t readcfg_pid = 0; static bool launchd_inited = false; static bool shutdown_in_progress = false; + +sigset_t blocked_signals; + +#ifdef _BUILD_MACOS static pthread_t mach_server_loop_thread; -/* We undeclared this variable in includes/launchd.h so we will do so here as - * well. (on Darwin, mach_port_t is an unsigned int, it's purpose escapes me.. - * I would assume it's related to mach's bootstrap concept, so I should probably - * hit it as I replace init(8) mach_port_t launchd_bootstrap_port = MACH_PORT_NULL; - */ -sigset_t blocked_signals = 0; +blocked_signals = 0; +#endif + static char *pending_stdout = NULL; static char *pending_stderr = NULL; -int main(int argc, char *argv[]) { +int main(int argc, char *argv[]) +{ static const int sigigns[] = { SIGHUP, SIGINT, SIGPIPE, SIGALRM, SIGTERM, SIGURG, SIGTSTP, SIGTSTP, SIGCONT, /*SIGCHLD,*/ SIGTTIN, SIGTTOU, SIGIO, SIGXCPU, SIGXFSZ, SIGVTALRM, SIGPROF, @@ -318,7 +319,9 @@ if (getpid() == 1) { pid1_magic_init(sflag, vflag, xflag); } else { +#ifdef _BUILD_MACOS launchd_bootstrap_port = bootstrap_port; +#endif launchd_server_init(argv[0] ? true : false); } @@ -403,34 +406,41 @@ if (memsz == 4) mem = *(uint32_t *)&mem; mvn = mem / (64 * 1024) + 1024; + + // Performance note: change the max # of vnodes if (sysctl(mvnmib, 2, NULL, NULL, &mvn, sizeof(mvn)) == -1) syslog(LOG_WARNING, "sysctl(\"%s\"): %m", "kern.maxvnodes"); } + + // Performance note: set our hostname to localhost for now if (sysctl(hnmib, 2, NULL, NULL, "localhost", sizeof("localhost")) == -1) syslog(LOG_WARNING, "sysctl(\"%s\"): %m", "kern.hostname"); if (setlogin("root") == -1) syslog(LOG_ERR, "setlogin(\"root\"): %m"); - + + // Performance note: setup our loopback interface inline loopback_setup(); if (mount("fdesc", "/dev", MNT_UNION, NULL) == -1) syslog(LOG_ERR, "mount(\"%s\", \"%s\", ...): %m", "fdesc", "/dev/"); setenv("PATH", _PATH_STDPATH, 1); - +#ifdef _BUILD_MACOS launchd_bootstrap_port = mach_init_init(); task_set_bootstrap_port(mach_task_self(), launchd_bootstrap_port); bootstrap_port = MACH_PORT_NULL; +#endif pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); - +#ifdef _BUILD_MACOS pthr_r = pthread_create(&mach_server_loop_thread, &attr, mach_server_loop, NULL); if (pthr_r != 0) { syslog(LOG_ERR, "pthread_create(mach_server_loop): %s", strerror(pthr_r)); exit(EXIT_FAILURE); } +#endif pthread_attr_destroy(&attr); @@ -2246,6 +2256,10 @@ return launch_data_new_opaque(l, sizeof(struct rlimit) * RLIM_NLIMITS); } +/* + * XXX: I'm not exactly sure what this function's exact purpose is. + */ +#ifdef _BUILD_MACOS __private_extern__ void launchd_SessionCreate(const char *who) { void *seclib = dlopen(SECURITY_LIB, RTLD_LAZY); @@ -2267,6 +2281,7 @@ syslog(LOG_WARNING, "%s: dlopen(\"%s\",...): %s", who, SECURITY_LIB, dlerror()); } } +#endif static int dir_has_files(const char *path) {