# SA\_RESTART - signal - trap

**URL:** <https://rubytalk.org/t/sa-restart-signal-trap/4396>\
**Category:** ruby-talk\
**Created:** [29 January 2003 17:07 UTC](https://rubytalk.org/t/sa-restart-signal-trap/4396 "2003-01-29T17:07:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ara.T.Howard1](https://avatars.discourse-cdn.com/v4/letter/a/f19dbf/32.png) [@Ara.T.Howard1](https://rubytalk.org/u/Ara.T.Howard1)\
**Post date:** [29 January 2003 17:07 UTC](https://rubytalk.org/t/sa-restart-signal-trap/4396/1 "2003-01-29T17:07:00Z")

</div>

rubyists-

does anyone know how to specify SA\_RESTART in the signal mask such that  
interupted system calls are automatically restarted on solaris, as they are on  
linux?

-a

> **···**
>
> –
> 
> ====================================
> 
> > Ara Howard  
> > NOAA Forecast Systems Laboratory  
> > Information and Technology Services  
> > Data Systems Group  
> > R/FST 325 Broadway  
> > Boulder, CO 80305-3328  
> > Email: [ahoward@fsl.noaa.gov](mailto:ahoward@fsl.noaa.gov)  
> > Phone: 303-497-7238  
> > Fax: 303-497-7259  
> > ====================================

---

<div class="post-metadata">

**Author:** ![Nobuyoshi\_Nakada](https://avatars.discourse-cdn.com/v4/letter/n/edb3f5/32.png) [@Nobuyoshi\_Nakada](https://rubytalk.org/u/Nobuyoshi_Nakada)\
**Post date:** [29 January 2003 17:15 UTC](https://rubytalk.org/t/sa-restart-signal-trap/4396/2 "2003-01-29T17:15:24Z")

</div>

Hi,

> **···**
>
> At Thu, 30 Jan 2003 02:07:00 +0900, ahoward wrote:
> 
> > does anyone know how to specify SA\_RESTART in the signal mask such that  
> > interupted system calls are automatically restarted on solaris, as they are on  
> > linux?
> 
> If all of sigprocmask, sigaction and SA\_RESTART are available,  
> ruby always sets it.
> 
> –  
> Nobu Nakada

---

<div class="post-metadata">

**Author:** ![Ara.T.Howard1](https://avatars.discourse-cdn.com/v4/letter/a/f19dbf/32.png) [@Ara.T.Howard1](https://rubytalk.org/u/Ara.T.Howard1)\
**Post date:** [29 January 2003 18:27 UTC](https://rubytalk.org/t/sa-restart-signal-trap/4396/3 "2003-01-29T18:27:35Z")

</div>

if that is the case, then shouldn’t it be impossible for system calls to fail  
with EINTR? (see thread regarding solaris/flock for history)

-a

> **···**
>
> On Thu, 30 Jan 2003 [nobu.nokada@softhome.net](mailto:nobu.nokada@softhome.net) wrote:
> 
> > Hi,
> > 
> > At Thu, 30 Jan 2003 02:07:00 +0900, \> ahoward wrote:
> > 
> > > does anyone know how to specify SA\_RESTART in the signal mask such that  
> > > interupted system calls are automatically restarted on solaris, as they are on  
> > > linux?
> > 
> > If all of sigprocmask, sigaction and SA\_RESTART are available,  
> > ruby always sets it.
> 
> –
> 
> ====================================
> 
> > Ara Howard  
> > NOAA Forecast Systems Laboratory  
> > Information and Technology Services  
> > Data Systems Group  
> > R/FST 325 Broadway  
> > Boulder, CO 80305-3328  
> > Email: [ahoward@fsl.noaa.gov](mailto:ahoward@fsl.noaa.gov)  
> > Phone: 303-497-7238  
> > Fax: 303-497-7259  
> > ====================================

---

<div class="post-metadata">

**Author:** ![Joel\_VanderWerf1](https://avatars.discourse-cdn.com/v4/letter/j/94ad74/32.png) [@Joel\_VanderWerf1](https://rubytalk.org/u/Joel_VanderWerf1)\
**Post date:** [30 January 2003 22:09 UTC](https://rubytalk.org/t/sa-restart-signal-trap/4396/4 "2003-01-30T22:09:32Z")

</div>

ahoward wrote:

> > Hi,
> > 
> > > does anyone know how to specify SA\_RESTART in the signal mask such that  
> > > interupted system calls are automatically restarted on solaris, as they are on  
> > > linux?
> > 
> > If all of sigprocmask, sigaction and SA\_RESTART are available,  
> > ruby always sets it.
> 
> if that is the case, then shouldn’t it be impossible for system calls to fail  
> with EINTR? (see thread regarding solaris/flock for history)

I’m wondering too. I see this not only in Ara’s test code, but in my  
own, with heavy demand by threads and processes doing shared reads and  
exclusive writes. After getting all(?) my concurrency bugs out, I still  
had to put in a few “rescue Errno::EINTR; retry” statements, or else  
there would be some (very infrequent) failures. Interestingly, it only  
seems to happen during the shared reads, so it looks like something one  
thread is doing causes a system call in another thread to be interrupted.

Again, this is solaris only. Linux is fine.

> **···**
>
> > On Thu, 30 Jan 2003 [nobu.nokada@softhome.net](mailto:nobu.nokada@softhome.net) wrote:
> > 
> > > At Thu, 30 Jan 2003 02:07:00 +0900, \>\>ahoward wrote:

---

<div class="post-metadata">

**Author:** ![Nobuyoshi\_Nakada](https://avatars.discourse-cdn.com/v4/letter/n/edb3f5/32.png) [@Nobuyoshi\_Nakada](https://rubytalk.org/u/Nobuyoshi_Nakada)\
**Post date:** [30 January 2003 22:24 UTC](https://rubytalk.org/t/sa-restart-signal-trap/4396/5 "2003-01-30T22:24:43Z")

</div>

Hi,

> **···**
>
> At Fri, 31 Jan 2003 07:09:32 +0900, Joel VanderWerf wrote:
> 
> > > > > does anyone know how to specify SA\_RESTART in the signal mask such that  
> > > > > interupted system calls are automatically restarted on solaris, as they are on  
> > > > > linux?
> > > > 
> > > > If all of sigprocmask, sigaction and SA\_RESTART are available,  
> > > > ruby always sets it.  
> > > > if that is the case, then shouldn’t it be impossible for system  
> > > > calls to fail  
> > > > with EINTR? (see thread regarding solaris/flock for history)
> > 
> > I’m wondering too. I see this not only in Ara’s test code, but in my  
> > own, with heavy demand by threads and processes doing shared reads and  
> > exclusive writes. After getting all(?) my concurrency bugs out, I  
> > still had to put in a few “rescue Errno::EINTR; retry” statements, or  
> > else there would be some (very infrequent) failures. Interestingly, it  
> > only seems to happen during the shared reads, so it looks like  
> > something one thread is doing causes a system call in another thread  
> > to be interrupted.
> 
> In Solaris, it apparently needs to handle EINTR at every I/O  
> operations. Also fseek()?
> 
> # Index: file.c
> 
> RCS file: /cvs/ruby/src/ruby/file.c,v  
> retrieving revision 1.130  
> diff -u -2 -p -r1.130 file.c  
> — file.c 29 Jan 2003 23:28:47 -0000 1.130  
> +++ file.c 30 Jan 2003 22:21:47 -0000  
> @@ -1990,4 +1990,5 @@ rb\_file\_flock(obj, operation)  
> fflush(GetWriteFile(fptr));  
> }
> 
> - retry:  
> TRAP\_BEG;  
> ret = flock(fileno(fptr-\>f), NUM2INT(operation));  
> @@ -2001,4 +2002,9 @@ rb\_file\_flock(obj, operation)  
> #endif  
> return Qfalse;
> - 
> 
> ```
> case EINTR:
> 
> ```
> 
> +#if defined(ERESTART)
> 
> - 
> 
> ```
> case ERESTART:
> 
> ```
> 
> +#endif
> 
> - 
> 
> ```
> goto retry;
> }
> 
> ```
> 
> rb\_sys\_fail(fptr-\>path);
> 
> –  
> Nobu Nakada

---

<div class="post-metadata">

**Author:** ![Ara.T.Howard1](https://avatars.discourse-cdn.com/v4/letter/a/f19dbf/32.png) [@Ara.T.Howard1](https://rubytalk.org/u/Ara.T.Howard1)\
**Post date:** [31 January 2003 00:04 UTC](https://rubytalk.org/t/sa-restart-signal-trap/4396/6 "2003-01-31T00:04:11Z")

</div>

> In Solaris, it apparently needs to handle EINTR at every I/O  
> operations. Also fseek()?

i _think_ this is actually the case for _any_ system call on solaris - they  
are not automatically restarted as in linux by default. i’ve posted to  
comp.lang.unix.programmer regarding this, but i seem to find more knowledge on  
this list…

-a

> **···**
>
> On Fri, 31 Jan 2003 [nobu.nokada@softhome.net](mailto:nobu.nokada@softhome.net) wrote:
> 
> > # Index: file.c
> > 
> > RCS file: /cvs/ruby/src/ruby/file.c,v  
> > retrieving revision 1.130  
> > diff -u -2 -p -r1.130 file.c  
> > — file.c 29 Jan 2003 23:28:47 -0000 1.130  
> > +++ file.c 30 Jan 2003 22:21:47 -0000  
> > @@ -1990,4 +1990,5 @@ rb\_file\_flock(obj, operation)  
> > fflush(GetWriteFile(fptr));  
> > }
> > 
> > - retry:  
> > TRAP\_BEG;  
> > ret = flock(fileno(fptr-\>f), NUM2INT(operation));  
> > @@ -2001,4 +2002,9 @@ rb\_file\_flock(obj, operation)  
> > #endif  
> > return Qfalse;
> > - case EINTR:  
> > +#if defined(ERESTART)
> > - case ERESTART:  
> > +#endif
> > - 
> > 
> > ```
> > goto retry;
> > }
> > 
> > ```
> > 
> > rb\_sys\_fail(fptr-\>path);
> 
> –
> 
> ====================================
> 
> > Ara Howard  
> > NOAA Forecast Systems Laboratory  
> > Information and Technology Services  
> > Data Systems Group  
> > R/FST 325 Broadway  
> > Boulder, CO 80305-3328  
> > Email: [ahoward@fsl.noaa.gov](mailto:ahoward@fsl.noaa.gov)  
> > Phone: 303-497-7238  
> > Fax: 303-497-7259  
> > ====================================
