Login
[x]
Log in using an account from:
Fedora Account System
Red Hat Associate
Red Hat Customer
Or login using a Red Hat Bugzilla account
Forgot Password
Login:
Hide Forgot
Create an Account
Red Hat Bugzilla – Attachment 1476411 Details for
Bug 1615467
Tee hangs with EAGAIN error when logging a telnet session
[?]
New
Simple Search
Advanced Search
My Links
Browse
Requests
Reports
Current State
Search
Tabular reports
Graphical reports
Duplicates
Other Reports
User Changes
Plotly Reports
Bug Status
Bug Severity
Non-Defaults
|
Product Dashboard
Help
Page Help!
Bug Writing Guidelines
What's new
Browser Support Policy
5.0.4.rh83 Release notes
FAQ
Guides index
User guide
Web Services
Contact
Legal
This site requires JavaScript to be enabled to function correctly, please enable it.
[patch]
[PATCH] tee: recover from EAGAIN returned from fwrite()
0001-tee-recover-from-EAGAIN-returned-from-fwrite.patch (text/plain), 2.53 KB, created by
Kamil Dudka
on 2018-08-16 11:56:18 UTC
(
hide
)
Description:
[PATCH] tee: recover from EAGAIN returned from fwrite()
Filename:
MIME Type:
Creator:
Kamil Dudka
Created:
2018-08-16 11:56:18 UTC
Size:
2.53 KB
patch
obsolete
>From 90e5a7248668555be2f42be43d6180a950651e46 Mon Sep 17 00:00:00 2001 >From: Kamil Dudka <kdudka@redhat.com> >Date: Thu, 16 Aug 2018 13:00:14 +0200 >Subject: [PATCH] tee: recover from EAGAIN returned from fwrite() > >tee expects the output descriptors to operate in blocking mode but this >assumption might be invalidated by other programs connected to the same >terminal, as in the following example: > >$ telnet ... | tee log_file > >telnet calls ioctl(stdin, FIONBIO, [1]), which causes the O_NONBLOCK >flag to be set on tee's output, which is connected to the same terminal. > >This patch has zero impact unless EAGAIN returns from fwrite(). In that >case we try to reset the O_NONBLOCK flag on the output file descriptor >and retry the call to fwrite(). >--- > src/tee.c | 42 +++++++++++++++++++++++++++++++++++++++++- > 1 file changed, 41 insertions(+), 1 deletion(-) > >diff --git a/src/tee.c b/src/tee.c >index e5165de..bd06d74 100644 >--- a/src/tee.c >+++ b/src/tee.c >@@ -128,6 +128,46 @@ main (int argc, char **argv) > exit (ok ? EXIT_SUCCESS : EXIT_FAILURE); > } > >+/* wrapper of fwrite() that tries to recover from EAGAIN caused by externally >+ set O_NONBLOCK flag on the output file descriptor */ >+static bool >+write_buf (const char *buf, ssize_t size, FILE *f) >+{ >+ int fwrite_errno; >+ int fd; >+ int flags; >+ >+ if (fwrite (buf, size, 1, f) == 1) >+ /* successful write */ >+ return true; >+ if (errno != EAGAIN) >+ /* non-recoverable write error */ >+ return false; >+ >+ /* preserve the original errno value in case our recovery attempt failed */ >+ fwrite_errno = errno; >+ >+ /* read file descriptor flags */ >+ fd = fileno (f); >+ if (fd == -1) >+ goto fail; >+ flags = fcntl (fd, F_GETFL); >+ if (flags == -1) >+ goto fail; >+ >+ /* reset the O_NONBLOCK flag on the file descriptor */ >+ flags &= ~O_NONBLOCK; >+ if (fcntl (fd, F_SETFL, flags) == -1) >+ goto fail; >+ >+ /* ... and try fwrite() once again in blocking mode */ >+ return (fwrite (buf, size, 1, f) == 1); >+ >+fail: >+ errno = fwrite_errno; >+ return false; >+} >+ > /* Copy the standard input into each of the NFILES files in FILES > and into the standard output. > Return true if successful. */ >@@ -191,7 +231,7 @@ tee_files (int nfiles, const char **files) > Standard output is the first one. */ > for (i = 0; i <= nfiles; i++) > if (descriptors[i] >- && fwrite (buffer, bytes_read, 1, descriptors[i]) != 1) >+ && !write_buf (buffer, bytes_read, descriptors[i])) > { > error (0, errno, "%s", files[i]); > descriptors[i] = NULL; >-- >1.8.3.1 >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 1615467
:
1476411
|
1476430
|
1501868