PERFORCE change 82997 for review

soc-tyler soc-tyler at FreeBSD.org
Fri Sep 2 05:07:04 GMT 2005


http://perforce.freebsd.org/chv.cgi?CH=82997

Change 82997 by soc-tyler at 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 <sys/types.h>
 #include <libutil.h>
 
+/* 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)) {


More information about the p4-projects mailing list