www.delorie.com/djgpp/bugs/show.cgi   search  
Bug 000271

When Created: 02/10/1999 04:00:17
Against DJGPP version: 2.02
By whom: vvs@auto.bnm.org
Abstract: setitimer bug
setitimer incorrectly sets timer to negative value
after first call to uclock(). Try example below:

#include <signal.h>
#include <sys/time.h>

volatile int flag = 0;

void timersig(int sig)
{
  flag++;
}

int main(void)
{
  struct itimerval timer;

  signal(SIGALRM, timersig);

  timer = (struct itimerval){{0, 0}, {5, 0}};
  setitimer(ITIMER_REAL, &timer, NULL);
  while(!flag)
    getitimer(ITIMER_REAL, &timer);
  flag--;
  timer = (struct itimerval){{0, 0}, {5, 0}};
  setitimer(ITIMER_REAL, &timer, NULL);
  while(!flag)
    getitimer(ITIMER_REAL, &timer);
  
  signal(SIGALRM, SIG_DFL);

  return(0);
}

Solution added: 02/10/1999 04:00:05
By whom: vvs@auto.bnm.org
Apply the following patch:

--- itimer.ori	Thu Jan  1 22:57:00 1998
+++ itimer.c	Wed Feb 10 11:06:56 1999
@@ -203,6 +203,9 @@
   *t_rel = value-> it_interval.tv_sec           * UCLOCKS_PER_SEC
     + (value->it_interval.tv_usec * 4096) / 3433;
 
+  if (*t_exp)
+    *t_exp += u_now;
+
   start_timer();
   return 0;
 }

Fixed in version on 02/10/1999 04:00:05
By whom: vvs@auto.bnm.org



  webmaster   donations   bookstore     delorie software   privacy  
  Copyright 2010   by DJ Delorie     Updated Jul 2010