public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jacky Malcles <Jacky.Malcles@bull.net>
To: linux-kernel@vger.kernel.org
Subject: (2.6.12) is there any reason for alarm() call to add 1 to the returned value?
Date: Tue, 21 Jun 2005 15:26:57 +0200	[thread overview]
Message-ID: <42B815A1.7090303@bull.net> (raw)

I've:
Linux version 2.6.12-rc6
LSB_VERSION="1.3"
Red Hat Enterprise Linux AS release 4 (Nahant)
Gnu C    gcc (GCC)     3.4.3 20041212 (Red Hat 3.4.3-9.EL4)
Gnu make               3.80
util-linux             2.12a
mount                  2.12a
modutils               3.1-pre5
e2fsprogs              1.35
pcmcia-cs              3.2.7
PPP                    2.4.2
isdn4k-utils           3.3
Linux C Library        2.3.4
Dynamic linker (ldd)   2.3.4

this behavior is new:
        alarm() does not return the number of seconds  remaining  until  any
       previously  scheduled  alarm was due to be delivered
  but
         it returns (the number of seconds  remaining + 1)
(with 2.6.10 and previous, 1 was not added to the returned value)


----------------------------------------------------------------------------------
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <errno.h>
#include <string.h>
#include <signal.h>

int almreceived = 0;            /* flag to indicate SIGALRM received or not */

void setup();                   /* Main setup function of test */
void sigproc(int sig);          /* signal catching function */

int
main(int ac, char **av)
{
         int time_sec1 = 10;     /* time for which 1st alarm is set */
         int time_sec2 = 5;      /* time for which 2st alarm is set */
         int ret_val1, ret_val2; /* return values for alarm() calls */
         int ret_val3;
         int sleep_time1 = 3;    /* waiting time for the signal */
         int sleep_time2 = 6;    /* waiting time for the signal */

         /* Perform global setup for test */
         setup();

                 /*
                  * Call First alarm() with non-zero time parameter
                  * 'time_sec1' to send SIGALRM to the calling process.
                  */
                 ret_val1 = (alarm(time_sec1));

                 /* Wait for signal SIGALARM */
                 sleep(sleep_time1);

                 /*
                  * Call Second alarm() with non-zero time parameter
                  * 'time_sec2' to send SIGALRM to the calling process.
                  */
                 ret_val2 = (alarm(time_sec2));

                 /* Wait for signal SIGALRM */
                 sleep(sleep_time2);

                 /*
                  * Check whether the second alarm() call returned
                  * the amount of time previously remaining in the
                  * alarm clock of the calling process, and
                  * sigproc() executed when SIGALRM received by the
                  * process, the variable almreceived is set.
                  */
                 printf("ret_val2 returned = %d \n",ret_val2);
                 printf("ret_val2 expected = %d\n",time_sec1 - sleep_time1);
                 if ((almreceived == 1) &&
                     (ret_val2 == (time_sec1 - sleep_time1))) {

                         /*
                          *  Make sure the system cleaned up the alarm
                          *  after it delivered it.
                          */
                         ret_val3 = (alarm(0));

                         if (ret_val3 != 0) {
                                 printf("System did not "
                                        "clean up delivered "
                                        "alarm");
                         } else {
                                 printf("Functionality of "
                                        "alarm(%u) successful",
                                         time_sec2);
                         }
                 } else {
                         printf("alarm(%u) fails, returned %d, "
                                "almreceived:%d",
                                time_sec2, ret_val2, almreceived);
                 }

         return 0;
         /*NOTREACHED*/
}
/*
  * sigproc(int) - This function defines the action that has to be taken
  *                when the SIGALRM signal is caught.
  *   It also sets the variable which is used to check whether the
  *   alarm system call was successful.
  */
void
sigproc(int sig)
{
         almreceived = almreceived + 1;
}

/*
  * setup() - performs all ONE TIME setup for this test.
  *  Setup the signal handler to catch SIGALRM.
  */
void
setup()
{
         if (signal(SIGALRM, sigproc) == SIG_ERR) {
                       printf("signal() fails to catch SIGALARM, errno=%d",
                          errno);
         }
}
-----------------------------------------------------------
result:
------
ret_val2 returned = 8
ret_val2 expected = 7

I'm interested knowing what is the expected behavior ...

many thanks,



-- 
  Jacky Malcles    	     B1-403   Email : Jacky.Malcles@bull.net
  Bull SA, 1 rue de Provence, B.P 208, 38432 Echirolles CEDEX, FRANCE
  Tel : 04.76.29.73.14

                 reply	other threads:[~2005-06-21 13:31 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=42B815A1.7090303@bull.net \
    --to=jacky.malcles@bull.net \
    --cc=linux-kernel@vger.kernel.org \
    /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