Skip to content

Commit b1ed40a

Browse files
committed
8293466: libjsig should ignore non-modifying sigaction calls
Reviewed-by: manc, dholmes
1 parent b6ff8fa commit b1ed40a

File tree

1 file changed

+19
-8
lines changed
  • src/java.base/unix/native/libjsig

1 file changed

+19
-8
lines changed

src/java.base/unix/native/libjsig/jsig.c

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -248,17 +248,28 @@ JNIEXPORT int sigaction(int sig, const struct sigaction *act, struct sigaction *
248248
signal_unlock();
249249
return 0;
250250
} else if (jvm_signal_installing) {
251-
/* jvm is installing its signal handlers. Install the new
252-
* handlers and save the old ones. */
251+
/* jvm is installing its signal handlers.
252+
* - if this is a modifying sigaction call, we install a new signal handler and store the old one
253+
* as chained signal handler.
254+
* - if this is a non-modifying sigaction call, we don't change any state; we just return the existing
255+
* signal handler in the system (not the stored one).
256+
* This works under the assumption that there is only one modifying sigaction call for a specific signal
257+
* within the JVM_begin_signal_setting-JVM_end_signal_setting-window. There can be any number of non-modifying
258+
* calls, but they will only return the expected preexisting handler if executed before the modifying call.
259+
*/
253260
res = call_os_sigaction(sig, act, &oldAct);
254-
sact[sig] = oldAct;
255-
if (oact != NULL) {
256-
*oact = oldAct;
261+
if (res == 0) {
262+
if (act != NULL) {
263+
/* store pre-existing handler as chained handler */
264+
sact[sig] = oldAct;
265+
/* Record the signals used by jvm. */
266+
sigaddset(&jvmsigs, sig);
267+
}
268+
if (oact != NULL) {
269+
*oact = oldAct;
270+
}
257271
}
258272

259-
/* Record the signals used by jvm. */
260-
sigaddset(&jvmsigs, sig);
261-
262273
signal_unlock();
263274
return res;
264275
} else {

0 commit comments

Comments
 (0)