]> git.cameronkatri.com Git - cgit.git/blobdiff - shared.c
filter: make exit status local
[cgit.git] / shared.c
index 919a99ef6629549fd597aa8154f78737306f1d03..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)
@@ -404,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;
 }
 
@@ -458,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");
@@ -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);
 }