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

closing stdin on pipe #479

Closed
andreas-ibm opened this issue Aug 1, 2018 · 9 comments
Closed

closing stdin on pipe #479

andreas-ibm opened this issue Aug 1, 2018 · 9 comments
Assignees
Labels

Comments

@andreas-ibm
Copy link

May I request that someone checks their standard unix file descriptor numbers... from replay.c line 128:

    /* close stdin if reading from it (needed for some OS's) */
    if (strncmp(path, "-", 1) == 0)
        close(1);

(HINT: stdin is 0, 1 is stdout...)

@fklassen
Copy link
Member

fklassen commented Aug 1, 2018

Check for what?

@andreas-ibm
Copy link
Author

I was being sarcastic.

the block of code either doesn't do what's commented, or the comment is wrong.

The comment says "close stdin", the code closes stdout.

This has the effect of dropping all output from the command if you happen to be pipeing data to it via stdin. I've removed the block of code in my copy and it works much better.

I didn't simply send a PR, because I couldn't figure out the intent behind the code, I have a sneaky feeling that it's an attempted bugfix that might have inadvertently worked on "some OS" without the author of the code realising the unintended side effect. Changing the code to close(0) which would do as the comment says, but I believe would have very detrimental effects.

@fklassen fklassen self-assigned this Aug 1, 2018
@fklassen
Copy link
Member

fklassen commented Aug 1, 2018

Ahh ... I was looking at the code, not the comment. That code is well before my time, so I may have to guess at the intent. I'll schedule comment update for a future release.

@andreas-ibm
Copy link
Author

Could I suggest removing the whole block of code please? Closing stdout causes errors down the line when it tries to write (e.g. statistics) to stdout.

@fklassen
Copy link
Member

fklassen commented Aug 2, 2018

I'll review and test. We had some issues come up with stdin/stdout not being closed. I just want to make sure we are not introducing any regression.

@fklassen
Copy link
Member

See #416 and #470. Not a bug.

@andreas-ibm
Copy link
Author

I'd still argue it is a bug.
#416 introduced this change:

    /* avoid making STDIN non-blocking */
    int nb = 0;
    ioctl(0, FIONBIO, &nb)

Which indeed sets it to blocking mode using the old Unix way, but I fail to see how it relates to the current code:

    /* close stdin if reading from it (needed for some OS's) */
    if (strncmp(path, "-", 1) == 0)
        close(1);

a) I've never heard of an OS that needs you to close STDIN when reading from STDIN!
b) you're closing STDOUT

I honestly don't see the connection between #416, #470 and #479. #416 was a change to avoid non-blocking, that code is no-longer present in the codebase. #470 is asking that you set blocking mode prior to termination. Whilst #479 is merely a request that you stop closing STDOUT!

I don't use tcpreplay anymore as I've fixed my original problem in a different way, I'd still expect users of the code to be surprised when they don't get any output when passing it data on STDIN.

@fklassen
Copy link
Member

Appears I got STDIN/STDOUT confused. Reopening.

@fklassen fklassen reopened this Oct 24, 2018
@fklassen fklassen added bug and removed invalid labels Oct 24, 2018
fklassen added a commit that referenced this issue Oct 24, 2018
@fklassen
Copy link
Member

fixed in #510

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants