From owner-p4-projects@FreeBSD.ORG Fri Aug 26 11:47:56 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 0906816A423; Fri, 26 Aug 2005 11:47:56 +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 C0E3716A41F for ; Fri, 26 Aug 2005 11:47:55 +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 8066043D49 for ; Fri, 26 Aug 2005 11:47:55 +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 j7QBltYf040583 for ; Fri, 26 Aug 2005 11:47:55 GMT (envelope-from soc-tyler@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.1/8.13.1/Submit) id j7QBltQR040580 for perforce@freebsd.org; Fri, 26 Aug 2005 11:47:55 GMT (envelope-from soc-tyler@freebsd.org) Date: Fri, 26 Aug 2005 11:47:55 GMT Message-Id: <200508261147.j7QBltQR040580@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 82610 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, 26 Aug 2005 11:47:57 -0000 http://perforce.freebsd.org/chv.cgi?CH=82610 Change 82610 by soc-tyler@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 +#endif + #include #include #include @@ -72,8 +76,12 @@ #include #include #include -/* include libutil.h for basic property parsing (see: xx.launch) */ + +#ifndef _BUILD_DARWIN_ +/* include libutil.h for basic property parsing on FreeBSD */ #include +#endif + #include #include #include @@ -84,9 +92,11 @@ #include #include -/* Mac OS specific - * #include - * +// Mac OS specific +#ifdef _BUILD_DARWIN_ +#include +#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 #include #include @@ -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);