Skip to content

Commit 8e6f6b8

Browse files
committed
Restore SIGFPE handler after initializing PL/Perl.
Perl, for some unaccountable reason, believes it's a good idea to reset SIGFPE handling to SIG_IGN. Which wouldn't be a good idea even if it worked; but on some platforms (Linux at least) it doesn't work at all, instead resulting in forced process termination if the signal occurs. Given the lack of other complaints, it seems safe to assume that Perl never actually provokes SIGFPE and so there is no value in the setting anyway. Hence, reset it to our normal handler after initializing Perl. Report, analysis and patch by Andres Freund.
1 parent 970212f commit 8e6f6b8

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/pl/plperl/plperl.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@
2323
#include "commands/trigger.h"
2424
#include "executor/spi.h"
2525
#include "funcapi.h"
26+
#include "libpq/pqsignal.h"
2627
#include "mb/pg_wchar.h"
2728
#include "miscadmin.h"
2829
#include "nodes/makefuncs.h"
2930
#include "parser/parse_type.h"
3031
#include "storage/ipc.h"
32+
#include "tcop/tcopprot.h"
3133
#include "utils/builtins.h"
3234
#include "utils/fmgroids.h"
3335
#include "utils/guc.h"
@@ -741,6 +743,18 @@ plperl_init_interp(void)
741743
char *dummy_env[1] = {NULL};
742744

743745
PERL_SYS_INIT3(&nargs, (char ***) &embedding, (char ***) &dummy_env);
746+
747+
/*
748+
* For unclear reasons, PERL_SYS_INIT3 sets the SIGFPE handler to
749+
* SIG_IGN. Aside from being extremely unfriendly behavior for a
750+
* library, this is dumb on the grounds that the results of a
751+
* SIGFPE in this state are undefined according to POSIX, and in
752+
* fact you get a forced process kill at least on Linux. Hence,
753+
* restore the SIGFPE handler to the backend's standard setting.
754+
* (See Perl bug 114574 for more information.)
755+
*/
756+
pqsignal(SIGFPE, FloatExceptionHandler);
757+
744758
perl_sys_init_done = 1;
745759
/* quiet warning if PERL_SYS_INIT3 doesn't use the third argument */
746760
dummy_env[0] = NULL;

0 commit comments

Comments
 (0)