aboutsummaryrefslogtreecommitdiff
path: root/contrib/libarchive/test_utils/test_main.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/libarchive/test_utils/test_main.c')
-rw-r--r--contrib/libarchive/test_utils/test_main.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/contrib/libarchive/test_utils/test_main.c b/contrib/libarchive/test_utils/test_main.c
index f4d443060d88..f31678166ad0 100644
--- a/contrib/libarchive/test_utils/test_main.c
+++ b/contrib/libarchive/test_utils/test_main.c
@@ -84,6 +84,18 @@
#if HAVE_MEMBERSHIP_H
#include <membership.h>
#endif
+#if !defined(_WIN32) || defined(__CYGWIN__)
+# if HAVE_POSIX_SPAWN
+# if HAVE_SYS_WAIT_H
+# include <sys/wait.h>
+# endif
+# if HAVE_SPAWN_H
+# include <spawn.h>
+# endif
+extern char **environ;
+# define USE_POSIX_SPAWN 1
+# endif
+#endif
#ifndef nitems
#define nitems(arr) (sizeof(arr) / sizeof((arr)[0]))
@@ -3009,15 +3021,28 @@ int
systemf(const char *fmt, ...)
{
char buff[8192];
+#if USE_POSIX_SPAWN
+ char *argv[] = { "/bin/sh", "-c", buff, NULL };
+ pid_t pid;
+#endif
va_list ap;
int r;
va_start(ap, fmt);
vsnprintf(buff, sizeof(buff), fmt, ap);
+ va_end(ap);
if (verbosity > VERBOSITY_FULL)
logprintf("Cmd: %s\n", buff);
+#if USE_POSIX_SPAWN
+ if ((r = posix_spawn(&pid, *argv, NULL, NULL, argv, environ)) == 0) {
+ while (waitpid(pid, &r, 0) == -1) {
+ if (errno != EINTR)
+ return (-1);
+ }
+ }
+#else
r = system(buff);
- va_end(ap);
+#endif
return (r);
}