|
diff --git a/shared.c b/shared.c index 911a55a..4cb9573 100644 --- a/ shared.c+++ b/ shared.c |
|
@@ -380,16 +380,37 @@ int cgit_open_filter(struct cgit_filter *filter) |
380 | close(filter->pipe_fh[1]); |
380 | close(filter->pipe_fh[1]); |
381 | return 0; |
381 | return 0; |
382 | } |
382 | } |
383 | |
383 | |
384 | int cgit_close_filter(struct cgit_filter *filter) |
384 | int cgit_close_filter(struct cgit_filter *filter) |
385 | { |
385 | { |
386 | chk_non_negative(dup2(filter->old_stdout, STDOUT_FILENO), |
386 | chk_non_negative(dup2(filter->old_stdout, STDOUT_FILENO), |
387 | "Unable to restore STDOUT"); |
387 | "Unable to restore STDOUT"); |
388 | close(filter->old_stdout); |
388 | close(filter->old_stdout); |
389 | if (filter->pid < 0) |
389 | if (filter->pid < 0) |
390 | return 0; |
390 | return 0; |
391 | waitpid(filter->pid, &filter->exitstatus, 0); |
391 | waitpid(filter->pid, &filter->exitstatus, 0); |
392 | if (WIFEXITED(filter->exitstatus) && !WEXITSTATUS(filter->exitstatus)) |
392 | if (WIFEXITED(filter->exitstatus) && !WEXITSTATUS(filter->exitstatus)) |
393 | return 0; |
393 | return 0; |
394 | die("Subprocess %s exited abnormally", filter->cmd); |
394 | die("Subprocess %s exited abnormally", filter->cmd); |
395 | } |
395 | } |
| |
396 | |
| |
397 | /* Read the content of the specified file into a newly allocated buffer, |
| |
398 | * zeroterminate the buffer and return 0 on success, errno otherwise. |
| |
399 | */ |
| |
400 | int readfile(const char *path, char **buf, size_t *size) |
| |
401 | { |
| |
402 | int fd; |
| |
403 | struct stat st; |
| |
404 | |
| |
405 | fd = open(path, O_RDONLY); |
| |
406 | if (fd == -1) |
| |
407 | return errno; |
| |
408 | if (fstat(fd, &st)) |
| |
409 | return errno; |
| |
410 | if (!S_ISREG(st.st_mode)) |
| |
411 | return EISDIR; |
| |
412 | *buf = xmalloc(st.st_size + 1); |
| |
413 | *size = read_in_full(fd, *buf, st.st_size); |
| |
414 | (*buf)[*size] = '\0'; |
| |
415 | return (*size == st.st_size ? 0 : errno); |
| |
416 | } |
|