]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
Added execv_const() and execvp_const() helper functions.
authorTimo Sirainen <tss@iki.fi>
Fri, 26 Mar 2010 23:33:33 +0000 (01:33 +0200)
committerTimo Sirainen <tss@iki.fi>
Fri, 26 Mar 2010 23:33:33 +0000 (01:33 +0200)
--HG--
branch : HEAD

src/lib/Makefile.am
src/lib/execv-const.c [new file with mode: 0644]
src/lib/execv-const.h [new file with mode: 0644]

index 85b515d8acd8fab56063c25e79ec1ecf1b1f5804..b916ad805b2af8a60344f191fc580de1d851187d 100644 (file)
@@ -24,6 +24,7 @@ liblib_la_SOURCES = \
        data-stack.c \
        eacces-error.c \
        env-util.c \
+       execv-const.c \
        failures.c \
        fd-close-on-exec.c \
        fd-set-nonblock.c \
@@ -131,6 +132,7 @@ headers = \
        data-stack.h \
        eacces-error.h \
        env-util.h \
+       execv-const.h \
        failures.h \
        fd-close-on-exec.h \
        fd-set-nonblock.h \
diff --git a/src/lib/execv-const.c b/src/lib/execv-const.c
new file mode 100644 (file)
index 0000000..c89dcb6
--- /dev/null
@@ -0,0 +1,20 @@
+/* Copyright (c) 2010 Dovecot authors, see the included COPYING file */
+
+#include "lib.h"
+#include "execv-const.h"
+
+#include <unistd.h>
+
+void execv_const(const char *path, const char *const argv[])
+{
+       (void)execv(path, (void *)argv);
+       i_fatal_status(errno == ENOMEM ? FATAL_OUTOFMEM : FATAL_EXEC,
+                      "execv(%s) failed: %m", path);
+}
+
+void execvp_const(const char *file, const char *const argv[])
+{
+       (void)execvp(file, (void *)argv);
+       i_fatal_status(errno == ENOMEM ? FATAL_OUTOFMEM : FATAL_EXEC,
+                      "execvp(%s) failed: %m", file);
+}
diff --git a/src/lib/execv-const.h b/src/lib/execv-const.h
new file mode 100644 (file)
index 0000000..f112cec
--- /dev/null
@@ -0,0 +1,9 @@
+#ifndef EXECV_CONST_H
+#define EXECV_CONST_H
+
+/* Just like execv() and execvp(), except argv points to const strings.
+   Also if calling execv*() fails, these functions call i_fatal(). */
+void execv_const(const char *path, const char *const argv[]) ATTR_NORETURN;
+void execvp_const(const char *file, const char *const argv[]) ATTR_NORETURN;
+
+#endif