Skip to content

Commit 51a80dd

Browse files
committedOct 3, 2023
8293466: libjsig should ignore non-modifying sigaction calls
Backport-of: b1ed40a87ab357d1b51ac5102bba181f21ffa9b6
1 parent a4b3027 commit 51a80dd

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

+19-8
Original file line numberDiff line numberDiff line change
@@ -278,17 +278,28 @@ int sigaction(int sig, const struct sigaction *act, struct sigaction *oact) {
278278
signal_unlock();
279279
return 0;
280280
} else if (jvm_signal_installing) {
281-
/* jvm is installing its signal handlers. Install the new
282-
* handlers and save the old ones. */
281+
/* jvm is installing its signal handlers.
282+
* - if this is a modifying sigaction call, we install a new signal handler and store the old one
283+
* as chained signal handler.
284+
* - if this is a non-modifying sigaction call, we don't change any state; we just return the existing
285+
* signal handler in the system (not the stored one).
286+
* This works under the assumption that there is only one modifying sigaction call for a specific signal
287+
* within the JVM_begin_signal_setting-JVM_end_signal_setting-window. There can be any number of non-modifying
288+
* calls, but they will only return the expected preexisting handler if executed before the modifying call.
289+
*/
283290
res = call_os_sigaction(sig, act, &oldAct);
284-
sact[sig] = oldAct;
285-
if (oact != NULL) {
286-
*oact = oldAct;
291+
if (res == 0) {
292+
if (act != NULL) {
293+
/* store pre-existing handler as chained handler */
294+
sact[sig] = oldAct;
295+
/* Record the signals used by jvm. */
296+
sigaddset(&jvmsigs, sig);
297+
}
298+
if (oact != NULL) {
299+
*oact = oldAct;
300+
}
287301
}
288302

289-
/* Record the signals used by jvm. */
290-
sigaddset(&jvmsigs, sig);
291-
292303
signal_unlock();
293304
return res;
294305
} else {

0 commit comments

Comments
 (0)
Please sign in to comment.