SungHawk Kim wrote:
> Is there any way to implement signal-safe code using not pselect() but
> select()?

Yes.  In Linux longjmp and siglongjmp can reliably jump out of a signal
handler.  See below.

> I have two cases in that select() should returns,
> . when any of the descriptors are ready
> . when a specific signal(ie, SIGUSR1) is pending
> 
> What I want to do is like this:
> 
>         unblock SIGUSR1
>         select();
>         block SIGUSR1
> 
> This code seems good, but has a problem.
> If a SIGUSR1 signal arrives between unblock and select(), the signal is
> lost.  so, select() can sleep forerver.

Solution is:

jmp_buf * save_jb;
volatile sigatomic_t save_jb_flag = 0;

        jmp_buf jb;
        if (!setjmp (&jb)) {
                save_jb = &jb;
                save_jb_flag = 1;
                unblock SIGUSR1
                select();
                save_jb_flag = 0;
                save_jb = 0;
        }
        block SIGUSR1

With SIGUSR1 handler:

        if (save_jb_flag)
                longjmp (save_jb, 1);

The appropriate settings for sigaction are left as an exercise...

enjoy,
-- Jamie
-
To unsubscribe from this list: send the line "unsubscribe linux-net" in
the body of a message to [EMAIL PROTECTED]

Reply via email to