Current-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Strange (or at least interesting) printf() behavior!

On Mon, 3 Jan 2011, Joerg Sonnenberger wrote:

On Mon, Jan 03, 2011 at 08:01:36AM -0800, Paul Goyette wrote:
While researching another problem, I created the following test program:
static sigjmp_buf sigfpe_flt_env;
static void
sigfpe_flt_action(int signo, siginfo_t *info, void *ptr)


I changed that to

        if (flt_signal++ != 0)

        siglongjmp(sigfpe_flt_env, 1);

I would suggest to add an abort here if flt_signal is already set.
That would pin point the issue.

int main(int argc, void *argv[])
        struct sigaction sa;
        double d;


va_arg users have at least some minimal side effects like saving all fpu

        if (sigsetjmp(sigfpe_flt_env, 0) == 0) {
                sa.sa_flags = SA_SIGINFO;
                sa.sa_sigaction = sigfpe_flt_action;
                sigaction(SIGFPE, &sa, NULL);
                d = 1.0 / strtod("0", NULL);

And I added here (which is where the siglongjmp() should go)


(I wold have placed this right in the signal handler, but fpsetmask() is not listed as signalsafe in the signal(7) man page!)

        printf("FPE signal handler invoked %d times.\n", flt_signal);

As listed, the program runs find and produces the expected results.

However, if I remove the printf() pointed to by the >>>> the program
actually hangs!  Running it under gdb and interrupting with
Control/C shows the following traceback:

Not without a lot more guessing, but the above should tell you where
exactly the second trap comes from. Note that the test case is likely a
lot more stable if you actually restore the mask before calling anything

The abort() does not trigger, so the handler is being called only once.

And even though the exception mask is being reset, the program still hangs.

| Paul Goyette     | PGP Key fingerprint:     | E-mail addresses:       |
| Customer Service | FA29 0E3B 35AF E8AE 6651 | paul at    |
| Network Engineer | 0786 F758 55DE 53BA 7731 | pgoyette at |
| Kernel Developer |                          | pgoyette at  |

Home | Main Index | Thread Index | Old Index