summaryrefslogtreecommitdiffstats
path: root/patches/0008-Use-gnulib-execute-module.patch
diff options
context:
space:
mode:
Diffstat (limited to 'patches/0008-Use-gnulib-execute-module.patch')
-rw-r--r--patches/0008-Use-gnulib-execute-module.patch114
1 files changed, 114 insertions, 0 deletions
diff --git a/patches/0008-Use-gnulib-execute-module.patch b/patches/0008-Use-gnulib-execute-module.patch
new file mode 100644
index 0000000..b609d41
--- /dev/null
+++ b/patches/0008-Use-gnulib-execute-module.patch
@@ -0,0 +1,114 @@
+From ff1d3a67da1e7f7af6a760ba5f0cee70763666da Mon Sep 17 00:00:00 2001
+From: Andreas Gruenbacher <agruen@gnu.org>
+Date: Fri, 6 Apr 2018 20:24:07 +0200
+Subject: [PATCH 08/17] Use gnulib execute module
+
+* bootstrap.conf (gnulib_modules): Add execute.
+* src/pch.c (do_ed_script): Switch from fork + execlp to execute.
+---
+ bootstrap.conf | 1 +
+ m4/.gitignore | 13 +++++++++++++
+ src/pch.c | 40 +++++++++++++++++++++-------------------
+ 3 files changed, 35 insertions(+), 19 deletions(-)
+
+diff --git a/bootstrap.conf b/bootstrap.conf
+index 47255fa..7c49a98 100644
+--- a/bootstrap.conf
++++ b/bootstrap.conf
+@@ -25,6 +25,7 @@ diffseq
+ dirname
+ dup2
+ errno
++execute
+ exitfail
+ extensions
+ faccessat
+diff --git a/m4/.gitignore b/m4/.gitignore
+index 9a94c0e..a84117a 100644
+--- a/m4/.gitignore
++++ b/m4/.gitignore
+@@ -275,3 +275,16 @@ xvasprintf.m4
+ /utime.m4
+ /utime_h.m4
+ /nstrftime.m4
++/execute.m4
++/fatal-signal.m4
++/posix_spawn.m4
++/rawmemchr.m4
++/sched_h.m4
++/sig_atomic_t.m4
++/sigaction.m4
++/signalblocking.m4
++/spawn_h.m4
++/strchrnul.m4
++/sys_wait_h.m4
++/wait-process.m4
++/waitpid.m4
+diff --git a/src/pch.c b/src/pch.c
+index 16e001a..1f14624 100644
+--- a/src/pch.c
++++ b/src/pch.c
+@@ -33,7 +33,8 @@
+ # include <io.h>
+ #endif
+ #include <safe.h>
+-#include <sys/wait.h>
++#include <alloca.h>
++#include "execute.h"
+
+ #define INITHUNKMAX 125 /* initial dynamic allocation size */
+
+@@ -2453,6 +2454,9 @@ do_ed_script (char const *inname, char const *outname,
+
+ if (! dry_run && ! skip_rest_of_patch) {
+ int exclusive = *outname_needs_removal ? 0 : O_EXCL;
++ char const **ed_argv;
++ int stdin_dup, status;
++
+ *outname_needs_removal = true;
+ if (inerrno != ENOENT)
+ {
+@@ -2461,24 +2465,22 @@ do_ed_script (char const *inname, char const *outname,
+ }
+ fflush (stdout);
+
+- pid = fork();
+- if (pid == -1)
+- pfatal ("Can't fork");
+- else if (pid == 0)
+- {
+- dup2 (tmpfd, 0);
+- assert (outname[0] != '!' && outname[0] != '-');
+- execlp (editor_program, editor_program, "-", outname, (char *) NULL);
+- _exit (2);
+- }
+- else
+- {
+- int wstatus;
+- if (waitpid (pid, &wstatus, 0) == -1
+- || ! WIFEXITED (wstatus)
+- || WEXITSTATUS (wstatus) != 0)
+- fatal ("%s FAILED", editor_program);
+- }
++ if ((stdin_dup = dup (0)) == -1
++ || dup2 (tmpfd, 0) == -1)
++ pfatal ("Failed to duplicate standard input");
++ assert (outname[0] != '!' && outname[0] != '-');
++ ed_argv = alloca (4 * sizeof * ed_argv);
++ ed_argv[0] = editor_program;
++ ed_argv[1] = "-";
++ ed_argv[2] = outname;
++ ed_argv[3] = (char *) NULL;
++ status = execute (editor_program, editor_program, (char **)ed_argv,
++ false, false, false, false, true, false, NULL);
++ if (status)
++ fatal ("%s FAILED", editor_program);
++ if (dup2 (stdin_dup, 0) == -1
++ || close (stdin_dup) == -1)
++ pfatal ("Failed to duplicate standard input");
+ }
+
+ fclose (tmpfp);
+--
+2.11.0
+