Migrate to new launchpad API
Change-Id: If8ab10035726e952220fa6d997f8b2689bd36bc0
diff --git a/job.c b/job.c
index 34c65e2..c985a72 100644
--- a/job.c
+++ b/job.c
@@ -2298,17 +2298,12 @@
{
const int fdin = good_stdin ? FD_STDIN : get_bad_stdin ();
launchpad_t *lp = NULL;
- mx_handle_t child_job = MX_HANDLE_INVALID;
- mx_handle_t this_job = mx_job_default ();
mx_status_t status;
char *full_filename;
char *orig_exe_name = argv[0];
int argc;
- mx_handle_t result = -1;
-
- /* Copy privileges. */
- if (this_job != MX_HANDLE_INVALID)
- mx_handle_duplicate (this_job, MX_RIGHT_SAME_RIGHTS, &child_job);
+ mx_handle_t proc;
+ const char *errmsg;
full_filename = find_exe_file_location (argv[0], envp);
if (! full_filename)
@@ -2319,96 +2314,51 @@
argv[0] = full_filename;
- status = launchpad_create (child_job, argv[0], &lp);
- if (status != NO_ERROR)
- {
- free (full_filename);
- goto done_noalloc;
- }
-
- status = launchpad_file_load (lp, launchpad_vmo_from_file (argv[0]));
- if (status != NO_ERROR)
- goto done;
-
- status = launchpad_load_vdso (lp, MX_HANDLE_INVALID);
- if (status != NO_ERROR)
- goto done;
-
- status = launchpad_add_vdso_vmo (lp);
- if (status != NO_ERROR)
- goto done;
-
/* We have to tell launchpad how many arguments. */
for (argc = 0; argv[argc]; argc++)
;
-
- status = launchpad_arguments (lp, argc, (const char * const *) argv);
- if (status != NO_ERROR)
- goto done;
-
- status = launchpad_environ (lp, (const char * const *) envp);
- if (status != NO_ERROR)
- goto done;
-
- status = launchpad_clone_mxio_root (lp);
- if (status != NO_ERROR)
- goto done;
-
- status = launchpad_clone_mxio_cwd (lp);
- if (status != NO_ERROR)
- goto done;
+ launchpad_create (MX_HANDLE_INVALID, argv[0], &lp);
+ launchpad_load_from_file (lp, argv[0]);
+ launchpad_set_args (lp, argc, (const char * const *) argv);
+ launchpad_set_environ (lp, (const char * const *) envp);
+ launchpad_clone (lp, LP_CLONE_MXIO_ROOT | LP_CLONE_MXIO_CWD);
/* Copy descriptors, but don't make stdin available to the child. */
if (fdin >= 0 && fdin != FD_STDIN)
- status = launchpad_clone_fd (lp, fdin, FD_STDIN);
+ launchpad_clone_fd (lp, fdin, FD_STDIN);
else
- status = launchpad_clone_fd (lp, FD_STDIN, FD_STDIN);
-
- if (status != NO_ERROR)
- goto done;
+ launchpad_clone_fd (lp, FD_STDIN, FD_STDIN);
if (out && out->syncout)
{
if (out->out >= 0)
- status = launchpad_clone_fd (lp, out->out, FD_STDOUT);
+ launchpad_clone_fd (lp, out->out, FD_STDOUT);
else
- status = launchpad_clone_fd (lp, FD_STDOUT, FD_STDOUT);
-
- if (status != NO_ERROR)
- goto done;
+ launchpad_clone_fd (lp, FD_STDOUT, FD_STDOUT);
if (out->err >= 0)
- status = launchpad_clone_fd (lp, out->err, FD_STDERR);
+ launchpad_clone_fd (lp, out->err, FD_STDERR);
else
- status = launchpad_clone_fd (lp, FD_STDERR, FD_STDERR);
+ launchpad_clone_fd (lp, FD_STDERR, FD_STDERR);
}
else
{
- status = launchpad_clone_fd (lp, FD_STDOUT, FD_STDOUT);
- if (status != NO_ERROR)
- goto done;
-
- status = launchpad_clone_fd (lp, FD_STDERR, FD_STDERR);
+ launchpad_clone_fd (lp, FD_STDOUT, FD_STDOUT);
+ launchpad_clone_fd (lp, FD_STDERR, FD_STDERR);
}
- if (status == NO_ERROR)
- result = launchpad_start (lp);
-
-done:
- launchpad_destroy (lp);
+ status = launchpad_go (lp, &proc, &errmsg);
free (full_filename);
-done_noalloc:
argv[0] = orig_exe_name;
- if (status != NO_ERROR)
- OSN (error, NILF, _("launchpad: failure to launch command '%s' (%d)"),
- argv[0], status);
-
- if (result > 0)
- return (int) result;
- else
+ if (status == NO_ERROR) {
+ return (int) proc;
+ } else {
+ OSN (error, NILF, _("launchpad: failure to launch command '%s' (%s)"),
+ argv[0], errmsg);
return -1;
+ }
}
#elif !defined (_AMIGA) && !defined (__MSDOS__) && !defined (VMS)