3350 return parse_options_environment_variable("_JAVA_OPTIONS", scp_p, 3351 scp_assembly_required_p); 3352 } 3353 3354 jint Arguments::parse_java_tool_options_environment_variable(SysClassPath* scp_p, bool* scp_assembly_required_p) { 3355 return parse_options_environment_variable("JAVA_TOOL_OPTIONS", scp_p, 3356 scp_assembly_required_p); 3357 } 3358 3359 jint Arguments::parse_options_environment_variable(const char* name, SysClassPath* scp_p, bool* scp_assembly_required_p) { 3360 const int N_MAX_OPTIONS = 64; 3361 const int OPTION_BUFFER_SIZE = 1024; 3362 char buffer[OPTION_BUFFER_SIZE]; 3363 3364 // The variable will be ignored if it exceeds the length of the buffer. 3365 // Don't check this variable if user has special privileges 3366 // (e.g. unix su command). 3367 if (os::getenv(name, buffer, sizeof(buffer)) && 3368 !os::have_special_privileges()) { 3369 JavaVMOption options[N_MAX_OPTIONS]; // Construct option array 3370 jio_fprintf(defaultStream::error_stream(), 3371 "Picked up %s: %s\n", name, buffer); 3372 char* rd = buffer; // pointer to the input string (rd) 3373 int i; 3374 for (i = 0; i < N_MAX_OPTIONS;) { // repeat for all options in the input string 3375 while (isspace(*rd)) rd++; // skip whitespace 3376 if (*rd == 0) break; // we re done when the input string is read completely 3377 3378 // The output, option string, overwrites the input string. 3379 // Because of quoting, the pointer to the option string (wrt) may lag the pointer to 3380 // input string (rd). 3381 char* wrt = rd; 3382 3383 options[i++].optionString = wrt; // Fill in option 3384 while (*rd != 0 && !isspace(*rd)) { // unquoted strings terminate with a space or NULL 3385 if (*rd == '\'' || *rd == '"') { // handle a quoted string 3386 int quote = *rd; // matching quote to look for 3387 rd++; // don't copy open quote 3388 while (*rd != quote) { // include everything (even spaces) up until quote 3389 if (*rd == 0) { // string termination means unmatched string 3390 jio_fprintf(defaultStream::error_stream(), 3391 "Unmatched quote in %s\n", name); 3392 return JNI_ERR; 3393 } 3394 *wrt++ = *rd++; // copy to option string 3395 } 3396 rd++; // don't copy close quote 3397 } else { 3398 *wrt++ = *rd++; // copy to option string 3399 } 3400 } 3401 // Need to check if we're done before writing a NULL, 3402 // because the write could be to the byte that rd is pointing to. 3403 if (*rd++ == 0) { 3404 *wrt = 0; 3405 break; 3406 } 3407 *wrt = 0; // Zero terminate option 3408 } 3409 // Construct JavaVMInitArgs structure and parse as if it was part of the command line 3410 JavaVMInitArgs vm_args; 3411 vm_args.version = JNI_VERSION_1_2; 3412 vm_args.options = options; 3413 vm_args.nOptions = i; 3414 vm_args.ignoreUnrecognized = IgnoreUnrecognizedVMOptions; 3415 3416 if (PrintVMOptions) { 3417 const char* tail; 3418 for (int i = 0; i < vm_args.nOptions; i++) { 3419 const JavaVMOption *option = vm_args.options + i; 3420 if (match_option(option, "-XX:", &tail)) { 3421 logOption(tail); 3422 } 3423 } 3424 } 3425 3426 return(parse_each_vm_init_arg(&vm_args, scp_p, scp_assembly_required_p, Flag::ENVIRON_VAR)); 3427 } | 3350 return parse_options_environment_variable("_JAVA_OPTIONS", scp_p, 3351 scp_assembly_required_p); 3352 } 3353 3354 jint Arguments::parse_java_tool_options_environment_variable(SysClassPath* scp_p, bool* scp_assembly_required_p) { 3355 return parse_options_environment_variable("JAVA_TOOL_OPTIONS", scp_p, 3356 scp_assembly_required_p); 3357 } 3358 3359 jint Arguments::parse_options_environment_variable(const char* name, SysClassPath* scp_p, bool* scp_assembly_required_p) { 3360 const int N_MAX_OPTIONS = 64; 3361 const int OPTION_BUFFER_SIZE = 1024; 3362 char buffer[OPTION_BUFFER_SIZE]; 3363 3364 // The variable will be ignored if it exceeds the length of the buffer. 3365 // Don't check this variable if user has special privileges 3366 // (e.g. unix su command). 3367 if (os::getenv(name, buffer, sizeof(buffer)) && 3368 !os::have_special_privileges()) { 3369 JavaVMOption options[N_MAX_OPTIONS]; // Construct option array 3370 3371 bool suppress_message = false; // the message will be printed unless requested not to 3372 char message[OPTION_BUFFER_SIZE + 256]; // enough space for the options, message and the variable name 3373 jio_snprintf(message, sizeof(message), // message with the unmodidied yet buffer 3374 "Picked up %s: %s\n", 3375 name, buffer); 3376 3377 char* rd = buffer; // pointer to the input string (rd) 3378 int i; 3379 for (i = 0; i < N_MAX_OPTIONS;) { // repeat for all options in the input string 3380 while (isspace(*rd)) rd++; // skip whitespace 3381 if (*rd == 0) break; // we re done when the input string is read completely 3382 3383 // The output, option string, overwrites the input string. 3384 // Because of quoting, the pointer to the option string (wrt) may lag the pointer to 3385 // input string (rd). 3386 char* wrt = rd; 3387 3388 options[i].optionString = wrt; // Fill in option 3389 3390 // Check if we're requested to suppress the message about picking up options 3391 const char* tail; 3392 if (match_option(&options[i], "-XX:+SuppressJavaOptsOutput", &tail) && 3393 (*tail == 0 || isspace(*tail))) { 3394 suppress_message = true; 3395 // remove the -XX:+SuppressJavaOptsOutput option from further processing 3396 rd += tail - rd; 3397 continue; 3398 } 3399 3400 i++; 3401 while (*rd != 0 && !isspace(*rd)) { // unquoted strings terminate with a space or NULL 3402 if (*rd == '\'' || *rd == '"') { // handle a quoted string 3403 int quote = *rd; // matching quote to look for 3404 rd++; // don't copy open quote 3405 while (*rd != quote) { // include everything (even spaces) up until quote 3406 if (*rd == 0) { // string termination means unmatched string 3407 jio_fprintf(defaultStream::error_stream(), 3408 "%sUnmatched quote in %s\n", 3409 suppress_message ? "" : message, name); 3410 return JNI_ERR; 3411 } 3412 *wrt++ = *rd++; // copy to option string 3413 } 3414 rd++; // don't copy close quote 3415 } else { 3416 *wrt++ = *rd++; // copy to option string 3417 } 3418 } 3419 // Need to check if we're done before writing a NULL, 3420 // because the write could be to the byte that rd is pointing to. 3421 if (*rd++ == 0) { 3422 *wrt = 0; 3423 break; 3424 } 3425 *wrt = 0; // Zero terminate option 3426 } 3427 if (!suppress_message) { 3428 jio_fprintf(defaultStream::error_stream(), "%s", message); 3429 } 3430 // Construct JavaVMInitArgs structure and parse as if it was part of the command line 3431 JavaVMInitArgs vm_args; 3432 vm_args.version = JNI_VERSION_1_2; 3433 vm_args.options = options; 3434 vm_args.nOptions = i; 3435 vm_args.ignoreUnrecognized = IgnoreUnrecognizedVMOptions; 3436 3437 if (PrintVMOptions) { 3438 const char* tail; 3439 for (int i = 0; i < vm_args.nOptions; i++) { 3440 const JavaVMOption *option = vm_args.options + i; 3441 if (match_option(option, "-XX:", &tail)) { 3442 logOption(tail); 3443 } 3444 } 3445 } 3446 3447 return(parse_each_vm_init_arg(&vm_args, scp_p, scp_assembly_required_p, Flag::ENVIRON_VAR)); 3448 } |