Move to new launchpad api.

(and fix a couple of whitespace issues)

Change-Id: I4f98ce9e369d97341db4fcfbe4d0aa9bcd3fce0d
diff --git a/patches/gcc-patch.txt b/patches/gcc-patch.txt
index 10d9355..e3598a5 100644
--- a/patches/gcc-patch.txt
+++ b/patches/gcc-patch.txt
@@ -1156,8 +1156,8 @@
       /* Find out the max path size.  */
       long path_max = pathconf ("/", _PC_PATH_MAX);
 diff -rdcp --unidirectional-new-file gcc-6.2.0-fsf/libiberty/pex-unix.c gcc-6.2.0/libiberty/pex-unix.c
-*** gcc-6.2.0-fsf/libiberty/pex-unix.c	2016-12-20 14:00:06.758830644 -0800
---- gcc-6.2.0/libiberty/pex-unix.c	2017-01-10 09:09:16.271408329 -0800
+*** gcc-6.2.0-fsf/libiberty/pex-unix.c	2017-03-02 15:29:41.979495096 -0800
+--- gcc-6.2.0/libiberty/pex-unix.c	2017-03-06 08:45:00.518152950 -0800
 *************** extern int errno;
 *** 60,65 ****
 --- 60,71 ----
@@ -1190,7 +1190,7 @@
 ! 
 ! static pid_t
 ! pex_wait (struct pex_obj *obj ATTRIBUTE_UNUSED, pid_t pid, int *status,
-!           struct pex_time *time ATTRIBUTE_UNUSED)
+! 	  struct pex_time *time ATTRIBUTE_UNUSED)
 ! {
 !   mx_status_t wait_result, procinfo_result;
 !   mx_info_process_t proc_info;
@@ -1237,9 +1237,26 @@
   /* Implementation of pex->exec_child using the Cygwin spawn operation.  */
   
   /* Subroutine of pex_unix_exec_child.  Move OLD_FD to a new file descriptor
+*************** static pid_t
+*** 492,498 ****
+  pex_unix_exec_child (struct pex_obj *obj ATTRIBUTE_UNUSED,
+  		     int flags, const char *executable,
+  		     char * const * argv, char * const * env,
+!                      int in, int out, int errdes, int toclose,
+  		     const char **errmsg, int *err)
+  {
+    int fl_in = 0, fl_out = 0, fl_err = 0, fl_tc = 0;
+--- 528,534 ----
+  pex_unix_exec_child (struct pex_obj *obj ATTRIBUTE_UNUSED,
+  		     int flags, const char *executable,
+  		     char * const * argv, char * const * env,
+! 		     int in, int out, int errdes, int toclose,
+  		     const char **errmsg, int *err)
+  {
+    int fl_in = 0, fl_out = 0, fl_err = 0, fl_tc = 0;
 *************** pex_unix_exec_child (struct pex_obj *obj
-*** 547,556 ****
---- 583,605 ----
+*** 547,552 ****
+--- 583,612 ----
       {
         typedef const char * const *cc_cp;
   
@@ -1251,18 +1268,52 @@
 + 	for (argc = 0; argv[argc]; argc++)
 + 	  ;
 + 
-+         /* TODO: Implement PATH search for PEX_SEARCH option.  */
-+         pid = launchpad_launch_mxio (executable, argc, argv);
++ 	/* TODO: Implement PATH search for PEX_SEARCH option.  */
++ 	launchpad_t *lp;
++ 	launchpad_create (MX_HANDLE_INVALID, executable, &lp);
++ 	launchpad_load_from_file (lp, executable);
++ 	launchpad_set_args (lp, argc, argv);
++ 	launchpad_clone (lp, LP_CLONE_ALL);
++ 	mx_handle_t handle;
++ 	mx_status_t status = launchpad_go (lp, &handle, errmsg);
++ 	if (status == NO_ERROR) {
++ 	  pid = (pid_t) handle;
++ 	  break;
++ 	}
++ 	*err = status;
++ 	return (pid_t) -1;
 +       }
 + #else
         if (flags & PEX_SEARCH)
   	pid = spawnvpe (_P_NOWAITO, executable, (cc_cp)argv, (cc_cp)env);
         else
-  	pid = spawnve (_P_NOWAITO, executable, (cc_cp)argv, (cc_cp)env);
+*************** pex_unix_exec_child (struct pex_obj *obj
+*** 560,565 ****
+--- 620,626 ----
+        if (errno != EAGAIN || ++retries == 4)
+  	return (pid_t) -1;
+        sleep (1 << retries);
 + #endif
+      }
   
-        if (pid > 0)
-  	break;
+    /* Success.  Restore the parent's file descriptors that we saved above.  */
+*************** pex_unix_exec_child (struct pex_obj *obj
+*** 590,596 ****
+  static pid_t
+  pex_unix_exec_child (struct pex_obj *obj, int flags, const char *executable,
+  		     char * const * argv, char * const * env,
+!                      int in, int out, int errdes,
+  		     int toclose, const char **errmsg, int *err)
+  {
+    pid_t pid;
+--- 651,657 ----
+  static pid_t
+  pex_unix_exec_child (struct pex_obj *obj, int flags, const char *executable,
+  		     char * const * argv, char * const * env,
+! 		     int in, int out, int errdes,
+  		     int toclose, const char **errmsg, int *err)
+  {
+    pid_t pid;
 diff -rdcp --unidirectional-new-file gcc-6.2.0-fsf/libiberty/stack-limit.c gcc-6.2.0/libiberty/stack-limit.c
 *** gcc-6.2.0-fsf/libiberty/stack-limit.c	2016-12-20 14:00:06.730830744 -0800
 --- gcc-6.2.0/libiberty/stack-limit.c	2017-01-10 14:58:25.856453718 -0800