aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsinanmohd <sinan@sinanmohd.com>2024-07-09 23:41:48 +0530
committersinanmohd <sinan@sinanmohd.com>2024-07-09 23:47:07 +0530
commit9386c1f2519abd8b4351fc97419c41182389a1f6 (patch)
treee7b3d7f28839a00fe9a1ade63ccb394b3a209e0d /src
parent3c85d4765bc6592043c0dc5adfa377c3db51140b (diff)
util/vpopen: support for reading stderr
Diffstat (limited to 'src')
-rw-r--r--src/evanix.c6
-rw-r--r--src/jobs.c4
-rw-r--r--src/util.c14
3 files changed, 15 insertions, 9 deletions
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,
diff --git a/src/jobs.c b/src/jobs.c
index 096c97d..9ffe478 100644
--- a/src/jobs.c
+++ b/src/jobs.c
@@ -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;
}
diff --git a/src/util.c b/src/util.c
index 5001e01..95e5341 100644
--- a/src/util.c
+++ b/src/util.c
@@ -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;