[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
mingw and execute vs. posix_spawn
From: |
Eric Blake |
Subject: |
mingw and execute vs. posix_spawn |
Date: |
Tue, 3 Mar 2009 16:44:05 +0000 (UTC) |
User-agent: |
Loom/3.14 (http://gmane.org/) |
Bruno, I've run into an issue trying to make m4 use the execute module. The
problem boils down to the fact that posix_spawn isn't ported to mingw yet[1].
Even though execute, pipe, and wait-process work just fine on mingw, the fact
that they pull in a dependency on posix_spawn on all other platforms means that
the build attempts to compile files, like lib/spawni.c or test-posix_spawn.c
that cause failures on mingw.
[1]http://lists.gnu.org/archive/html/bug-gnulib/2008-09/msg00373.html
My idea was to use an AM_CONDITIONAL to skip the attempts to compile anything
related to posix_spawn on mingw, for the benefit of programs (like m4) that
directly use execute but not posix_spawn. What do you think of this patch?
With it, I am finally able to get this to pass for mingw:
./gnulib-tool --with-tests --test execute pipe
while verifying no regressions in cygwin, which lacks posix_spawn but where the
gnulib posix_spawn replacement works.
Meanwhile, the mingw headers have a bug - POSIX requires that execve and
friends use 'char *const *', but mingw mistakenly declares them with 'const
char *const *'. Is it worth detecting this bug, and altering unistd.in.h to
define macros to avoid compiler warnings about incompatible pointer types?
gmane probably bothced line wrapping, so the patch is also at:
git pull git://repo.or.cz/gnulib/ericb.git master
From: Eric Blake <address@hidden>
Date: Tue, 3 Mar 2009 09:27:22 -0700
Subject: [PATCH] execute: avoid compilation problems on mingw
* m4/posix_spawn.m4 (gl_POSIX_SPAWN_CONDITION): New macro.
(gl_POSIX_SPAWN_BODY): Create an automake conditional, to avoid
posix_spawn files on platforms where they won't compile.
* modules/posix_spawn (configure.ac): Use new conditional.
* modules/posix_spawnp (configure.ac): Likewise.
* modules/posix_spawn-tests (Makefile.am): Likewise.
* modules/posix_spawnp-tests (Makefile.am): Likewise.
* lib/execute.c (execute) [_MSC_VER || __MINGW32__]: Avoid
compiler warning about incompatible types.
* lib/pipe.c (create_pipe) [_MSC_VER || __MINGW32__]: Likewise.
* lib/w32spawn.h (dup_noinherit): Use correct type in printf.
Signed-off-by: Eric Blake <address@hidden>
---
ChangeLog | 17 ++++++++++++++++-
lib/execute.c | 7 +++++--
lib/pipe.c | 7 +++++--
lib/w32spawn.h | 4 ++--
m4/posix_spawn.m4 | 24 ++++++++++++++++++++++--
modules/posix_spawn | 2 +-
modules/posix_spawn-tests | 2 ++
modules/posix_spawnp | 2 +-
modules/posix_spawnp-tests | 2 ++
9 files changed, 56 insertions(+), 11 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 3059649..354d2e7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2009-03-03 Eric Blake <address@hidden>
+
+ execute: avoid compilation problems on mingw
+ * m4/posix_spawn.m4 (gl_POSIX_SPAWN_CONDITION): New macro.
+ (gl_POSIX_SPAWN_BODY): Create an automake conditional, to avoid
+ posix_spawn files on platforms where they won't compile.
+ * modules/posix_spawn (configure.ac): Use new conditional.
+ * modules/posix_spawnp (configure.ac): Likewise.
+ * modules/posix_spawn-tests (Makefile.am): Likewise.
+ * modules/posix_spawnp-tests (Makefile.am): Likewise.
+ * lib/execute.c (execute) [_MSC_VER || __MINGW32__]: Avoid
+ compiler warning about incompatible types.
+ * lib/pipe.c (create_pipe) [_MSC_VER || __MINGW32__]: Likewise.
+ * lib/w32spawn.h (dup_noinherit): Use correct type in printf.
+
2009-03-03 Jim Meyering <address@hidden>
unlinkdir: cannot_unlink_dir may modify process state
diff --git a/lib/execute.c b/lib/execute.c
index c9f25b5..3bef9e7 100644
--- a/lib/execute.c
+++ b/lib/execute.c
@@ -154,14 +154,17 @@ execute (const char *progname,
copy of the environment block - ignoring the effects of putenv() and
[un]setenv(). */
{
- exitcode = spawnvpe (P_WAIT, prog_path, prog_argv, environ);
+ exitcode = spawnvpe (P_WAIT, prog_path, (const char * const*) prog_argv,
+ (const char * const*) environ);
if (exitcode < 0 && errno == ENOEXEC)
{
/* prog is not an native executable. Try to execute it as a
shell script. Note that prepare_spawn() has already prepended
a hidden element "sh.exe" to prog_argv. */
--prog_argv;
- exitcode = spawnvpe (P_WAIT, prog_argv[0], prog_argv, environ);
+ exitcode = spawnvpe (P_WAIT, prog_argv[0],
+ (const char* const*) prog_argv,
+ (const char* const*) environ);
}
}
if (nulloutfd >= 0)
diff --git a/lib/pipe.c b/lib/pipe.c
index d44f62e..10e253d 100644
--- a/lib/pipe.c
+++ b/lib/pipe.c
@@ -195,14 +195,17 @@ create_pipe (const char *progname,
copy of the environment block - ignoring the effects of putenv() and
[un]setenv(). */
{
- child = spawnvpe (P_NOWAIT, prog_path, prog_argv, environ);
+ child = spawnvpe (P_NOWAIT, prog_path, (const char* const*) prog_argv,
+ (const char* const*) environ);
if (child < 0 && errno == ENOEXEC)
{
/* prog is not an native executable. Try to execute it as a
shell script. Note that prepare_spawn() has already prepended
a hidden element "sh.exe" to prog_argv. */
--prog_argv;
- child = spawnvpe (P_NOWAIT, prog_argv[0], prog_argv, environ);
+ child = spawnvpe (P_NOWAIT, prog_argv[0],
+ (const char* const*) prog_argv,
+ (const char* const*) environ);
}
}
if (stdinfd >= 0)
diff --git a/lib/w32spawn.h b/lib/w32spawn.h
index 9ebf5bc..f4939fb 100644
--- a/lib/w32spawn.h
+++ b/lib/w32spawn.h
@@ -1,5 +1,5 @@
/* Auxiliary functions for the creation of subprocesses. Native Woe32 API.
- Copyright (C) 2003, 2006-2008 Free Software Foundation, Inc.
+ Copyright (C) 2003, 2006-2009 Free Software Foundation, Inc.
Written by Bruno Haible <address@hidden>, 2003.
This program is free software: you can redistribute it and/or modify
@@ -44,7 +44,7 @@ dup_noinherit (int fd)
(DWORD) 0, /* DesiredAccess */
FALSE, /* InheritHandle */
DUPLICATE_SAME_ACCESS)) /* Options */
- error (EXIT_FAILURE, 0, _("DuplicateHandle failed with error code 0x%08x"),
+ error (EXIT_FAILURE, 0, _("DuplicateHandle failed with error code 0x%
08lx"),
GetLastError ());
nfd = _open_osfhandle ((long) new_handle, O_BINARY);
diff --git a/m4/posix_spawn.m4 b/m4/posix_spawn.m4
index acf122d..9a1a85f 100644
--- a/m4/posix_spawn.m4
+++ b/m4/posix_spawn.m4
@@ -1,5 +1,5 @@
-# posix_spawn.m4 serial 4
-dnl Copyright (C) 2008 Free Software Foundation, Inc.
+# posix_spawn.m4 serial 5
+dnl Copyright (C) 2008, 2009 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
@@ -43,10 +43,30 @@ AC_DEFUN([gl_POSIX_SPAWN_BODY],
*) REPLACE_POSIX_SPAWN=1 ;;
esac
else
+ dnl For now, we have not ported this interface to native Woe32
+ dnl environments. However, if the application only uses the
+ dnl 'execute' or 'pipe' modules, this is not a fatal problem.
+ AC_CACHE_CHECK([whether posix_spawn can be simulated],
+ [gl_cv_func_posix_spawn_ported],
+ [AC_EGREP_CPP([notposix], [[
+#if defined _MSC_VER || defined __MINGW32__
+ notposix
+#endif
+ ]],
+ [gl_cv_func_posix_spawn_ported=no],
+ [gl_cv_func_posix_spawn_ported=yes])])
HAVE_POSIX_SPAWN=0
fi
+ AM_CONDITIONAL([NEED_POSIX_SPAWN], [gl_POSIX_SPAWN_CONDITION])
])
+dnl Codify the condition used by the automake conditional NEED_POSIX_SPAWN,
+dnl since we can't yet rely on Automake 1.11 AM_COND_IF.
+m4_define([gl_POSIX_SPAWN_CONDITION],
+[test $REPLACE_POSIX_SPAWN = 1 || {
+ test $HAVE_POSIX_SPAWN = 0 && test $gl_cv_func_posix_spawn_ported = yes
+}])
+
dnl Test whether posix_spawn actually works.
dnl posix_spawn on AIX 5.3..6.1 has two bugs:
dnl 1) When it fails to execute the program, the child process exits with
diff --git a/modules/posix_spawn b/modules/posix_spawn
index 4433119..cf32e60 100644
--- a/modules/posix_spawn
+++ b/modules/posix_spawn
@@ -11,7 +11,7 @@ posix_spawn-internal
configure.ac:
gl_POSIX_SPAWN
-if test $HAVE_POSIX_SPAWN = 0 || test $REPLACE_POSIX_SPAWN = 1; then
+if gl_POSIX_SPAWN_CONDITION; then
gl_REPLACE_SPAWN_H
AC_LIBOBJ([spawn])
gl_POSIX_SPAWN_INTERNAL
diff --git a/modules/posix_spawn-tests b/modules/posix_spawn-tests
index b34ea1d..faa60a0 100644
--- a/modules/posix_spawn-tests
+++ b/modules/posix_spawn-tests
@@ -12,5 +12,7 @@ sys_wait
configure.ac:
Makefile.am:
+if NEED_POSIX_SPAWN
TESTS += test-posix_spawn3
check_PROGRAMS += test-posix_spawn3
+endif NEED_POSIX_SPAWN
diff --git a/modules/posix_spawnp b/modules/posix_spawnp
index f78760c..ca0f660 100644
--- a/modules/posix_spawnp
+++ b/modules/posix_spawnp
@@ -11,7 +11,7 @@ posix_spawn-internal
configure.ac:
gl_POSIX_SPAWN
-if test $HAVE_POSIX_SPAWN = 0 || test $REPLACE_POSIX_SPAWN = 1; then
+if gl_POSIX_SPAWN_CONDITION; then
gl_REPLACE_SPAWN_H
AC_LIBOBJ([spawnp])
gl_POSIX_SPAWN_INTERNAL
diff --git a/modules/posix_spawnp-tests b/modules/posix_spawnp-tests
index 7c04580..0a3ce3b 100644
--- a/modules/posix_spawnp-tests
+++ b/modules/posix_spawnp-tests
@@ -22,6 +22,7 @@ sys_wait
configure.ac:
Makefile.am:
+if NEED_POSIX_SPAWN
TESTS += test-posix_spawn1 test-posix_spawn2
check_PROGRAMS += test-posix_spawn1 test-posix_spawn2
@@ -36,3 +37,4 @@ test-posix_spawn2.sh: test-posix_spawn2.in.sh
cp $(srcdir)/test-posix_spawn2.in.sh address@hidden
mv address@hidden $@
MOSTLYCLEANFILES += test-posix_spawn2.sh test-posix_spawn2.sh-t
+endif NEED_POSIX_SPAWN
--
1.6.1.2
- mingw and execute vs. posix_spawn,
Eric Blake <=