[PATCH] libstddjb: add pathexec_run_or_die

From: Rasmus Villemoes <rv_at_rasmusvillemoes.dk>
Date: Wed, 17 May 2017 22:28:06 +0200

  pathexec_run(a, b, c);
  strerr_dieexec(111, a);

is a reasonably common pattern in execline programs, and since
strerr_dieexec expands to a 11 argument function call (of
strerr_diesys), this ends up generating a lot of code. Provide a
helper to do these two calls.
---
 src/include/skalibs/djbunix.h       |  1 +
 src/libstddjb/pathexec_run_or_die.c | 10 ++++++++++
 2 files changed, 11 insertions(+)
 create mode 100644 src/libstddjb/pathexec_run_or_die.c
diff --git a/src/include/skalibs/djbunix.h b/src/include/skalibs/djbunix.h
index fb08658..4568891 100644
--- a/src/include/skalibs/djbunix.h
+++ b/src/include/skalibs/djbunix.h
_at_@ -60,6 +60,7 @@ extern void pathexec_run (char const *, char const *const *, char const *const *
 extern void pathexec0_run (char const *const *, char const *const *) ;
 extern void pathexec (char const *const *) ;
 extern void pathexec0 (char const *const *) ;
+extern void pathexec_run_or_die (char const *, char const *const *, char const *const *) gccattr_noreturn ;
 
 #define prot_gid(gid) setgid(gid)
 #define prot_uid(uid) setuid(uid)
diff --git a/src/libstddjb/pathexec_run_or_die.c b/src/libstddjb/pathexec_run_or_die.c
new file mode 100644
index 0000000..a1fafc2
--- /dev/null
+++ b/src/libstddjb/pathexec_run_or_die.c
_at_@ -0,0 +1,10 @@
+/* ISC license. */
+
+#include <skalibs/djbunix.h>
+#include <skalibs/strerr2.h>
+
+void pathexec_run_or_die (char const *file, char const *const *argv, char const *const *envp)
+{
+  pathexec_run(file, argv, envp) ;
+  strerr_dieexec(111, file) ;
+}
-- 
2.1.4
Received on Wed May 17 2017 - 20:28:06 UTC

This archive was generated by hypermail 2.3.0 : Sun May 09 2021 - 19:38:49 UTC