Web lists-archives.com

return value of getitimer after an alarm




Hi-

There is an unusual behaviour with setitimer/getitimer and I'm not
sure if it is a bug or not.

Basically, if I call setitimer to set an SIGALRM, and then call
getitimer *after* the alarm goes off, I rather expect the time I
receive from getitimer should be {tv_sec = 0, tv_usec = 0}, but, in
fact, it_value is the negative of the unix timestamp.

Attached is a test case.

Thanks,
Mike Gran



#include <sys/time.h>
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/mman.h>

int loop = 1;

static void
handler(int sig, siginfo_t *si, void *unused)
{
  printf("Got SIGALRM at address: 0x%lx\n",
	 (long) si->si_addr);
  loop = 0;
}

int main(int argc, char **argv)
{

  struct sigaction sa;

  sa.sa_flags = SA_SIGINFO;
  sigemptyset(&sa.sa_mask);
  sa.sa_sigaction = handler;
  sigaction(SIGALRM, &sa, NULL);

  struct itimerval new_value, old_value;
  new_value.it_interval.tv_sec = 0;
  new_value.it_interval.tv_usec = 0;
  new_value.it_value.tv_sec = 0;
  new_value.it_value.tv_usec = 1000;
  setitimer(ITIMER_REAL, &new_value, &old_value);
  while (loop)
    ;
  printf("Loop is complete\n");
  int ret = getitimer(ITIMER_REAL, &old_value);
  printf("%d %ld %ld %ld %ld\n",
	 ret,
	 old_value.it_interval.tv_sec,
	 old_value.it_interval.tv_usec,
	 old_value.it_value.tv_sec,
	 old_value.it_value.tv_usec
	 );

  return 0;
}

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple