SA_RESTART

SA_RESTART

Post by Dirk Zabe » Sat, 29 Sep 2001 00:32:07



Hi,

I am trying to use a timer and SIGALRM to call some functions
time-dependent. I set sa_flags to SA_RESTART to automatically restart
interrupted system calls (see code below). But if my program is
blocked inside select when the timer fires, select aborts with
errno == -EINTR instead of being restarted. What ist wrong?

Thanks for any hint,

        Dirk

--------- code -----------------

struct sigaction sa_old;

void client_tmsinit(void)
{

  struct sigaction sa;

  sa.sa_handler = do_timer;
  sigemptyset(&sa.sa_mask);
  sa.sa_flags = SA_RESTART;
  sigaction(SIGALRM, &sa, &tms.sa_old);  

Quote:}

void prepare_next_alarm(unsigned long expires /* ms */)
{
  struct itimerval val;
  int n;

  if (tms.used_timer) {
    val.it_interval.tv_usec = 0;
    val.it_interval.tv_sec = 0;
    val.it_value.tv_usec = (expires % 1000) * 1000;
    val.it_value.tv_sec = expires/1000;
    n =  setitimer (ITIMER_REAL, &val, NULL);
    if (n<0) {
      perror("set_itimer");
    }
  }

Quote:}

 
 
 

SA_RESTART

Post by el.. » Sat, 29 Sep 2001 03:30:32




Quote:>I am trying to use a timer and SIGALRM to call some functions
>time-dependent. I set sa_flags to SA_RESTART to automatically restart
>interrupted system calls (see code below). But if my program is
>blocked inside select when the timer fires, select aborts with
>errno == -EINTR instead of being restarted. What ist wrong?

Just test the result and reissue the select.  SA_RESTART doesn't
handle all system calls.

--
http://www.spinics.net/linux/

 
 
 

SA_RESTART

Post by Dirk » Sat, 29 Sep 2001 06:24:48


Quote:>>I am trying to use a timer and SIGALRM to call some functions
>>time-dependent. I set sa_flags to SA_RESTART to automatically restart
>>interrupted system calls (see code below). But if my program is
>>blocked inside select when the timer fires, select aborts with
>>errno == -EINTR instead of being restarted. What ist wrong?

>Just test the result and reissue the select.  SA_RESTART doesn't
>handle all system calls.

OK, to put it this way: how do i know for sure, which system call
will be restarted and which one not?

Thanks
        Dirk

 
 
 

SA_RESTART

Post by Kasper Dupon » Sat, 29 Sep 2001 06:59:37



> >>I am trying to use a timer and SIGALRM to call some functions
> >>time-dependent. I set sa_flags to SA_RESTART to automatically restart
> >>interrupted system calls (see code below). But if my program is
> >>blocked inside select when the timer fires, select aborts with
> >>errno == -EINTR instead of being restarted. What ist wrong?

> >Just test the result and reissue the select.  SA_RESTART doesn't
> >handle all system calls.

> OK, to put it this way: how do i know for sure, which system call
> will be restarted and which one not?

> Thanks
>         Dirk

You could read the source code to see.

In order for a system call to be interrupted
it must go into interruptible sleep. When it
is waked up again it must check signals and
return an error if there has been a signal.
This error determines the behavior:

-ERESTARTNOHAND or -EINTR means that this
syscall will never be restarted.

-ERESTARTSYS means that this syscall will
be restarted if the SA_RESTART is set and
otherwise not.

-ERESTARTNOINTR means that this syscall will
always be restarted.

You could also write code that will handle
the EINTR error condition, just restart the
systemcall (and take the passed time into
account if the syscall involves a timeout
or a sleep for a specific time.)

--
Kasper Dupont

 
 
 

SA_RESTART

Post by michael kerris » Wed, 03 Oct 2001 19:16:40



> >>I am trying to use a timer and SIGALRM to call some functions
> >>time-dependent. I set sa_flags to SA_RESTART to automatically restart
> >>interrupted system calls (see code below). But if my program is
> >>blocked inside select when the timer fires, select aborts with
> >>errno == -EINTR instead of being restarted. What ist wrong?

> >Just test the result and reissue the select.  SA_RESTART doesn't
> >handle all system calls.

> OK, to put it this way: how do i know for sure, which system call
> will be restarted and which one not?

> Thanks
>         Dirk

A while back, I went through this exercise myself.  As I listed things in
the end, the following are restarted by SA_RESTART:

- wait(), waitpid(), wait3(), and wait4().

- read(), readv(), write(), writev(), and ioctl() when applied to "slow"
devices (e.g. terminal reads).

- Open() in cases where it can block (e.g., when opening FIFOs)

- Various sockets calls: accept(), connect(), send(), sendmsg(), recv(),
and recvmsg().

- fcntl() when used to apply file region locks

The following are not restarted:

- The poll() and select() I/O multiplexing calls.  (Under System V AFAIK,
these system calls are restarted if the SA_RESTART option is specified.)

- System V IPC: semop(), msgrcv(), and msgsnd().

This list is current and accurate for 2.2, and should be also for 2.4 (I
had a read of the 2.4 sources, but didn't do all the tests yet)

Cheers

Michael

 
 
 

SA_RESTART

Post by Michael Kerri » Wed, 03 Oct 2001 19:20:58



Quote:

>>>I am trying to use a timer and SIGALRM to call some functions
>>>time-dependent. I set sa_flags to SA_RESTART to automatically restart
>>>interrupted system calls (see code below). But if my program is
>>>blocked inside select when the timer fires, select aborts with
>>>errno == -EINTR instead of being restarted. What ist wrong?

>>Just test the result and reissue the select.  SA_RESTART doesn't
>>handle all system calls.

>OK, to put it this way: how do i know for sure, which system call
>will be restarted and which one not?

A while back, I went through this exercise myself.  As I listed things
in the end, the following are restarted by SA_RESTART:

- wait(), waitpid(), wait3(), and wait4().

- read(), readv(), write(), writev(), and ioctl() when applied to
"slow" devices (e.g. terminal reads).

- Open() in cases where it can block (e.g., when opening FIFOs)

- Various sockets calls: accept(), connect(), send(), sendmsg(),
recv(), and recvmsg().

- fcntl() when used to apply file region locks

The following are not restarted:

- The poll() and select() I/O multiplexing calls.  (Under System V
AFAIK, these system calls are restarted if the SA_RESTART option is
specified.)

- System V IPC: semop(), msgrcv(), and msgsnd().

This list is current and accurate for 2.2, and should be also for 2.4
(I had a read of the 2.4 sources, but didn't do all the tests yet)

Cheers

Michael

 
 
 

1. SA_RESTART

Hello,

I am using message queues in my program. I am also using sigaction and
setitimer.

setitimer() causes SIGALRM to be generated at regular intrevals. I use
sigaction to catch SIGALRM. However, if SIGALRM is generated in the
midst
of executing msgrcv(), msgrcv fails with EINTR.

After reading the man pages , I understand that if I set the SA_RESTART
flag in sigaction I will not have this problem. However, this does not
seem to work.

I am using Solaris 2.5.1. I am of the opinion that SA_RESTART does not
seem to be doing what its supposed to do. Am I correct? If so, can you
please tell me of another way to achieve what I want?

Thank you very much,
Bala

Sent via Deja.com http://www.deja.com/
Before you buy.

2. 32 and 64 bit libraries

3. SA_RESTART and Solaris 2.3/2.4 "select()"

4. Waking up Non-acpi (and non-apm) compliant IDE devices

5. SA_RESTART

6. TBS Montego Sound card

7. sleep() with SA_RESTART

8. 2.0.35: 3c900 locks up

9. SA_RESTART ... ?

10. SA_RESTART not interrupting select() on IRIX 6.5.6f

11. SA_RESTART signal handler, but read() still interrupted

12. Signal() sets SA_RESTART???

13. SA_RESTART flag of sigaction call