aboutsummaryrefslogtreecommitdiffstats
path: root/shared.c
diff options
context:
space:
mode:
authorGravatar Lars Hjemli <hjemli@gmail.com>2011-05-24 06:28:38 (JST)
committerGravatar Lars Hjemli <hjemli@gmail.com>2011-05-24 06:28:38 (JST)
commitab350a77b1d3b0e251cc28329f2e16f0566e521e (patch)
tree1af2b0760858fcd87ce1e628465f9b60af7815e3 /shared.c
parent652a5a18db3b0409fedfaf8c5720446d87628ba0 (diff)
parentc2b58ed8539fcfa4f05cc9da316bbc782f4b8f10 (diff)
downloadcgit-ab350a77b1d3b0e251cc28329f2e16f0566e521e.zip
cgit-ab350a77b1d3b0e251cc28329f2e16f0566e521e.tar.gz
Merge branch 'fh/filter-api'
Conflicts: cgit.c
Diffstat (limited to 'shared.c')
-rw-r--r--shared.c32
1 files changed, 31 insertions, 1 deletions
diff --git a/shared.c b/shared.c
index 3778a5b..be2ae59 100644
--- a/shared.c
+++ b/shared.c
@@ -7,6 +7,8 @@
7 */ 7 */
8 8
9#include "cgit.h" 9#include "cgit.h"
10#include <stdio.h>
11#include <linux/limits.h>
10 12
11struct cgit_repolist cgit_repolist; 13struct cgit_repolist cgit_repolist;
12struct cgit_context ctx; 14struct cgit_context ctx;
@@ -367,7 +369,33 @@ int cgit_parse_snapshots_mask(const char *str)
367 return rv; 369 return rv;
368} 370}
369 371
370int cgit_open_filter(struct cgit_filter *filter) 372typedef struct {
373 char * name;
374 char * value;
375} cgit_env_var;
376
377static void prepare_env(struct cgit_repo * repo) {
378 cgit_env_var env_vars[] = {
379 { .name = "CGIT_REPO_URL", .value = repo->url },
380 { .name = "CGIT_REPO_NAME", .value = repo->name },
381 { .name = "CGIT_REPO_PATH", .value = repo->path },
382 { .name = "CGIT_REPO_OWNER", .value = repo->owner },
383 { .name = "CGIT_REPO_DEFBRANCH", .value = repo->defbranch },
384 { .name = "CGIT_REPO_SECTION", .value = repo->section },
385 { .name = "CGIT_REPO_CLONE_URL", .value = repo->clone_url }
386 };
387 int env_var_count = ARRAY_SIZE(env_vars);
388 cgit_env_var *p, *q;
389 static char *warn = "cgit warning: failed to set env: %s=%s\n";
390
391 p = env_vars;
392 q = p + env_var_count;
393 for (; p < q; p++)
394 if (setenv(p->name, p->value, 1))
395 fprintf(stderr, warn, p->name, p->value);
396}
397
398int cgit_open_filter(struct cgit_filter *filter, struct cgit_repo * repo)
371{ 399{
372 400
373 filter->old_stdout = chk_positive(dup(STDOUT_FILENO), 401 filter->old_stdout = chk_positive(dup(STDOUT_FILENO),
@@ -378,6 +406,8 @@ int cgit_open_filter(struct cgit_filter *filter)
378 close(filter->pipe_fh[1]); 406 close(filter->pipe_fh[1]);
379 chk_non_negative(dup2(filter->pipe_fh[0], STDIN_FILENO), 407 chk_non_negative(dup2(filter->pipe_fh[0], STDIN_FILENO),
380 "Unable to use pipe as STDIN"); 408 "Unable to use pipe as STDIN");
409 if (repo)
410 prepare_env(repo);
381 execvp(filter->cmd, filter->argv); 411 execvp(filter->cmd, filter->argv);
382 die("Unable to exec subprocess %s: %s (%d)", filter->cmd, 412 die("Unable to exec subprocess %s: %s (%d)", filter->cmd,
383 strerror(errno), errno); 413 strerror(errno), errno);