Skip to content
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

Merged
merged 5 commits into from
Jan 22, 2018

Conversation

fklassen
Copy link
Member

No description provided.

dlangille and others added 3 commits August 28, 2017 12:41
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);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dlangille some questions/comments

  1. PR Avoid non-blocking behaviour when using STDIN #416 has a compile issue fixed int this PR
  2. I don't understand why this is implemented just before the exiting the program.
  3. Is this fixing any particular issue?
  4. 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.

Copy link
Contributor

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Member Author

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.

Copy link
Contributor

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.

@fklassen fklassen merged commit e8d05fb into 4.3 Jan 22, 2018
@fklassen fklassen deleted the Enhancement_#416_non-blocking_STDIN branch January 22, 2018 16:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants