nanosleep() replacement

Tim Rice tim at multitalents.net
Tue Mar 18 04:28:03 EST 2003


On Mon, 17 Mar 2003, Darren Tucker wrote:

> Tim Rice wrote:
> > I put together a nanosleep() for systems without it.
> > 
> > Please review/test before I commit.
> 
> Before I forget, a couple of things I noticed while playing around with
> this:
> 
> [snip]
> > +       gettimeofday(&tsave, NULL);
> > +       rc = select(0, NULL, NULL, NULL, &time2wait);
> > +       if (rc) {
> 
> Checking for rc == -1, right?  Would "if (rc < 0)" be clearer?

Any non 0 means it didn't timeout.

> 
> > +               gettimeofday (&ttmp, NULL);
> 
> This can reset errno so (errno==EINTR) from select can be lost.

Opps. Good catch.

> > +               ttmp.tv_sec -= tsave.tv_sec;
> > +               ttmp.tv_usec -= tsave.tv_usec;
> > +               tsave.tv_sec = (time2wait.tv_sec - ttmp.tv_sec);
> > +               tsave.tv_usec = (time2wait.tv_usec - ttmp.tv_usec);
> > +               if(tsave.tv_sec < 0){
> > +                       tsave.tv_sec = 0;
> > +                       tsave.tv_usec += 1000000L;
> > +               }
> > +               rc = -1;
> > +       }
> > +
> > +       TIMEVAL_TO_TIMESPEC(&tsave, rem)
> 
> In the case where select returns normally, the remainder is whatever
> gettimeofday() returned which will be *way* bigger than the requested
> wait time and any possible remainder.

I wouldn't matter for how bwlimit() uses it, but your right, I should
have done that correctly. (I was too focused on making bwlimit() work)

> 
> > +       return(rc);
> [snip]

-- 
Tim Rice				Multitalents	(707) 887-1469
tim at multitalents.net




More information about the openssh-unix-dev mailing list