Revision: 22879 http://trac.macosforge.org/projects/launchd/changeset/22879 Author: zarzycki@apple.com Date: 2006-09-24 13:01:11 -0700 (Sun, 24 Sep 2006) Log Message: ----------- Adopt MIG's automatic type conversion feature. This will make our life easier in the long run. Modified Paths: -------------- trunk/launchd/src/bootstrap.defs trunk/launchd/src/bootstrap_private.h trunk/launchd/src/launchd_core_logic.c trunk/launchd/src/launchd_core_logic.h trunk/launchd/src/launchd_mach_ipc.c trunk/launchd/src/launchd_runtime.c Modified: trunk/launchd/src/bootstrap.defs =================================================================== --- trunk/launchd/src/bootstrap.defs 2006-09-24 18:25:30 UTC (rev 22878) +++ trunk/launchd/src/bootstrap.defs 2006-09-24 20:01:11 UTC (rev 22879) @@ -39,11 +39,18 @@ type bootstrap_status_t = integer_t; type bootstrap_status_array_t = ^array [] of bootstrap_status_t; +type job_t = mach_port_t + intran: job_t job_mig_intran(mach_port_t) + outtran: mach_port_t job_mig_outtran(job_t) + destructor: job_mig_destructor(job_t) + cusertype: vproc_mig_t; + + userprefix raw_; serverprefix x_; routine bootstrap_create_server( - __bs_port : mach_port_t; + __bs_port : job_t; __server_cmd : cmd_t; __server_uid : natural_t; __on_demand : boolean_t; @@ -53,19 +60,19 @@ skip; /* Last used in 10.4. Was bootstrap_unprivileged() */ routine bootstrap_check_in( - __bs_port : mach_port_t; + __bs_port : job_t; __service_name : name_t; ServerAuditToken __token : audit_token_t; out __service_port : mach_port_move_receive_t); routine bootstrap_register( - __bs_port : mach_port_t; + __bs_port : job_t; ServerAuditToken __token : audit_token_t; __service_name : name_t; __service_port : mach_port_t); routine bootstrap_look_up( - __bs_port : mach_port_t; + __bs_port : job_t; ServerAuditToken __token : audit_token_t; __service_name : name_t; out __service_port : mach_port_send_t); @@ -73,28 +80,28 @@ skip; /* last used in 10.4 */ routine bootstrap_parent( - __bs_port : mach_port_t; + __bs_port : job_t; out __parent_port : mach_port_send_t); skip; /* last used in 10.4 */ routine bootstrap_info( - __bs_port : mach_port_t; + __bs_port : job_t; out __service_names : name_array_t, dealloc; out __service_active : bootstrap_status_array_t, dealloc); routine bootstrap_subset( - __bs_port : mach_port_t; + __bs_port : job_t; __requestor_port: mach_port_t; out __subset_port : mach_port_make_send_t); routine bootstrap_create_service( - __bs_port : mach_port_t; + __bs_port : job_t; __service_name : name_t; out __service_port : mach_port_t); routine bootstrap_transfer_subset( - __bs_port : mach_port_t; + __bs_port : job_t; out __bs_reqport : mach_port_t; out __bs_rcvright : mach_port_move_receive_t; out __service_names : name_array_t, dealloc; @@ -102,11 +109,11 @@ out __service_ports : mach_port_array_t, dealloc); routine bootstrap_getsocket( - __bs_port : mach_port_t; + __bs_port : job_t; out __sockpath : name_t); routine mpm_spawn( - __bs_port : mach_port_t; + __bs_port : job_t; ServerAuditToken __token : audit_token_t; __chars : _internal_string_t; __argc : uint32_t; @@ -117,17 +124,17 @@ out __obsvr_port : mach_port_make_send_t); routine mpm_wait( - __bs_port : mach_port_t; + __bs_port : job_t; sreplyport __rport : mach_port_make_send_once_t; ServerAuditToken __token : audit_token_t; out __waitval : integer_t); routine mpm_uncork_fork( - __bs_port : mach_port_t; + __bs_port : job_t; ServerAuditToken __token : audit_token_t); /* Essentially the inverse of bootstrap_unprivileged() */ routine bootstrap_get_self( - __bs_port : mach_port_t; + __bs_port : job_t; ServerAuditToken __token : audit_token_t; out __job_port : mach_port_make_send_t); Modified: trunk/launchd/src/bootstrap_private.h =================================================================== --- trunk/launchd/src/bootstrap_private.h 2006-09-24 18:25:30 UTC (rev 22878) +++ trunk/launchd/src/bootstrap_private.h 2006-09-24 20:01:11 UTC (rev 22879) @@ -20,7 +20,14 @@ * @APPLE_APACHE_LICENSE_HEADER_END@ */ -typedef char *_internal_string_t; +typedef char * _internal_string_t; +typedef mach_port_t vproc_mig_t; + +#ifdef bootstrap_MSG_COUNT +/* HACK */ +#include "launchd_core_logic.h" +#endif + #define SPAWN_HAS_PATH 0x0001 #define SPAWN_HAS_WDIR 0x0002 #define SPAWN_HAS_UMASK 0x0004 Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2006-09-24 18:25:30 UTC (rev 22878) +++ trunk/launchd/src/launchd_core_logic.c 2006-09-24 20:01:11 UTC (rev 22879) @@ -1373,12 +1373,17 @@ } job_t -job_find_by_port(mach_port_t p) +job_mig_intran(mach_port_t p) { return job_find_by_port2(root_job, p); } void +job_mig_destructor(job_t j __attribute__((unused))) +{ +} + +void job_export_all2(job_t j, launch_data_t where) { launch_data_t tmp; Modified: trunk/launchd/src/launchd_core_logic.h =================================================================== --- trunk/launchd/src/launchd_core_logic.h 2006-09-24 18:25:30 UTC (rev 22878) +++ trunk/launchd/src/launchd_core_logic.h 2006-09-24 20:01:11 UTC (rev 22879) @@ -21,6 +21,7 @@ */ #include "bootstrap_public.h" +#include "launch.h" #define job_assumes(j, e) \ (__builtin_expect(!(e), 0) ? job_log_bug(j, __rcs_file_version__, __FILE__, __LINE__, #e), false : true) @@ -43,7 +44,8 @@ job_t job_find(job_t j, const char *label); job_t job_find_by_pid(job_t j, pid_t p, bool recurse); -job_t job_find_by_port(mach_port_t mp); +job_t job_mig_intran(mach_port_t mp); +void job_mig_destructor(job_t j); job_t job_import(launch_data_t pload); launch_data_t job_import_bulk(launch_data_t pload); job_t job_new(job_t p, const char *label, const char *prog, const char *const *argv, const char *stdinpath, mach_port_t); Modified: trunk/launchd/src/launchd_mach_ipc.c =================================================================== --- trunk/launchd/src/launchd_mach_ipc.c 2006-09-24 18:25:30 UTC (rev 22878) +++ trunk/launchd/src/launchd_mach_ipc.c 2006-09-24 20:01:11 UTC (rev 22879) @@ -53,13 +53,13 @@ #include <stdbool.h> #include <syslog.h> +#include "launchd_core_logic.h" #include "bootstrap_public.h" #include "bootstrap_private.h" #include "bootstrap.h" #include "bootstrapServer.h" #include "launchd.h" #include "launchd_runtime.h" -#include "launchd_core_logic.h" #include "launch_priv.h" #include "launchd_unix_ipc.h" @@ -145,11 +145,11 @@ } kern_return_t -x_bootstrap_create_server(mach_port_t bp, cmd_t server_cmd, uid_t server_uid, boolean_t on_demand, +x_bootstrap_create_server(job_t j, cmd_t server_cmd, uid_t server_uid, boolean_t on_demand, audit_token_t au_tok, mach_port_t *server_portp) { - job_t js, j = job_find_by_port(bp); struct ldcred ldc; + job_t js; audit_token_to_launchd_cred(au_tok, &ldc); @@ -185,7 +185,7 @@ } kern_return_t -x_bootstrap_getsocket(mach_port_t bp, name_t spr) +x_bootstrap_getsocket(job_t j, name_t spr) { if (!sockpath) { return BOOTSTRAP_NO_MEMORY; @@ -199,10 +199,10 @@ } kern_return_t -x_bootstrap_get_self(mach_port_t bp, audit_token_t au_tok, mach_port_t *unprivportp) +x_bootstrap_get_self(job_t j, audit_token_t au_tok, mach_port_t *unprivportp) { - job_t j2, j = job_find_by_port(bp); struct ldcred ldc; + job_t j2; audit_token_to_launchd_cred(au_tok, &ldc); @@ -229,10 +229,9 @@ kern_return_t -x_bootstrap_check_in(mach_port_t bp, name_t servicename, audit_token_t au_tok, mach_port_t *serviceportp) +x_bootstrap_check_in(job_t j, name_t servicename, audit_token_t au_tok, mach_port_t *serviceportp) { static pid_t last_warned_pid = 0; - job_t j = job_find_by_port(bp); struct machservice *ms; struct ldcred ldc; @@ -267,11 +266,11 @@ } kern_return_t -x_bootstrap_register(mach_port_t bp, audit_token_t au_tok, name_t servicename, mach_port_t serviceport) +x_bootstrap_register(job_t j, audit_token_t au_tok, name_t servicename, mach_port_t serviceport) { - job_t j2, j = job_find_by_port(bp); struct machservice *ms; struct ldcred ldc; + job_t j2; audit_token_to_launchd_cred(au_tok, &ldc); @@ -316,9 +315,8 @@ } kern_return_t -x_bootstrap_look_up(mach_port_t bp, audit_token_t au_tok, name_t servicename, mach_port_t *serviceportp, mach_msg_type_name_t *ptype) +x_bootstrap_look_up(job_t j, audit_token_t au_tok, name_t servicename, mach_port_t *serviceportp, mach_msg_type_name_t *ptype) { - job_t j = job_find_by_port(bp); struct machservice *ms; struct ldcred ldc; @@ -347,10 +345,8 @@ } kern_return_t -x_bootstrap_parent(mach_port_t bp, mach_port_t *parentport, mach_msg_type_name_t *pptype) +x_bootstrap_parent(job_t j, mach_port_t *parentport, mach_msg_type_name_t *pptype) { - job_t j = job_find_by_port(bp); - job_log(j, LOG_DEBUG, "Requested parent bootstrap port"); j = job_get_bs(j); @@ -403,12 +399,12 @@ } kern_return_t -x_bootstrap_info(mach_port_t bp, name_array_t *servicenamesp, unsigned int *servicenames_cnt, +x_bootstrap_info(job_t j, name_array_t *servicenamesp, unsigned int *servicenames_cnt, bootstrap_status_array_t *serviceactivesp, unsigned int *serviceactives_cnt) { struct x_bootstrap_info_copyservices_cb info_resp = { NULL, NULL, NULL, NULL, 0 }; - job_t ji, j = job_find_by_port(bp); unsigned int cnt = 0; + job_t ji; for (ji = j; ji; ji = job_parent(ji)) job_foreach_service(ji, x_bootstrap_info_countservices, &cnt, false); @@ -446,13 +442,12 @@ } kern_return_t -x_bootstrap_transfer_subset(mach_port_t bp, mach_port_t *reqport, mach_port_t *rcvright, +x_bootstrap_transfer_subset(job_t j, mach_port_t *reqport, mach_port_t *rcvright, name_array_t *servicenamesp, unsigned int *servicenames_cnt, vm_offset_t *service_pids, mach_msg_type_number_t *service_pidsCnt, mach_port_array_t *ports, unsigned int *ports_cnt) { struct x_bootstrap_info_copyservices_cb info_resp = { NULL, NULL, NULL, NULL, 0 }; - job_t j = job_find_by_port(bp); unsigned int cnt = 0; if (getpid() != 1) { @@ -516,16 +511,15 @@ } kern_return_t -x_bootstrap_subset(mach_port_t bp, mach_port_t requestorport, mach_port_t *subsetportp) +x_bootstrap_subset(job_t j, mach_port_t requestorport, mach_port_t *subsetportp) { - job_t js, j = job_find_by_port(bp); int bsdepth = 0; + job_t js = j; - while ((j = job_parent(j)) != NULL) + while ((js = job_parent(js)) != NULL) { bsdepth++; + } - j = job_find_by_port(bp); - /* Since we use recursion, we need an artificial depth for subsets */ if (bsdepth > 100) { job_log(j, LOG_ERR, "Mach sub-bootstrap create request failed. Depth greater than: %d", bsdepth); @@ -544,9 +538,8 @@ } kern_return_t -x_bootstrap_create_service(mach_port_t bp, name_t servicename, mach_port_t *serviceportp) +x_bootstrap_create_service(job_t j, name_t servicename, mach_port_t *serviceportp) { - job_t j = job_find_by_port(bp); struct machservice *ms; if (job_prog(j)[0] == '\0') { @@ -577,9 +570,8 @@ } kern_return_t -x_mpm_wait(mach_port_t bp, mach_port_t srp, audit_token_t au_tok, integer_t *waitstatus) +x_mpm_wait(job_t j, mach_port_t srp, audit_token_t au_tok, integer_t *waitstatus) { - job_t j = job_find_by_port(bp); #if 0 struct ldcred ldc; audit_token_to_launchd_cred(au_tok, &ldc); @@ -588,10 +580,8 @@ } kern_return_t -x_mpm_uncork_fork(mach_port_t bp, audit_token_t au_tok) +x_mpm_uncork_fork(job_t j, audit_token_t au_tok) { - job_t j = job_find_by_port(bp); - if (!j) { return BOOTSTRAP_NOT_PRIVILEGED; } @@ -602,12 +592,12 @@ } kern_return_t -x_mpm_spawn(mach_port_t bp, audit_token_t au_tok, +x_mpm_spawn(job_t j, audit_token_t au_tok, _internal_string_t charbuf, mach_msg_type_number_t charbuf_cnt, uint32_t argc, uint32_t envc, uint64_t flags, uint16_t mig_umask, pid_t *child_pid, mach_port_t *obsvr_port) { - job_t jr, j = job_find_by_port(bp); + job_t jr; struct ldcred ldc; size_t offset = 0; char *tmpp; Modified: trunk/launchd/src/launchd_runtime.c =================================================================== --- trunk/launchd/src/launchd_runtime.c 2006-09-24 18:25:30 UTC (rev 22878) +++ trunk/launchd/src/launchd_runtime.c 2006-09-24 20:01:11 UTC (rev 22879) @@ -158,7 +158,7 @@ continue; } if (status.mps_msgcount) { - EV_SET(&kev, members[i], EVFILT_MACHPORT, 0, 0, 0, job_find_by_port(members[i])); + EV_SET(&kev, members[i], EVFILT_MACHPORT, 0, 0, 0, job_mig_intran(members[i])); (*((kq_callback *)kev.udata))(kev.udata, &kev); /* the callback may have tainted our ability to continue this for loop */ break; @@ -426,7 +426,7 @@ kern_return_t do_mach_notify_no_senders(mach_port_t notify, mach_port_mscount_t mscount) { - job_t j = job_find_by_port(notify); + job_t j = job_mig_intran(notify); /* This message is sent to us when the last customer of one of our * objects goes away.
participants (1)
-
source_changes@macosforge.org