public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: "Mike Gran via cygwin" <cygwin@cygwin.com>
To: cygwin@cygwin.com
Subject: return value of getitimer after an alarm
Date: Sun, 24 Feb 2019 09:15:00 -0000	[thread overview]
Message-ID: <20190224065837.GA14582@joshua.dnsalias.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 400 bytes --]

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




[-- Attachment #2: tmp.c --]
[-- Type: text/plain, Size: 1016 bytes --]

#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;
}


[-- Attachment #3: Type: text/plain, Size: 219 bytes --]


--
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

             reply	other threads:[~2019-02-24  6:58 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-24  9:15 Mike Gran via cygwin [this message]
2019-02-24 10:14 ` Corinna Vinschen
2019-02-24 17:27   ` Mike Gran via cygwin
2019-02-24 19:09     ` Corinna Vinschen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190224065837.GA14582@joshua.dnsalias.com \
    --to=cygwin@cygwin.com \
    --cc=spk121@yahoo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).