On Sun, Sep 27, 2020 at 02:18:21PM -0600, Bob Beck wrote:
> On Sun, Sep 27, 2020 at 02:46:39PM +1000, Duncan Roe wrote:
> > The motivation for this is to make debug logs less confusing.
>
> What is this fixing and what behavior are you changing?

You can only see the difference when running nc under gdb, if you choose to
breakpoint those lines that set pfd[POLL_xxxxxx].fd to -1.

I was doing this because I wanted to track when file units got closed.
But sometimes an fd was getting set to -1 when it was -1 already, hence the
patch.

Loking at the patch again, I see that the first part of hunk 3 is unnecessary
so I'll send a v2.

Cheers ... Duncan.
>
> >
> > All changed lines have previously demonstrated the problem.
> >
> > Signed-off-by: Duncan Roe <[email protected]>
> > ---
> >  usr.bin/nc/netcat.c | 27 ++++++++++++++-------------
> >  1 file changed, 14 insertions(+), 13 deletions(-)
> >
> > diff --git a/usr.bin/nc/netcat.c b/usr.bin/nc/netcat.c
> > index 528dbeea678..b152cfaf635 100644
> > --- a/usr.bin/nc/netcat.c
> > +++ b/usr.bin/nc/netcat.c
> > @@ -1196,7 +1196,7 @@ readwrite(int net_fd, struct tls *tls_ctx)
> >                 !(pfd[POLL_NETIN].revents & POLLIN))
> >                     pfd[POLL_NETIN].fd = -1;
> >
> > -           if (pfd[POLL_NETOUT].revents & POLLHUP) {
> > +           if ((pfd[POLL_NETOUT].revents & POLLHUP) && pfd[POLL_NETOUT].fd 
> > != -1) {
> >                     if (Nflag)
> >                             shutdown(pfd[POLL_NETOUT].fd, SHUT_WR);
> >                     pfd[POLL_NETOUT].fd = -1;
> > @@ -1205,14 +1205,14 @@ readwrite(int net_fd, struct tls *tls_ctx)
> >             if (pfd[POLL_STDOUT].revents & POLLHUP)
> >                     pfd[POLL_STDOUT].fd = -1;
> >             /* if no net out, stop watching stdin */
> > -           if (pfd[POLL_NETOUT].fd == -1)
> > +           if (pfd[POLL_NETOUT].fd == -1 && pfd[POLL_STDIN].fd != -1)
> >                     pfd[POLL_STDIN].fd = -1;
> >             /* if no stdout, stop watching net in */
> > -           if (pfd[POLL_STDOUT].fd == -1) {
> > -                   if (pfd[POLL_NETIN].fd != -1)
> > -                           shutdown(pfd[POLL_NETIN].fd, SHUT_RD);
> > -                   pfd[POLL_NETIN].fd = -1;
> > -           }
> > +           if (pfd[POLL_STDOUT].fd == -1 &&
> > +               pfd[POLL_NETIN].fd != -1) {
> > +                       shutdown(pfd[POLL_NETIN].fd, SHUT_RD);
> > +                       pfd[POLL_NETIN].fd = -1;
> > +               }
> >
> >             /* try to read from stdin */
> >             if (pfd[POLL_STDIN].revents & POLLIN && stdinbufpos < BUFSIZE) {
> > @@ -1299,15 +1299,16 @@ readwrite(int net_fd, struct tls *tls_ctx)
> >             }
> >
> >             /* stdin gone and queue empty? */
> > -           if (pfd[POLL_STDIN].fd == -1 && stdinbufpos == 0) {
> > -                   if (pfd[POLL_NETOUT].fd != -1 && Nflag)
> > -                           shutdown(pfd[POLL_NETOUT].fd, SHUT_WR);
> > +           if (pfd[POLL_STDIN].fd == -1 && stdinbufpos == 0 &&
> > +               pfd[POLL_NETOUT].fd != -1) {
> > +                       if (Nflag)
> > +                               shutdown(pfd[POLL_NETOUT].fd, SHUT_WR);
> >                     pfd[POLL_NETOUT].fd = -1;
> >             }
> >             /* net in gone and queue empty? */
> > -           if (pfd[POLL_NETIN].fd == -1 && netinbufpos == 0) {
> > -                   pfd[POLL_STDOUT].fd = -1;
> > -           }
> > +           if (pfd[POLL_NETIN].fd == -1 && netinbufpos == 0 &&
> > +               pfd[POLL_STDOUT].fd != -1)
> > +                       pfd[POLL_STDOUT].fd = -1;
> >     }
> >  }
> >
> > --
> > 2.17.5
> >

Reply via email to