[comp.unix.internals] sigblock,sigmask,sigsetmask ... for SYS V?

hpn@regentdb.osrhe.uoknor.edu (Huy Nguyen / (405) 721-3798) (06/22/91)

Does anyone know of a library package, hacks, etc to emulate these BSD
signal routines for SYS V?  

Huy Nguyen
hpn@regentdb.osrhe.uoknor.edu

srp@babar.mmwb.ucsf.edu (Scott R. Presnell%Cohen) (06/23/91)

hpn@regentdb.osrhe.uoknor.edu (Huy Nguyen / (405) 721-3798) writes:

>Does anyone know of a library package, hacks, etc to emulate these BSD
>signal routines for SYS V?  

>Huy Nguyen
>hpn@regentdb.osrhe.uoknor.edu

I've used the following in the past as a quick hack (NSIG can usually be
found in /usr/include/sys/signals.h):

/* Mask of held signals */
static int sigheld = 0;

int sigblock (sigs)
int sigs;
{
  int i,old;
  for (i = 0; i < NSIG; i++)
    if (sigs & sigbit (i))
  sighold (i);
  old = sigheld;
  sigheld |= sigs;
  return(old);
}

sigsetmask(sigset)
int sigset;
{
  int newheld,newrel,tmp;
  newheld = sigset & ~sigheld;
  newrel = sigheld & ~sigset;
  tmp = sigblock(newheld);
  sigfree(newrel);
}

sigfree (sigs) 
int sigs;
{
  int i;
  for (i = 0; i < NSIG; i++)
    if (sigs & sigbit (i))
      sigrelse (i);
  sigheld &= ~sigs;
}

sigbit (i)
int i;
{
  return 1 << (i - 1);
}


	Hope this helps.

	- Scott Presnell (srp@cgl.ucsf.edu)
--
Scott Presnell				        +1 (415) 476-9890
Pharm. Chem., S-926				Internet: srp@cgl.ucsf.edu
University of California			UUCP: ...ucbvax!ucsfcgl!srp
San Francisco, CA. 94143-0446			Bitnet: srp@ucsfcgl.bitnet

tom@flood.com (Tom Chatt) (06/25/91)

srp@babar.mmwb.ucsf.edu (Scott R. Presnell%Cohen) writes:
> hpn@regentdb.osrhe.uoknor.edu (Huy Nguyen / (405) 721-3798) writes:
> 
> > Does anyone know of a library package, hacks, etc to emulate these BSD
> > signal routines for SYS V?  
> 
> I've used the following in the past as a quick hack...
>  [ code snippets emulating sigblock, sigsetmask enclosed ]

Yes, but the important question is: can you emulate sigpause?
The sigpause(2) call, which *atomically* waits for signals on
a provided signal mask, is essential to properly avoid the
critical races otherwise inherent in managing signals.
-- 
Tom Chatt                        \   Don't take offense, take action.
Internet: tom@flood.com           \    Speak up. When we remain silent,
UUCP: ...!uunet!flood!tom        / \     we oppress ourselves.

dkeisen@leland.Stanford.EDU (Dave Eisen) (06/26/91)

In article <1991Jun25.165700.17625@flood.com> tom@flood.com (Tom Chatt) writes:
>Yes, but the important question is: can you emulate sigpause?
>The sigpause(2) call, which *atomically* waits for signals on
>a provided signal mask, is essential to properly avoid the
>critical races otherwise inherent in managing signals.

You can't. That's why BSD changed the AT&T signal handling so drastically.

srp@babar.mmwb.ucsf.edu (Scott R. Presnell%Cohen) (06/26/91)

tom@flood.com (Tom Chatt) writes:

>srp@babar.mmwb.ucsf.edu (Scott R. Presnell%Cohen) writes:
>> hpn@regentdb.osrhe.uoknor.edu (Huy Nguyen / (405) 721-3798) writes:
>> 
>> > Does anyone know of a library package, hacks, etc to emulate these BSD
>> > signal routines for SYS V?  
>> 
>> I've used the following in the past as a quick hack...
>>  [ code snippets emulating sigblock, sigsetmask enclosed ]

>Yes, but the important question is: can you emulate sigpause?

Nu uh.  Nor can I do anything about restarting system calls after the
signal handler returns :-( wish I could, or alternatively, shoot the bozos
who write code that depends on this functionality).  And watch out for
possible semantic differences in "handling" SIGCLD and SIGCHLD (check your
man pages.)

"quick hack" means exactly that.  It works - most of the time - for most
purposes (in my experience)

	- Scott
--
Scott Presnell				        +1 (415) 476-9890
Pharm. Chem., S-926				Internet: srp@cgl.ucsf.edu
University of California			UUCP: ...ucbvax!ucsfcgl!srp
San Francisco, CA. 94143-0446			Bitnet: srp@ucsfcgl.bitnet