-
Notifications
You must be signed in to change notification settings - Fork 274
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enhancement #416 non blocking stdin #448
Conversation
While on BSD systems, tcprewrite likely sets `O_NDELAY` which is proper for most posix systems as this is the newer flag and they likely treat both similarly. However BSD and unix derivatives should likely utilize `FIONBIO` due to known issues with reading from tty with a 0 byte read returning -1 opposed to 0. Reference comment 1: https://stackoverflow.com/questions/1150635/unix-nonblocking-i-o-o-nonblock-vs-fionbio on behalf of Cisco Talos
Avoid non-blocking behaviour when using STDIN
src/tcprewrite.c
Outdated
@@ -149,6 +152,10 @@ main(int argc, char *argv[]) | |||
#ifdef ENABLE_DMALLOC | |||
dmalloc_shutdown(); | |||
#endif | |||
|
|||
/* avoid making STDIN non-blocking */ | |||
ioctl(0, FIONBIO, &nb); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dlangille some questions/comments
- PR Avoid non-blocking behaviour when using STDIN #416 has a compile issue fixed int this PR
- I don't understand why this is implemented just before the exiting the program.
- Is this fixing any particular issue?
- If so, should it not be applied to other
main()
procedures (e.g.tcpreplay
)?
I am pulling this PR out of 4.3 project until I receive clarification.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am relaying for the dev who found the issue.
tcprewrite (and likely tcpreplay see: https://stackoverflow.com/questions/16402363/read-fails-after-tcpreplay-with-error-0-resource-temporarily-unavailabl) sets STDIN as non-blocking and then doesn't set it back to blocking on exit, which causes reads to fail after exit. Example:
$ tcprewrite -C -i in.pcap -o out.pcap
$ cat > foo
cat: -: Resource temporarily unavailable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I applied your change to all executables. Thanks for the contribution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Much appreciated. Thanks for finding that other stuff.
No description provided.