If we can set up a mask with sigemptyset(), sigaddset(), sigdelset() and
sigfillset(), Is there an accepted way to copy the data from one signal
mask set to another?
In other words, If I have code that looks like this:
sigset_t sigmask1, sigmask2;
sigemptyset(&sigmask1);
sigaddset(&sigmask1, SIGUSR1);
sigaddset(&sigmask1, SIGUSR2);
/* magic code to copy sigmask1 to sigmask2 */
…
How do I go about copying the mask stored in sigmask1 to sigmask2 if I’m
theoretically not supposed to know the structure of sigset_t? I’m kinda
wary about using memcpy() because AFAIK it could be dangerous depending
on what the structure of sigset_t looks like and how the compiler
optimizes memory usage…
Or is the answer “You should not do something like this at all…”?
-Robert
Robert Agustin <agustin@apicom.com> wrote:
If we can set up a mask with sigemptyset(), sigaddset(), sigdelset() and
sigfillset(), Is there an accepted way to copy the data from one signal
mask set to another?
In other words, If I have code that looks like this:
sigset_t sigmask1, sigmask2;
sigemptyset(&sigmask1);
sigaddset(&sigmask1, SIGUSR1);
sigaddset(&sigmask1, SIGUSR2);
/* magic code to copy sigmask1 to sigmask2 */
…
How do I go about copying the mask stored in sigmask1 to sigmask2 if I’m
theoretically not supposed to know the structure of sigset_t? I’m kinda
wary about using memcpy() because AFAIK it could be dangerous depending
on what the structure of sigset_t looks like and how the compiler
optimizes memory usage…
Well, sigset_t, under the covers, is struct { long bits[2] }
so a memcpy() would work ok.
More correct, but a lot less efficient might be something like:
sigemtpyset(&sigmask2);
for (i = _SIGMIN; i< NSIG; i++)
{
if (sigismember(&sigmask1, i ))
sigaddset(&sigmask2, i );
}
But, I’d just go with the memcpy myself, I’d think.
-David
QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.
David Gibbs wrote:
Robert Agustin <> agustin@apicom.com> > wrote:
If we can set up a mask with sigemptyset(), sigaddset(), sigdelset() and
sigfillset(), Is there an accepted way to copy the data from one signal
mask set to another?
In other words, If I have code that looks like this:
sigset_t sigmask1, sigmask2;
sigemptyset(&sigmask1);
sigaddset(&sigmask1, SIGUSR1);
sigaddset(&sigmask1, SIGUSR2);
/* magic code to copy sigmask1 to sigmask2 */
…
How do I go about copying the mask stored in sigmask1 to sigmask2 if I’m
theoretically not supposed to know the structure of sigset_t? I’m kinda
wary about using memcpy() because AFAIK it could be dangerous depending
on what the structure of sigset_t looks like and how the compiler
optimizes memory usage…
Well, sigset_t, under the covers, is struct { long bits[2] }
so a memcpy() would work ok.
More correct, but a lot less efficient might be something like:
sigemtpyset(&sigmask2);
for (i = _SIGMIN; i< NSIG; i++)
{
if (sigismember(&sigmask1, i ))
sigaddset(&sigmask2, i );
}
But, I’d just go with the memcpy myself, I’d think.
-David
Okay, that’s pretty much the only “correct” solution I was able to think
of too. I think I’d be better off just rewrting that section of code
that I was trying to port.
Thanks!
-Robert