From owner-p4-projects@FreeBSD.ORG Fri Sep 2 05:07:04 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 0F29316A421; Fri, 2 Sep 2005 05:07:04 +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 C25A416A41F for ; Fri, 2 Sep 2005 05:07:03 +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 7EDE443D4C for ; Fri, 2 Sep 2005 05:07:03 +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 j82573bT000800 for ; Fri, 2 Sep 2005 05:07:03 GMT (envelope-from soc-tyler@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.1/8.13.1/Submit) id j825738t000797 for perforce@freebsd.org; Fri, 2 Sep 2005 05:07:03 GMT (envelope-from soc-tyler@freebsd.org) Date: Fri, 2 Sep 2005 05:07:03 GMT Message-Id: <200509020507.j825738t000797@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 82997 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, 02 Sep 2005 05:07:04 -0000 http://perforce.freebsd.org/chv.cgi?CH=82997 Change 82997 by soc-tyler@soc-tyler_launchd on 2005/09/02 05:06:17 WAHOO! Some sort of conf file functionality! I can load data from my rudimentary "launcher" configuration file format. rox0r. Now to add more "stuff" to launchctl and move on to init(8) code, 11th hour... race to the finish ;) Affected files ... .. //depot/projects/soc2005/launchd/includes/property.h#3 edit .. //depot/projects/soc2005/launchd/launchctl/launchctl.c#18 edit Differences ... ==== //depot/projects/soc2005/launchd/includes/property.h#3 (text+ko) ==== @@ -33,6 +33,12 @@ #include #include +/* launchd(8) specific definitions */ +#define LAUNCH_PROPERTY_LABEL "Label" +#define LAUNCH_PROPERTY_PATH "Path" +#define LAUNCH_PROPERTY_FLAGS "Flags" +#define LAUNCH_PROPERTY_LENGTH 128 + int property_count(properties list); #endif ==== //depot/projects/soc2005/launchd/launchctl/launchctl.c#18 (text+ko) ==== @@ -100,6 +100,7 @@ // FreeBSD related functions (for forwards compat? :P #ifndef _BUILD_DARWIN static launch_data_t read_conf_file(const char *, bool, bool); +static launch_data_t Conf2launch_data(void *); #endif static int load_and_unload_cmd(int argc, char *const argv[]); @@ -149,7 +150,6 @@ { "umask", umask_cmd, "Change launchd's umask" }, { "help", help_cmd, "This help output" }, {"exit", exit_cmd, "Exit launchctl" }, - {"quit", exit_cmd, "Exit launchctl"}, }; static bool istty = false; @@ -336,7 +336,7 @@ #ifdef _LAUNCHD_ 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; + launch_data_t r; properties conf_props; // libutil.h and -lutil are required for this.. int fd; @@ -346,30 +346,65 @@ return NULL; /* calling function must check for a NULL pointer */ conf_props = properties_read(fd); /* read in config data */ - - retval = launch_data_alloc(LAUNCH_DATA_PROPERTY); - //launch_data_set_opaque(retval, (const void *)(conf_props), sizeof(properties)); - - /* I figure we'll just add the properties(3) linked list to the - * opaque launch_data_t datatype (opaque ~= void *) - * - * this will probably come back to haunt me - */ + + r = Conf2launch_data(conf_props); close(fd); - return retval; + + return r; } /* This function should mimic CF2launch_data in how it creates * a launch_data_t data structure from the contents of a .plist file */ -/* -static launch_data_t Conf2launch_data(void *) { - launch_data_t r; +static launch_data_t Conf2launch_data(void *prop) { + bool fflag = true; + char *label, *path, *flags; + + launch_data_t job = launch_data_alloc(LAUNCH_DATA_DICTIONARY); + + label = malloc(sizeof(char) * LAUNCH_PROPERTY_LENGTH); + path = malloc(sizeof(char) * LAUNCH_PROPERTY_LENGTH); + flags = malloc(sizeof(char) * LAUNCH_PROPERTY_LENGTH); + + // retrieve appropriate data and assign to correct vars + if ((label = property_find((properties)(prop), LAUNCH_PROPERTY_LABEL)) + == NULL) { + fprintf(stderr, "Could not locate a 'Label' for this launcher\n"); + goto out_bad; + } + + if ((path = property_find((properties)(prop), LAUNCH_PROPERTY_PATH)) + == NULL) { + fprintf(stderr, "Could not locate a 'Path' for this launcher\n"); + goto out_bad; + } + + if ((flags = property_find((properties)(prop), LAUNCH_PROPERTY_FLAGS)) + == NULL) { + fprintf(stderr, "**debug** no flags set for this job\n"); + fflag = false; + free(flags); + } + + + /* begin to insert pertinent data into the job data structure */ + launch_data_dict_insert(job, launch_data_new_string(label), LAUNCH_JOBKEY_LABEL); + launch_data_dict_insert(job, launch_data_new_string(path), LAUNCH_JOBKEY_PROGRAM); + if (flags != NULL) + launch_data_dict_insert(job, launch_data_new_string(flags), LAUNCH_JOBKEY_PROGRAMARGUMENTS); + + + return job; - return r; +out_bad: + free(label); + free(path); + if (flags != NULL) + free(flags); + + exit(EXIT_FAILURE); } -*/ #endif #endif @@ -1439,7 +1474,9 @@ { "maxproc", RLIMIT_NPROC }, { "maxfiles", RLIMIT_NOFILE } }; - size_t limlookupcnt = sizeof limlookup / sizeof limlookup[0]; + + size_t limlookupcnt = (sizeof(limlookup) / sizeof(limlookup[0])); + bool name2num(const char *n) { for (i = 0; i < limlookupcnt; i++) { if (!strcmp(limlookup[i].name, n)) {