CodeSOD: A Select System Call

This post was originally published on this site

The Daily WTF

Way back in the 90s, in an era when Swedish pop bands were getting regular US radio play and CVS was the optimal source control system, Alan worked on a remote-execution service for a “Unix-like” OS. One of his co-workers had just left the company, and Alan needed to track down a bug in a module which the co-worker had more-or-less owned during their tenure.

The specific block of C code in question looked roughly like this:

int nsel, pty_fd, net_fd; fd_set rdset; . . . FD_ZERO(&rdset); FD_SET(pty_fd, &rdset); FD_SET(net_fd, &rdset); nsel = select(max(pty_fd, net_fd), &rdset, NULL, NULL, NULL);

Now, select is a system call, and it’s a bit of a weird one, and Alan assumed that was where the root issue lied. FD_SET is a built-in macro which adds a file descriptor to a set, so in this example, we expect to place two file descriptors

To read the full article click on the 'post' link at the top.