summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_file.c
diff options
context:
space:
mode:
authorAndrew Clayton <a.clayton@nginx.com>2023-03-30 05:44:18 +0100
committerAndrew Clayton <a.clayton@nginx.com>2023-04-11 19:08:12 +0100
commit8b8952930c8462b5c56cdaf14e4a1c7c8b0c203d (patch)
treea9e8a452ab806cc6ac302ec22aa392b7d5d719e7 /src/nxt_file.c
parentedbc43558d40768d91b378205c2d52bd7ba9d00a (diff)
downloadunit-8b8952930c8462b5c56cdaf14e4a1c7c8b0c203d.tar.gz
unit-8b8952930c8462b5c56cdaf14e4a1c7c8b0c203d.tar.bz2
Add nxt_file_stdout().
This is analogous to the nxt_file_stderr() function and will be used in a subsequent commit. This function redirects stdout to a given file descriptor. Reviewed-by: Alejandro Colomar <alx@nginx.com> Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
Diffstat (limited to 'src/nxt_file.c')
-rw-r--r--src/nxt_file.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/nxt_file.c b/src/nxt_file.c
index a3fcda76..6f1a93e4 100644
--- a/src/nxt_file.c
+++ b/src/nxt_file.c
@@ -563,6 +563,25 @@ nxt_file_redirect(nxt_file_t *file, nxt_fd_t fd)
}
+/* nxt_file_stdout() redirects the stdout descriptor to the file. */
+
+nxt_int_t
+nxt_file_stdout(nxt_file_t *file)
+{
+ nxt_thread_log_debug("dup2(%FD, %FD, \"%FN\")",
+ file->fd, STDOUT_FILENO, file->name);
+
+ if (dup2(file->fd, STDOUT_FILENO) != -1) {
+ return NXT_OK;
+ }
+
+ nxt_thread_log_alert("dup2(%FD, %FD, \"%FN\") failed %E",
+ file->fd, STDOUT_FILENO, file->name, nxt_errno);
+
+ return NXT_ERROR;
+}
+
+
/* nxt_file_stderr() redirects the stderr descriptor to the file. */
nxt_int_t