Skip to content

Commit 2430660

Browse files
committed
Ignore SIGXFSZ signal.
1 parent 12022ff commit 2430660

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/SunMiscSubstitutions.java

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -401,15 +401,15 @@ protected long decrementCount() {
401401
}
402402

403403
@AutomaticallyRegisteredFeature
404-
class IgnoreSIGPIPEFeature implements InternalFeature {
404+
class IgnoreSignalsFeature implements InternalFeature {
405405

406406
@Override
407407
public void beforeAnalysis(BeforeAnalysisAccess access) {
408-
RuntimeSupport.getRuntimeSupport().addStartupHook(new IgnoreSIGPIPEStartupHook());
408+
RuntimeSupport.getRuntimeSupport().addStartupHook(new IgnoreSignalsStartupHook());
409409
}
410410
}
411411

412-
final class IgnoreSIGPIPEStartupHook implements RuntimeSupport.Hook {
412+
final class IgnoreSignalsStartupHook implements RuntimeSupport.Hook {
413413

414414
@CEntryPoint(publishAs = Publish.NotPublished)
415415
@CEntryPointOptions(prologue = NoPrologue.class, epilogue = NoEpilogue.class)
@@ -418,20 +418,24 @@ static void noopSignalHandler(@SuppressWarnings("unused") int sig) {
418418
}
419419

420420
private static final CEntryPointLiteral<Signal.SignalDispatcher> NOOP_SIGNAL_HANDLER = //
421-
CEntryPointLiteral.create(IgnoreSIGPIPEStartupHook.class, "noopSignalHandler", int.class);
421+
CEntryPointLiteral.create(IgnoreSignalsStartupHook.class, "noopSignalHandler", int.class);
422422

423423
/**
424+
* HotSpot ignores the SIGPIPE and SIGXFSZ signals (see <a
425+
* href=https://github.com/openjdk/jdk/blob/fc76687c2fac39fcbf706c419bfa170b8efa5747/src/hotspot/os/posix/signals_posix.cpp#L608>signals_posix.cpp</a>).
426+
* When signal handling is enabled we do the same thing.
427+
* <p>
424428
* Ignore SIGPIPE. Reading from a closed pipe, instead of delivering a process-wide signal whose
425429
* default action is to terminate the process, will instead return an error code from the
426430
* specific write operation.
427-
*
431+
* <p>
428432
* From pipe(7): If all file descriptors referring to the read end of a pipe have been closed,
429433
* then a write(2) will cause a SIGPIPE signal to be generated for the calling process. If the
430434
* calling process is ignoring this signal, then write(2) fails with the error EPIPE.
431-
*
435+
* <p>
432436
* Note that the handler must be an empty function and not SIG_IGN. The problem is SIG_IGN is
433437
* inherited to subprocess but we only want to affect the current process.
434-
*
438+
* <p>
435439
* From signal(7): A child created via fork(2) inherits a copy of its parent's signal
436440
* dispositions. During an execve(2), the dispositions of handled signals are reset to the
437441
* default; the dispositions of ignored signals are left unchanged.
@@ -440,18 +444,21 @@ static void noopSignalHandler(@SuppressWarnings("unused") int sig) {
440444
public void execute(boolean isFirstIsolate) {
441445
if (isFirstIsolate && SubstrateOptions.EnableSignalHandling.getValue()) {
442446
synchronized (Target_jdk_internal_misc_Signal.class) {
443-
int signum = Signal.SignalEnum.SIGPIPE.getCValue();
444-
if (Util_jdk_internal_misc_Signal.isCurrentDispatcher(signum, Signal.SIG_DFL())) {
445-
/*
446-
* Replace with NOOP signal handler if a custom one has not already been
447-
* installed.
448-
*/
449-
final SignalDispatcher signalResult = PosixUtils.installSignalHandler(signum, NOOP_SIGNAL_HANDLER.getFunctionPointer());
450-
VMError.guarantee(signalResult != Signal.SIG_ERR(), "IgnoreSIGPIPEFeature.run: Could not ignore SIGPIPE");
451-
}
447+
installNoopHandler(Signal.SignalEnum.SIGPIPE.getCValue());
448+
installNoopHandler(Signal.SignalEnum.SIGXFSZ.getCValue());
452449
}
453450
}
454451
}
452+
453+
private static void installNoopHandler(int signum) {
454+
if (Util_jdk_internal_misc_Signal.isCurrentDispatcher(signum, Signal.SIG_DFL())) {
455+
/*
456+
* Replace with no-op signal handler if a custom one has not already been installed.
457+
*/
458+
final SignalDispatcher signalResult = PosixUtils.installSignalHandler(signum, NOOP_SIGNAL_HANDLER.getFunctionPointer());
459+
VMError.guarantee(signalResult != Signal.SIG_ERR(), "IgnoreSignalsStartupHook: Could not ignore signum: %s", signum);
460+
}
461+
}
455462
}
456463

457464
@TargetClass(className = "jdk.internal.misc.VM")

0 commit comments

Comments
 (0)