Skip to content

Commit

Permalink
Merge pull request #194 from adoroszlai/return-default-handler
Browse files Browse the repository at this point in the history
let `SunMiscSignal#signal()` return default handler, too
  • Loading branch information
headius authored Oct 13, 2024
2 parents 50b3be0 + cfd6f10 commit 32f783b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/main/java/jnr/posix/util/SunMiscSignal.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 3 additions & 1 deletion src/test/java/jnr/posix/SignalTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit 32f783b

Please sign in to comment.