Diff options
Diffstat (limited to '')
-rw-r--r--source/filter.c35
-rw-r--r--source/shared.c21
-rw-r--r--source/shared.h8
3 files changed, 30 insertions, 34 deletions
diff --git a/source/filter.c b/source/filter.c
index c33e9bc..6cc5e80 100644
--- a/source/filter.c
+++ b/source/filter.c
@@ -25,6 +25,31 @@
// The exec filter holding stdout, for cgit_abort_filters to take it back.
static struct cgit_exec_filter *running_exec;
+/*
+ * Each of these returns its argument untouched when the syscall it wraps
+ * succeeded, and dies with the message and errno otherwise.
+ */
+static int die_unless_zero(int result, const char *msg)
+{
+ if (result != 0)
+ die_errno("%s", msg);
+ return result;
+}
+
+static int die_unless_positive(int result, const char *msg)
+{
+ if (result <= 0)
+ die_errno("%s", msg);
+ return result;
+}
+
+static int die_unless_non_negative(int result, const char *msg)
+{
+ if (result < 0)
+ die_errno("%s", msg);
+ return result;
+}
+
static int open_exec_filter(struct cgit_filter *base, va_list ap)
{
struct cgit_exec_filter *filter = (struct cgit_exec_filter *)base;
@@ -34,12 +59,12 @@ static int open_exec_filter(struct cgit_filter *base, va_list ap)
for (i = 0; i < filter->base.argument_count; i++)
filter->argv[i + 1] = va_arg(ap, char *);
- filter->old_stdout = cgit_die_unless_positive(dup(STDOUT_FILENO), "Unable to duplicate stdout");
+ filter->old_stdout = die_unless_positive(dup(STDOUT_FILENO), "Unable to duplicate stdout");
// The child keeps the page's stdout, but not the descriptor the parent
// needs it back from.
fcntl(filter->old_stdout, F_SETFD, FD_CLOEXEC);
- cgit_die_unless_zero(pipe(pipefd), "Unable to create pipe to subprocess");
- filter->pid = cgit_die_unless_non_negative(fork(), "Unable to create subprocess");
+ die_unless_zero(pipe(pipefd), "Unable to create pipe to subprocess");
+ filter->pid = die_unless_non_negative(fork(), "Unable to create subprocess");
if (filter->pid == 0) {
close(pipefd[1]);
if (dup2(pipefd[0], STDIN_FILENO) < 0)
@@ -55,7 +80,7 @@ static int open_exec_filter(struct cgit_filter *base, va_list ap)
_exit(EXEC_FAILED);
}
close(pipefd[0]);
- cgit_die_unless_non_negative(dup2(pipefd[1], STDOUT_FILENO), "Unable to use pipe as stdout");
+ die_unless_non_negative(dup2(pipefd[1], STDOUT_FILENO), "Unable to use pipe as stdout");
close(pipefd[1]);
running_exec = filter;
return 0;
@@ -67,7 +92,7 @@ static int close_exec_filter(struct cgit_filter *base)
int exit_status = 0;
running_exec = NULL;
- cgit_die_unless_non_negative(dup2(filter->old_stdout, STDOUT_FILENO), "Unable to restore stdout");
+ die_unless_non_negative(dup2(filter->old_stdout, STDOUT_FILENO), "Unable to restore stdout");
close(filter->old_stdout);
waitpid(filter->pid, &exit_status, 0);
if (!WIFEXITED(exit_status))
diff --git a/source/shared.c b/source/shared.c
index 183d085..c881fac 100644
--- a/source/shared.c
+++ b/source/shared.c
@@ -154,27 +154,6 @@ static char *expand_macro(char *name, size_t room)
return name + len;
}
-int cgit_die_unless_zero(int result, const char *msg)
-{
- if (result != 0)
- die_errno("%s", msg);
- return result;
-}
-
-int cgit_die_unless_positive(int result, const char *msg)
-{
- if (result <= 0)
- die_errno("%s", msg);
- return result;
-}
-
-int cgit_die_unless_non_negative(int result, const char *msg)
-{
- if (result < 0)
- die_errno("%s", msg);
- return result;
-}
-
struct cgit_repo *cgit_add_repo(const char *url)
{
struct cgit_repo *repo;
diff --git a/source/shared.h b/source/shared.h
index 2633a24..2397f67 100644
--- a/source/shared.h
+++ b/source/shared.h
@@ -17,14 +17,6 @@ typedef void (*filepair_fn)(struct diff_filepair *pair);
typedef void (*linediff_fn)(char *line, int len);
/*
- * Each of these returns its argument untouched when the syscall it wraps
- * succeeded, and dies with the message and errno otherwise.
- */
-extern int cgit_die_unless_zero(int result, const char *msg);
-extern int cgit_die_unless_positive(int result, const char *msg);
-extern int cgit_die_unless_non_negative(int result, const char *msg);
-
-/*
* Append a repository to cgit_repolist and return it, seeded from the current
* global configuration. The returned pointer is invalidated by the next call,
* because the list grows by reallocation.