I hate UNIX

Today I found myself typing:

while (1)
{
[...]
int n = select (maxfd, &read_fds, NULL, &except_fds, NULL);
if (n < 0)
{ if (errno == EINTR)
// I hate UNIX.  Restart.
continue;
perror ("select failed");                                             
break;
}
}

9 thoughts on “I hate UNIX”

  1. I hate Win32 (otherwise known as Fail32)

    (for sommething similar to times(2) ):

    clock_t times(struct tms *buf)
    {
    BOOL r;
    FILETIME create, exit, kernel, user;
    ULARGE_INTEGER ulint;
    LARGE_INTEGER ticks;

    if(!buf)
    {
    errno= EINVAL;
    return -1;
    }

    r= GetProcessTimes(GetCurrentProcess(), &create, &exit, &kernel, &user);

    if(r==0)
    {
    errno= GetLastError();
    return -1;
    }
    ulint.LowPart= kernel.dwLowDateTime;
    ulint.HighPart= kernel.dwHighDateTime;
    buf->tms_stime= ulint.QuadPart;
    buf->tms_cstime= ulint.QuadPart;

    ulint.LowPart= user.dwLowDateTime;
    ulint.HighPart= user.dwHighDateTime;
    buf->tms_utime= ulint.QuadPart;
    buf->tms_cutime= ulint.QuadPart;

    if(QueryPerformanceCounter(&ticks)==0)
    {
    errno= GetLastError();
    return -1;
    }

    return ticks.QuadPart;
    }

    Because we really should have everything set up just in case we’re using a compiler without 64bit ints.
    No, this isn’t some old thing from 1990, APIs introduced with Vista have this.

  2. It’s actually quite perverse: at first, you feel somewhat smug that you don’t have to deal with this crap (we’re not in the 70’s anymore, right?), but then you realize that you need to stop a thread in its tracks, because a system call is stuck (say, something involving a network RPC). Remember the particular combination of NFS with the “hard,nointr” options? It’s kind of like that. Yeah, you never get an EINTR, but you don’t get a chance to recover either!

  3. Well, if you’re only working with Linux, then soon you’ll be able to use signalfd(2) and timerfd(2) to get signals and timers delivered on file descriptors, wait for them both with select(2), and have neither signals or timers interrupt said select().

    They’re both in 2.6.26. Just waiting for glibc support now…

Comments are closed.