diff options
| author | Justus Winter <4winter@informatik.uni-hamburg.de> | 2013-08-03 10:48:43 +0200 |
|---|---|---|
| committer | Justus Winter <4winter@informatik.uni-hamburg.de> | 2013-08-03 10:48:43 +0200 |
| commit | d12419c78ebf815f039c5c90cd3a9f7c90e2be16 (patch) | |
| tree | 7a836e577a323918cbe67fc0ae384ba424c88d02 | |
| parent | 05637574b488bbcf2f558bb8612a35e6ae899ed7 (diff) | |
libfshelp: use bootstrap port handed to start-translator-long
If a bootstrap port is given in the ports array to
start-translator-long, use that one instead of allocating a new one.
The only users of start-translator-long are in libfshelp, and noone
relies on the old behavior, as the bootstrap port given is always
MACH_PORT_NULL, in which case the old behavior is retained.
* libfshelp/start-translator-long.c (start-translator-long): Use the
bootstrap port if one is given.
| -rw-r--r-- | start-translator-long.c | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/start-translator-long.c b/start-translator-long.c index 174fe97..69816c8 100644 --- a/start-translator-long.c +++ b/start-translator-long.c @@ -202,7 +202,7 @@ fshelp_start_translator_long (fshelp_open_fn_t underlying_open_fn, file_t executable; mach_port_t bootstrap = MACH_PORT_NULL; mach_port_t task = MACH_PORT_NULL; - mach_port_t prev_notify, proc, saveport, childproc; + mach_port_t prev_notify, proc, childproc; int ports_moved = 0; /* Find the translator itself. Since argz has zero-separated elements, we @@ -211,11 +211,17 @@ fshelp_start_translator_long (fshelp_open_fn_t underlying_open_fn, if (executable == MACH_PORT_NULL) return errno; - /* Create a bootstrap port for the translator. */ - err = - mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE, &bootstrap); - if (err) - goto lose; + if (ports[INIT_PORT_BOOTSTRAP] == MACH_PORT_NULL) + { + /* Create a bootstrap port for the translator. */ + err = + mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE, + &bootstrap); + if (err) + goto lose; + + ports[INIT_PORT_BOOTSTRAP] = bootstrap; + } /* Create the task for the translator. */ err = task_create (mach_task_self (), @@ -269,9 +275,6 @@ fshelp_start_translator_long (fshelp_open_fn_t underlying_open_fn, abort (); } - saveport = ports[INIT_PORT_BOOTSTRAP]; - ports[INIT_PORT_BOOTSTRAP] = bootstrap; - /* Try and exec the translator in TASK... */ err = file_exec (executable, task, EXEC_DEFAULTS, argz, argz_len, 0, 0, @@ -280,10 +283,6 @@ fshelp_start_translator_long (fshelp_open_fn_t underlying_open_fn, ints, ints_len, 0, 0, 0, 0); ports_moved = 1; - if (ports_type == MACH_MSG_TYPE_COPY_SEND) - mach_port_deallocate (mach_task_self (), bootstrap); - ports[INIT_PORT_BOOTSTRAP] = saveport; - if (err) { task_terminate (task); @@ -293,8 +292,11 @@ fshelp_start_translator_long (fshelp_open_fn_t underlying_open_fn, /* Ask to be told if TASK dies. */ err = mach_port_request_notification(mach_task_self(), - bootstrap, MACH_NOTIFY_NO_SENDERS, 0, - bootstrap, MACH_MSG_TYPE_MAKE_SEND_ONCE, + ports[INIT_PORT_BOOTSTRAP], + MACH_NOTIFY_NO_SENDERS, + 0, + ports[INIT_PORT_BOOTSTRAP], + MACH_MSG_TYPE_MAKE_SEND_ONCE, &prev_notify); if (err) return err; @@ -317,7 +319,10 @@ fshelp_start_translator_long (fshelp_open_fn_t underlying_open_fn, mach_port_deallocate (mach_task_self (), ports[i]); } if (bootstrap != MACH_PORT_NULL) - mach_port_destroy(mach_task_self(), bootstrap); + { + mach_port_destroy(mach_task_self(), bootstrap); + ports[INIT_PORT_BOOTSTRAP] = MACH_PORT_NULL; + } if (executable != MACH_PORT_NULL) mach_port_deallocate(mach_task_self(), executable); if (task != MACH_PORT_NULL) |
