diff options
author | sinanmohd <sinan@sinanmohd.com> | 2024-07-09 23:41:48 +0530 |
---|---|---|
committer | sinanmohd <sinan@sinanmohd.com> | 2024-07-09 23:47:07 +0530 |
commit | 9386c1f2519abd8b4351fc97419c41182389a1f6 (patch) | |
tree | e7b3d7f28839a00fe9a1ade63ccb394b3a209e0d | |
parent | 3c85d4765bc6592043c0dc5adfa377c3db51140b (diff) |
util/vpopen: support for reading stderr
-rw-r--r-- | include/evanix.h | 2 | ||||
-rw-r--r-- | include/util.h | 8 | ||||
-rw-r--r-- | src/evanix.c | 6 | ||||
-rw-r--r-- | src/jobs.c | 4 | ||||
-rw-r--r-- | src/util.c | 14 |
5 files changed, 23 insertions, 11 deletions
diff --git a/include/evanix.h b/include/evanix.h index 48fe110..1e24590 100644 --- a/include/evanix.h +++ b/include/evanix.h @@ -7,7 +7,7 @@ struct evanix_opts_t { bool isflake; bool isdryrun; bool ispipelined; - bool close_stderr_exec; + bool close_unused_fd; char *system; uint32_t max_build; }; diff --git a/include/util.h b/include/util.h index 7c15354..1ffe148 100644 --- a/include/util.h +++ b/include/util.h @@ -13,7 +13,13 @@ (cur) = (next); \ } +typedef enum { + VPOPEN_STDERR, + VPOPEN_STDOUT +} vpopen_t; + +int vpopen(FILE **stream, const char *file, char *const argv[], vpopen_t type); + int json_streaming_read(FILE *stream, cJSON **json); -int vpopen(FILE **stream, const char *file, char *const argv[]); int atob(const char *s); int run(const char *file, char *argv[]); diff --git a/src/evanix.c b/src/evanix.c index cd35782..b801e73 100644 --- a/src/evanix.c +++ b/src/evanix.c @@ -17,11 +17,11 @@ static const char usage[] = " -s, --system System to build for.\n" " -m, --max-build Max number of builds.\n" " -p, --pipelined <bool> Use evanix build pipeline.\n" - " -c, --close-stderr-exec <bool> Close stderr on exec.\n" + " -c, --close-unused-fd <bool> Close stderr on exec.\n" "\n"; struct evanix_opts_t evanix_opts = { - .close_stderr_exec = true, + .close_unused_fd = true, .isflake = false, .ispipelined = true, .isdryrun = false, @@ -164,7 +164,7 @@ int main(int argc, char *argv[]) exit(EXIT_FAILURE); } - evanix_opts.close_stderr_exec = ret; + evanix_opts.close_unused_fd = ret; break; default: fprintf(stderr, @@ -257,7 +257,7 @@ int job_read(FILE *stream, struct job **job) temp = cJSON_GetObjectItemCaseSensitive(root, "error"); if (cJSON_IsString(temp)) { - if (evanix_opts.close_stderr_exec) + if (evanix_opts.close_unused_fd) puts(temp->valuestring); ret = JOB_READ_EVAL_ERR; goto out_free; @@ -463,7 +463,7 @@ int jobs_init(FILE **stream, char *expr) args[argindex++] = NULL; /* the package is wrapProgram-ed with nix-eval-jobs */ - ret = vpopen(stream, XSTR(NIX_EVAL_JOBS_PATH), args); + ret = vpopen(stream, XSTR(NIX_EVAL_JOBS_PATH), args, VPOPEN_STDOUT); return ret; } @@ -42,7 +42,7 @@ out_free_line: return ret; } -int vpopen(FILE **stream, const char *file, char *const argv[]) +int vpopen(FILE **stream, const char *file, char *const argv[], vpopen_t type) { int fd[2], ret; int nullfd = -1; @@ -72,19 +72,25 @@ int vpopen(FILE **stream, const char *file, char *const argv[]) } close(fd[0]); - ret = dup2(fd[1], STDOUT_FILENO); + if (type == VPOPEN_STDOUT) + ret = dup2(fd[1], STDOUT_FILENO); + else + ret = dup2(fd[1], STDERR_FILENO); if (ret < 0) { print_err("%s", strerror(errno)); goto out_close_fd_1; } - if (evanix_opts.close_stderr_exec) { + if (evanix_opts.close_unused_fd) { nullfd = open("/dev/null", O_WRONLY); if (nullfd < 0) { print_err("%s", strerror(errno)); goto out_close_fd_1; } - ret = dup2(nullfd, STDERR_FILENO); + if (type == VPOPEN_STDOUT) + ret = dup2(nullfd, STDERR_FILENO); + else + ret = dup2(nullfd, STDOUT_FILENO); if (ret < 0) { print_err("%s", strerror(errno)); goto out_close_nullfd; |