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, 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)
> {
> 
>         flt_signal++;
>         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;
> 
> >>>>   printf("Start\n");

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

>         if (sigsetjmp(sigfpe_flt_env, 0) == 0) {
>                 sa.sa_flags = SA_SIGINFO;
>                 sa.sa_sigaction = sigfpe_flt_action;
>                 sigemptyset(&sa.sa_mask);
>                 sigaction(SIGFPE, &sa, NULL);
>                 fpsetmask(FP_X_INV|FP_X_DZ|FP_X_OFL|FP_X_UFL|FP_X_IMP);
>               d = 1.0 / strtod("0", NULL);
>         }
>         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
else.

Joerg


Home | Main Index | Thread Index | Old Index