PERFORCE change 80195 for review
soc-tyler
soc-tyler at FreeBSD.org
Thu Jul 14 18:00:40 GMT 2005
http://perforce.freebsd.org/chv.cgi?CH=80195
Change 80195 by soc-tyler at 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 <Security/Authorization.h>
#include <Security/AuthorizationTags.h>
#include <Security/AuthSession.h>
@@ -58,26 +56,26 @@
#include <mach/mach_error.h>
#include <mach/port.h>
#endif
---------------------------------------------------------------------------------
- */
+#endif
+
#include <sys/types.h>
#include <sys/queue.h>
#include <sys/event.h>
#include <sys/stat.h>
-/* sys/param.h defines NGROUPS which is necessary for sys/ucred.h */
#include <sys/param.h>
#include <sys/ucred.h>
#include <sys/fcntl.h>
#include <sys/un.h>
#include <sys/wait.h>
#include <sys/sysctl.h>
+#include <sys/sockio.h>
#include <sys/socket.h>
-#include <sys/sockio.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/ioctl.h>
#include <sys/mount.h>
#include <net/if.h>
+#include <net/if_var.h>
#include <netinet/in.h>
#include <netinet/in_var.h>
#include <netinet6/nd6.h>
@@ -90,6 +88,7 @@
#include <stdlib.h>
#include <stdarg.h>
#include <stdbool.h>
+#include <string.h>
#include <pthread.h>
#include <paths.h>
#include <pwd.h>
@@ -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)
{
More information about the p4-projects
mailing list