/* 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)
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;
}
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;
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;
}
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");
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),
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);
}