diff options
Diffstat (limited to 'shared.c')
-rw-r--r-- | shared.c | 32 |
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 | ||
11 | struct cgit_repolist cgit_repolist; | 13 | struct cgit_repolist cgit_repolist; |
12 | struct cgit_context ctx; | 14 | struct 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 | ||
370 | int cgit_open_filter(struct cgit_filter *filter) | 372 | typedef struct { |
373 | char * name; | ||
374 | char * value; | ||
375 | } cgit_env_var; | ||
376 | |||
377 | static 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 | |||
398 | int 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); |