+static mach_port_t *msrvs = NULL;
+static size_t msrvs_cnt = 0;
+
+void
+submit_mach_jobs(launch_data_t jobs)
+{
+ size_t i, c;
+
+ c = launch_data_array_get_count(jobs);
+
+ msrvs = calloc(1, sizeof(mach_port_t) * c);
+ msrvs_cnt = c;
+
+ for (i = 0; i < c; i++) {
+ launch_data_t tmp, oai = launch_data_array_get_index(jobs, i);
+ const char *sn = NULL, *cmd = NULL;
+ bool d = true, k = false;
+ mach_port_t msr, msv, mhp;
+ kern_return_t kr;
+ uid_t u = getuid();
+
+ if ((tmp = launch_data_dict_lookup(oai, MACHINIT_JOBKEY_ONDEMAND)))
+ d = launch_data_get_bool(tmp);
+ if ((tmp = launch_data_dict_lookup(oai, MACHINIT_JOBKEY_ISKUNCSERVER)))
+ k = launch_data_get_bool(tmp);
+ if ((tmp = launch_data_dict_lookup(oai, MACHINIT_JOBKEY_SERVICENAME)))
+ sn = launch_data_get_string(tmp);
+ if ((tmp = launch_data_dict_lookup(oai, MACHINIT_JOBKEY_COMMAND)))
+ cmd = launch_data_get_string(tmp);
+
+ if ((kr = bootstrap_create_server(bootstrap_port, (char *)cmd, u, d, &msr)) != KERN_SUCCESS) {
+ fprintf(stderr, "%s: bootstrap_create_server(): %d\n", getprogname(), kr);
+ continue;
+ }
+ if ((kr = bootstrap_create_service(msr, (char*)sn, &msv)) != KERN_SUCCESS) {
+ fprintf(stderr, "%s: bootstrap_create_service(): %d\n", getprogname(), kr);
+ mach_port_destroy(mach_task_self(), msr);
+ continue;
+ }
+ if (k) {
+ mhp = mach_host_self();
+ if ((kr = host_set_UNDServer(mhp, msv)) != KERN_SUCCESS)
+ fprintf(stderr, "%s: host_set_UNDServer(): %s\n", getprogname(), mach_error_string(kr));
+ mach_port_deallocate(mach_task_self(), mhp);
+ }
+ mach_port_deallocate(mach_task_self(), msv);
+ msrvs[i] = msr;
+ }
+}
+
+void
+let_go_of_mach_jobs(void)
+{
+ size_t i;
+
+ for (i = 0; i < msrvs_cnt; i++)
+ mach_port_destroy(mach_task_self(), msrvs[i]);
+}
+
+void
+submit_job_pass(launch_data_t jobs)