]> git.cameronkatri.com Git - cgit.git/blobdiff - shared.c
filter: make exit status local
[cgit.git] / shared.c
index 10be35504dd7f110ef2f6db08dd47da08b81424e..6259d75d8841c26756aaf00d266940672b6162f3 100644 (file)
--- a/shared.c
+++ b/shared.c
@@ -1,6 +1,6 @@
 /* shared.c: global vars + some callback functions
  *
- * Copyright (C) 2006 Lars Hjemli
+ * Copyright (C) 2006-2014 cgit Development Team <cgit@lists.zx2c4.com>
  *
  * Licensed under GNU General Public License v2
  *   (see COPYING for full license text)
@@ -15,21 +15,21 @@ struct cgit_context ctx;
 int chk_zero(int result, char *msg)
 {
        if (result != 0)
-               die("%s: %s", msg, strerror(errno));
+               die_errno("%s", msg);
        return result;
 }
 
 int chk_positive(int result, char *msg)
 {
        if (result <= 0)
-               die("%s: %s", msg, strerror(errno));
+               die_errno("%s", msg);
        return result;
 }
 
 int chk_non_negative(int result, char *msg)
 {
        if (result < 0)
-               die("%s: %s", msg, strerror(errno));
+               die_errno("%s", msg);
        return result;
 }
 
@@ -63,6 +63,7 @@ struct cgit_repo *cgit_add_repo(const char *url)
        ret->enable_remote_branches = ctx.cfg.enable_remote_branches;
        ret->enable_subject_links = ctx.cfg.enable_subject_links;
        ret->max_stats = ctx.cfg.max_stats;
+       ret->branch_sort = ctx.cfg.branch_sort;
        ret->commit_sort = ctx.cfg.commit_sort;
        ret->module_link = ctx.cfg.module_link;
        ret->readme = ctx.cfg.readme;
@@ -403,28 +404,29 @@ void cgit_diff_commit(struct commit *commit, filepair_fn fn, const char *prefix)
 
 int cgit_parse_snapshots_mask(const char *str)
 {
+       struct string_list tokens = STRING_LIST_INIT_DUP;
+       struct string_list_item *item;
        const struct cgit_snapshot_format *f;
-       static const char *delim = " \t,:/|;";
-       int tl, sl, rv = 0;
+       int rv = 0;
 
        /* favor legacy setting */
        if (atoi(str))
                return 1;
-       for (;;) {
-               str += strspn(str, delim);
-               tl = strcspn(str, delim);
-               if (!tl)
-                       break;
+
+       string_list_split(&tokens, str, ' ', -1);
+       string_list_remove_empty_items(&tokens, 0);
+
+       for_each_string_list_item(item, &tokens) {
                for (f = cgit_snapshot_formats; f->suffix; f++) {
-                       sl = strlen(f->suffix);
-                       if ((tl == sl && !strncmp(f->suffix, str, tl)) ||
-                          (tl == sl - 1 && !strncmp(f->suffix + 1, str, tl - 1))) {
+                       if (!strcmp(item->string, f->suffix) ||
+                           !strcmp(item->string, f->suffix + 1)) {
                                rv |= f->bit;
                                break;
                        }
                }
-               str += tl;
        }
+
+       string_list_clear(&tokens, 0);
        return rv;
 }
 
@@ -457,7 +459,6 @@ void cgit_prepare_repo_env(struct cgit_repo * repo)
 
 int cgit_open_filter(struct cgit_filter *filter)
 {
-
        filter->old_stdout = chk_positive(dup(STDOUT_FILENO),
                "Unable to duplicate STDOUT");
        chk_zero(pipe(filter->pipe_fh), "Unable to create pipe to subprocess");
@@ -467,8 +468,7 @@ int cgit_open_filter(struct cgit_filter *filter)
                chk_non_negative(dup2(filter->pipe_fh[0], STDIN_FILENO),
                        "Unable to use pipe as STDIN");
                execvp(filter->cmd, filter->argv);
-               die("Unable to exec subprocess %s: %s (%d)", filter->cmd,
-                       strerror(errno), errno);
+               die_errno("Unable to exec subprocess %s", filter->cmd);
        }
        close(filter->pipe_fh[0]);
        chk_non_negative(dup2(filter->pipe_fh[1], STDOUT_FILENO),
@@ -479,13 +479,15 @@ int cgit_open_filter(struct cgit_filter *filter)
 
 int cgit_close_filter(struct cgit_filter *filter)
 {
+       int exit_status;
+
        chk_non_negative(dup2(filter->old_stdout, STDOUT_FILENO),
                "Unable to restore STDOUT");
        close(filter->old_stdout);
        if (filter->pid < 0)
                return 0;
-       waitpid(filter->pid, &filter->exitstatus, 0);
-       if (WIFEXITED(filter->exitstatus) && !WEXITSTATUS(filter->exitstatus))
+       waitpid(filter->pid, &exit_status, 0);
+       if (WIFEXITED(exit_status) && !WEXITSTATUS(exit_status))
                return 0;
        die("Subprocess %s exited abnormally", filter->cmd);
 }