PERFORCE change 82610 for review
soc-tyler
soc-tyler at FreeBSD.org
Fri Aug 26 11:47:57 GMT 2005
http://perforce.freebsd.org/chv.cgi?CH=82610
Change 82610 by soc-tyler at soc-tyler_launchd on 2005/08/26 11:47:44
Put some of the Darwin-based code back in under the guise of backwards
compatibility. Since we're going to use the non-XML plist file format
in the future for as much backwards compatibility with launchd/OS X
Oh, and fix some typos :D
Affected files ...
.. //depot/projects/soc2005/launchd/launchctl/launchctl.c#9 edit
.. //depot/projects/soc2005/launchd/launchd.c#15 edit
.. //depot/projects/soc2005/launchd/liblaunch.c#13 edit
Differences ...
==== //depot/projects/soc2005/launchd/launchctl/launchctl.c#9 (text+ko) ====
@@ -58,6 +58,10 @@
* the XML parsing functions
*/
+#ifdef _BUILD_DARWIN_
+#include <CoreFoundation/CoreFoundation.h>
+#endif
+
#include <sys/types.h>
#include <sys/time.h>
#include <sys/stat.h>
@@ -72,8 +76,12 @@
#include <unistd.h>
#include <dirent.h>
#include <libgen.h>
-/* include libutil.h for basic property parsing (see: xx.launch) */
+
+#ifndef _BUILD_DARWIN_
+/* include libutil.h for basic property parsing on FreeBSD */
#include <libutil.h>
+#endif
+
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
@@ -84,9 +92,11 @@
#include <readline/readline.h>
#include <readline/history.h>
-/* Mac OS specific
- * #include <dns_sd.h>
- *
+// Mac OS specific
+#ifdef _BUILD_DARWIN_
+#include <dns_sd.h>
+#endif
+/*
* This includes the Zeroconf headers, so launchctl(1) can start the
* 'advertising' end of Zeroconf for daemons (ssh, xinetd, etc)
*/
@@ -100,17 +110,25 @@
static void distill_config_file(launch_data_t);
static void sock_dict_cb(launch_data_t what, const char *key, void *context);
static void sock_dict_edit_entry(launch_data_t tmp, const char *key, launch_data_t fdarray, launch_data_t thejob);
-static launch_data_t read_conf_file(const char *, bool, bool);
-//static launch_data_t CF2launch_data(const void *);
-//static launch_data_t read_plist_file(const char *file, bool editondisk, bool load);
-//static const void *CreateMyPropertyListFromFile(const char *);
-//static void WriteMyPropertyListToFile(CFPropertyListRef, const char *);
static void readpath(const char *, launch_data_t, launch_data_t, bool editondisk, bool load);
static int _fd(int);
static int demux_cmd(int argc, char *const argv[]);
-//static launch_data_t do_rendezvous_magic(const struct addrinfo *res, const char *serv);
static void submit_job_pass(launch_data_t jobs);
+// Mac OS X/Darwin related functions (for backwards compat.)
+#ifdef _BUILD_DARWIN_
+static launch_data_t CF2launch_data(const void *);
+static launch_data_t read_plist_file(const char *file, bool editondisk, bool load);
+static const void *CreateMyPropertyListFromFile(const char *);
+static void WriteMyPropertyListToFile(CFPropertyListRef, const char *);
+static launch_data_t do_rendezvous_magic(const struct addrinfo *res, const char *serv);
+#endif
+
+// FreeBSD related functions (for forwards compat? :P
+#ifndef _BUILD_DARWIN
+static launch_data_t read_conf_file(const char *, bool, bool);
+#endif
+
static int load_and_unload_cmd(int argc, char *const argv[]);
//static int reload_cmd(int argc, char *const argv[]);
static int start_and_stop_cmd(int argc, char *const argv[]);
@@ -334,6 +352,7 @@
launch_data_free(resp);
}
+#ifndef _BUILD_DARWIN
static launch_data_t read_conf_file(const char *file, bool editondisk, bool load) {
/* fill this with an array of launch_data_t structs */
launch_data_t retval = NULL;
@@ -358,10 +377,10 @@
close(fd);
return retval;
}
+#endif
-/*
-static launch_data_t read_plist_file(const char *file, bool editondisk, bool load)
-{
+#ifdef _BUILD_DARWIN_
+static launch_data_t read_plist_file(const char *file, bool editondisk, bool load) {
CFPropertyListRef plist = CreateMyPropertyListFromFile(file);
launch_data_t r = NULL;
@@ -384,7 +403,7 @@
return r;
}
-*/
+#endif
static void delay_to_second_pass2(launch_data_t o, const char *key, void *context)
{
@@ -409,8 +428,7 @@
}
}
-static bool delay_to_second_pass(launch_data_t o)
-{
+static bool delay_to_second_pass(launch_data_t o) {
bool res = false;
launch_data_t socks = launch_data_dict_lookup(o, LAUNCH_JOBKEY_SOCKETS);
@@ -706,7 +724,7 @@
}
}
-/*
+#ifdef _BUILD_DARWIN_
static launch_data_t do_rendezvous_magic(const struct addrinfo *res, const char *serv)
{
struct stat sb;
@@ -849,7 +867,7 @@
}
return r;
}
-*/
+#endif
static int help_cmd(int argc, char *const argv[])
{
@@ -873,7 +891,7 @@
}
static int exit_cmd(int argc, char *const argv[]) {
- exit(0);
+ exit(EXIT_SUCCESS);
return 0; // god help us if we get here ;)
}
==== //depot/projects/soc2005/launchd/launchd.c#15 (text+ko) ====
@@ -29,7 +29,6 @@
*/
#ifdef _BUILD_DARWIN_
-
#include <Security/Authorization.h>
#include <Security/AuthorizationTags.h>
#include <Security/AuthSession.h>
@@ -212,9 +211,8 @@
static kq_callback kqmach_callback = mach_callback;
#endif
-// workaround for an OpenFirmware and Xnu bug, only on Darwin though ;)
+// workaround for an OpenFirmware and Darwin kernel bug
static void workaround3048875(int argc, char *argv[]);
-
static pthread_t mach_server_loop_thread;
mach_port_t launchd_bootstrap_port = MACH_PORT_NULL;
blocked_signals = 0;
@@ -355,7 +353,7 @@
exit(EXIT_SUCCESS);
}
}
- // XXX: error: delays gdb step-through
+
switch (kevent(mainkq, NULL, 0, &kev, 1, timeoutp)) {
case -1:
syslog(LOG_DEBUG, "kevent(): %m");
@@ -364,7 +362,9 @@
(*((kq_callback *)kev.udata))(kev.udata, &kev);
break;
case 0:
- // XXX: timeoutp == 0, launchd(8) exits normally
+ /* we exit here if and once we're done processing all jobs
+ * assigned to us
+ */
if (timeoutp)
exit(EXIT_SUCCESS);
else
==== //depot/projects/soc2005/launchd/liblaunch.c#13 (text+ko) ====
@@ -109,6 +109,7 @@
// if we can't calloc() _lc, exit function
if (_lc == NULL)
+ return;
pthread_mutex_init(&_lc->mtx, NULL);
More information about the p4-projects
mailing list