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)
{

        flt_signal++;

I changed that to

        if (flt_signal++ != 0)
                abort();

        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);
        }

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

                fpsetmask(0);

(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
else.


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 whooppee.com    |
| Network Engineer | 0786 F758 55DE 53BA 7731 | pgoyette at juniper.net |
| Kernel Developer |                          | pgoyette at netbsd.org  |
-------------------------------------------------------------------------


Home | Main Index | Thread Index | Old Index