jnr / jnr-posix

Java Posix layer
Other
241 stars 91 forks source link

let `SunMiscSignal#signal()` return default handler, too #194

Closed adoroszlai closed 1 month ago

adoroszlai commented 3 months ago

What changes were proposed in this pull request?

sun.misc.Signal#handle() returns the default handler when installing the first custom handler (for each signal).

On the other hand, JNR's SunMiscSignal#signal() returns the previous handler only if it is a SunMiscSignalHandler, which wraps a custom handler. When installing the first custom handler (for each signal), null is returned. The default handler is "lost".

This PR fixes that by returning an adapter for the default handler instead of null. This makes it possible to chain handlers, keeping original handler functionality.

How was this patch tested?

Added assertion in unit test.

Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.159 sec - in jnr.posix.SignalTest

Also tested in a real application that installs a custom handler (logger) on top of the default functionality.

headius commented 1 month ago

Looks good to me!