public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* [PATCH] Make - use spawn() instead of fork() - 3rd version
@ 2013-08-08 13:29 Pavel Fedin
  0 siblings, 0 replies; only message in thread
From: Pavel Fedin @ 2013-08-08 13:29 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 553 bytes --]

 Hello!

 My previous message apparently was lost, so i repeat in case if someone
would like to test it.
 This is the latest version of the patch. It fixes problem with rebuilding
cygwin DLL, as well as follows some GNU Make maintainer recommendation
(extra security #ifndef). Please feel free to test and give feedbacks.
 I would really love to see this accepted.

 P.S. I tried to send this from my private email, but it did not get to any
recipient as it seems.

Kind regards,
Pavel Fedin
Expert Engineer
Samsung Electronics Research center Russia



[-- Attachment #2: make-3.82.90-1-use-spawn-on-cygwin.diff --]
[-- Type: application/octet-stream, Size: 5626 bytes --]

diff -ru make-3.82.90.orig/function.c make-3.82.90/function.c
--- make-3.82.90.orig/function.c	2011-12-02 20:35:49.000000000 +0400
+++ make-3.82.90/function.c	2013-08-06 18:34:59.154034700 +0500
@@ -1672,7 +1672,7 @@
       return o;
     }
 
-# ifdef __EMX__
+# if defined (__EMX__) || defined (__CYGWIN__)
   /* close some handles that are unnecessary for the child process */
   CLOSE_ON_EXEC(pipedes[1]);
   CLOSE_ON_EXEC(pipedes[0]);
diff -ru make-3.82.90.orig/job.c make-3.82.90/job.c
--- make-3.82.90.orig/job.c	2011-12-02 20:35:49.000000000 +0400
+++ make-3.82.90/job.c	2013-08-07 17:23:42.033300500 +0500
@@ -111,8 +111,11 @@
 # define WAIT_NOHANG 1
 #endif /* WINDOWS32 */
 
-#ifdef __EMX__
+#if defined (__EMX__) || defined (__CYGWIN__)
 # include <process.h>
+# ifndef P_NOWAIT
+#  define P_NOWAIT _P_NOWAIT
+# endif
 #endif
 
 #if defined (HAVE_SYS_WAIT_H) || defined (HAVE_UNION_WAIT)
@@ -1351,7 +1354,7 @@
 
       parent_environ = environ;
 
-# ifdef __EMX__
+# if defined (__EMX__) || defined (__CYGWIN__)
       /* If we aren't running a recursive command and we have a jobserver
          pipe, close it before exec'ing.  */
       if (!(flags & COMMANDS_RECURSE) && job_fds[0] >= 0)
@@ -1365,6 +1368,7 @@
       /* Never use fork()/exec() here! Use spawn() instead in exec_command() */
       child->pid = child_execute_job (child->good_stdin ? 0 : bad_stdin, 1,
                                       argv, child->environment);
+      environ = parent_environ;	/* Restore value child may have clobbered.  */
       if (child->pid < 0)
 	{
 	  /* spawn failed!  */
@@ -2071,7 +2075,7 @@
 #ifndef WINDOWS32
 
 /* EMX: Start a child process. This function returns the new pid.  */
-# if defined __EMX__
+# if defined (__EMX__) || defined (__CYGWIN__)
 int
 child_execute_job (int stdin_fd, int stdout_fd, char **argv, char **envp)
 {
@@ -2158,7 +2162,7 @@
    with environment ENVP.  This function does not return.  */
 
 /* EMX: This function returns the pid of the child process.  */
-# ifdef __EMX__
+# if defined (__EMX__) || defined (__CYGWIN__)
 int
 # else
 void
@@ -2236,14 +2240,24 @@
 
 #else  /* !WINDOWS32 */
 
-# ifdef __EMX__
+# if defined (__EMX__) || defined (__CYGWIN__)
   int pid;
 # endif
 
   /* Be the user, permanently.  */
   child_access ();
 
-# ifdef __EMX__
+#ifndef __EMX__
+  /* CHECKME: This applies child's environment to ourselves making it possible
+     to locate the program in child's PATH which includes current directory
+     (our original PATH does not). Original EMX code didn't do this, however
+     on Cygwin this caused problems (inability to run perl script inside current
+     build directory). This problem should affect EMX either, however unknown
+     for sure.  */
+  environ = envp;
+#endif
+
+# if defined (__EMX__) || defined (__CYGWIN__)
 
   /* Run the program.  */
   pid = spawnvpe (P_NOWAIT, argv[0], argv, envp);
@@ -2258,7 +2272,6 @@
 # else
 
   /* Run the program.  */
-  environ = envp;
   execvp (argv[0], argv);
 
 # endif /* !__EMX__ */
@@ -2318,7 +2331,7 @@
 	    --argc;
 	  }
 
-# ifdef __EMX__
+# if defined (__EMX__) || defined (__CYGWIN__)
 	pid = spawnvpe (P_NOWAIT, shell, new_argv, envp);
 	if (pid >= 0)
           break;
@@ -2344,7 +2357,7 @@
       break;
     }
 
-# ifdef __EMX__
+# if defined (__EMX__) || defined (__CYGWIN__)
   return pid;
 # else
   _exit (127);
diff -ru make-3.82.90.orig/job.h make-3.82.90/job.h
--- make-3.82.90.orig/job.h	2010-07-13 06:20:41.000000000 +0500
+++ make-3.82.90/job.h	2013-05-17 14:56:12.818896600 +0500
@@ -77,14 +77,14 @@
                                int cmd_flags, char** batch_file);
 #ifdef VMS
 int child_execute_job (char *argv, struct child *child);
-#elif defined(__EMX__)
+#elif defined(__EMX__) || defined (__CYGWIN__)
 int child_execute_job (int stdin_fd, int stdout_fd, char **argv, char **envp);
 #else
 void child_execute_job (int stdin_fd, int stdout_fd, char **argv, char **envp);
 #endif
 #ifdef _AMIGA
 void exec_command (char **argv);
-#elif defined(__EMX__)
+#elif defined(__EMX__) || defined (__CYGWIN__)
 int exec_command (char **argv, char **envp);
 #else
 void exec_command (char **argv, char **envp);
diff -ru make-3.82.90.orig/main.c make-3.82.90/main.c
--- make-3.82.90.orig/main.c	2011-12-02 20:35:49.000000000 +0400
+++ make-3.82.90/main.c	2013-08-07 18:19:59.983579600 +0500
@@ -38,7 +38,7 @@
 # include "sub_proc.h"
 # include "w32err.h"
 #endif
-#ifdef __EMX__
+#if defined (__EMX__) || defined (__CYGWIN__)
 # include <sys/types.h>
 # include <sys/wait.h>
 #endif
@@ -2207,7 +2207,7 @@
 #ifdef _AMIGA
 	  exec_command (nargv);
 	  exit (0);
-#elif defined (__EMX__)
+#elif defined (__EMX__) || defined(__CYGWIN__)
 	  {
 	    /* It is not possible to use execve() here because this
 	       would cause the parent process to be terminated with
@@ -2216,15 +2216,15 @@
 	       child process including all file handles and to wait for its
 	       termination. */
 	    int pid;
-	    int status;
+	    int child_status;
 	    pid = child_execute_job (0, 1, nargv, environ);
 
 	    /* is this loop really necessary? */
 	    do {
-	      pid = wait (&status);
+	      pid = wait (&child_status);
 	    } while (pid <= 0);
 	    /* use the exit code of the child process */
-	    exit (WIFEXITED(status) ? WEXITSTATUS(status) : EXIT_FAILURE);
+	    exit (WIFEXITED(child_status) ? WEXITSTATUS(child_status) : EXIT_FAILURE);
 	  }
 #else
 	  exec_command (nargv, environ);


[-- Attachment #3: Type: text/plain, Size: 218 bytes --]

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2013-08-08 13:29 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-08-08 13:29 [PATCH] Make - use spawn() instead of fork() - 3rd version Pavel Fedin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).