[Pkg-gpm-devel] Bug in GPM

Alexander E. Patrakov alexander at linuxfromscratch.org
Sat Sep 24 14:11:49 UTC 2005


Hello,

while debugging a case where w3m on the utf8-newmake LFS LiveCD stops 
responding to mouse events until I press a key, I found the bug in GPM.

The code, from src/lib/libcurses.c:

      do
        {
        FD_ZERO(&selSet);
        FD_SET(fd,&selSet);
        FD_SET(gpm_fd,&selSet);
        gpm_timeout.tv_sec=SELECT_TIME;
        flag=select(max+1,&selSet,(fd_set *)NULL,(fd_set 
*)NULL,&gpm_timeout);
        }
      while (!flag);

      if (FD_ISSET(fd,&selSet))
        return GET(win);

      if (flag==-1)
        continue;

For those who don't know: the return value of -1 from select() means 
that it was interrupted by a signal. In this case, at least with glibc 
from trunk (2.3.90), the return value from FD_ISSET is undefined. Thus, 
GET(win) can be called when there's no actual input. This results in the 
lockup until a key is pressed.

Solution: move the "if (flag==-1) continue;" statement above the 
FD_ISSET test. For the LiveCD this doesn't matter because gpm is 
compiled --without-curses there, but this fix found its way into 
http://www.linuxfromscratch.org/~alexander/patches/w3m-0.5.1-gpm_fix-1.patch

-- 
Alexander E. Patrakov



More information about the Pkg-gpm-devel mailing list