mirror of
https://github.com/openjdk/jdk.git
synced 2026-01-28 12:09:14 +00:00
8353439: Shell grouping of -XX:OnError= commands is surprising
Reviewed-by: dholmes, stuefe
This commit is contained in:
parent
a1d566ce4b
commit
cd9fa3f7aa
@ -136,7 +136,9 @@ static const char* env_list[] = {
|
||||
nullptr // End marker.
|
||||
};
|
||||
|
||||
// A simple parser for -XX:OnError, usage:
|
||||
// A simple parser for lists of commands such as -XX:OnError and -XX:OnOutOfMemoryError
|
||||
// Command list (ptr) is expected to be a sequence of commands delineated by semicolons and/or newlines.
|
||||
// Usage:
|
||||
// ptr = OnError;
|
||||
// while ((cmd = next_OnError_command(buffer, sizeof(buffer), &ptr) != nullptr)
|
||||
// ... ...
|
||||
@ -145,13 +147,13 @@ static char* next_OnError_command(char* buf, int buflen, const char** ptr) {
|
||||
|
||||
const char* cmd = *ptr;
|
||||
|
||||
// skip leading blanks or ';'
|
||||
while (*cmd == ' ' || *cmd == ';') cmd++;
|
||||
// skip leading blanks, ';' or newlines
|
||||
while (*cmd == ' ' || *cmd == ';' || *cmd == '\n') cmd++;
|
||||
|
||||
if (*cmd == '\0') return nullptr;
|
||||
|
||||
const char * cmdend = cmd;
|
||||
while (*cmdend != '\0' && *cmdend != ';') cmdend++;
|
||||
while (*cmdend != '\0' && *cmdend != ';' && *cmdend != '\n') cmdend++;
|
||||
|
||||
Arguments::copy_expand_pid(cmd, cmdend - cmd, buf, buflen);
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -40,7 +40,10 @@ public class TestOnError {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
String msg = "Test Succeeded";
|
||||
String msg1 = "OnError Test Message1";
|
||||
String msg2 = "OnError Test Message2";
|
||||
|
||||
// Basic OnError test:
|
||||
ProcessBuilder pb = ProcessTools.createLimitedTestJavaProcessBuilder(
|
||||
"-XX:-CreateCoredumpOnCrash",
|
||||
"-XX:ErrorHandlerTest=14", // trigger potential SEGV
|
||||
@ -59,6 +62,30 @@ public class TestOnError {
|
||||
both get written to stdout.
|
||||
*/
|
||||
output.stdoutShouldMatch("^" + msg); // match start of line only
|
||||
|
||||
// Test multiple OnError arguments:
|
||||
pb = ProcessTools.createLimitedTestJavaProcessBuilder(
|
||||
"-XX:-CreateCoredumpOnCrash",
|
||||
"-XX:ErrorHandlerTest=14",
|
||||
"-XX:OnError=echo " + msg1,
|
||||
"-XX:OnError=echo " + msg2,
|
||||
TestOnError.class.getName());
|
||||
|
||||
output = new OutputAnalyzer(pb.start());
|
||||
output.stdoutShouldMatch("^" + msg1);
|
||||
output.stdoutShouldMatch("^" + msg2);
|
||||
|
||||
// Test one argument with multiple commands using ; separator:
|
||||
pb = ProcessTools.createLimitedTestJavaProcessBuilder(
|
||||
"-XX:-CreateCoredumpOnCrash",
|
||||
"-XX:ErrorHandlerTest=14",
|
||||
"-XX:OnError=echo " + msg1 + ";echo " + msg2,
|
||||
TestOnError.class.getName());
|
||||
|
||||
output = new OutputAnalyzer(pb.start());
|
||||
output.stdoutShouldMatch("^" + msg1);
|
||||
output.stdoutShouldMatch("^" + msg2);
|
||||
|
||||
System.out.println("PASSED");
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user