diff --git a/src/main/java/jnr/posix/util/SunMiscSignal.java b/src/main/java/jnr/posix/util/SunMiscSignal.java index 93de45e..164a52e 100644 --- a/src/main/java/jnr/posix/util/SunMiscSignal.java +++ b/src/main/java/jnr/posix/util/SunMiscSignal.java @@ -11,6 +11,13 @@ public static SignalHandler signal(jnr.constants.platform.Signal sig, final Sign if (oldHandler instanceof SunMiscSignalHandler) { return ((SunMiscSignalHandler)oldHandler).handler; + } else if (oldHandler != null) { + return new SignalHandler() { + @Override + public void handle(int signal) { + oldHandler.handle(s); + } + }; } else { return null; } diff --git a/src/test/java/jnr/posix/SignalTest.java b/src/test/java/jnr/posix/SignalTest.java index 7077cdd..01a8573 100644 --- a/src/test/java/jnr/posix/SignalTest.java +++ b/src/test/java/jnr/posix/SignalTest.java @@ -51,12 +51,14 @@ public void testJavaSignal() { if (!Platform.IS_WINDOWS) { Signal s = Signal.SIGHUP; final AtomicBoolean fired = new AtomicBoolean(false); - javaPosix.signal(s, new SignalHandler() { + SignalHandler previousHandler = javaPosix.signal(s, new SignalHandler() { public void handle(int signal) { fired.set(true); } }); + Assert.assertNotNull(previousHandler); + // have to use native here; no abstraction for kill in pure Java // TODO: sun.misc.Signal.raise can be used to kill current pid posix.kill(posix.getpid(), s.intValue());