1 /* |
1 /* |
2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
422 buffer_length = strlen(log_name) + 1; |
422 buffer_length = strlen(log_name) + 1; |
423 } |
423 } |
424 |
424 |
425 const char* star = strchr(basename, '*'); |
425 const char* star = strchr(basename, '*'); |
426 int star_pos = (star == NULL) ? -1 : (star - nametail); |
426 int star_pos = (star == NULL) ? -1 : (star - nametail); |
|
427 int skip = 1; |
|
428 if (star == NULL) { |
|
429 // Try %p |
|
430 star = strstr(basename, "%p"); |
|
431 if (star != NULL) { |
|
432 skip = 2; |
|
433 } |
|
434 } |
|
435 star_pos = (star == NULL) ? -1 : (star - nametail); |
427 |
436 |
428 char pid[32]; |
437 char pid[32]; |
429 if (star_pos >= 0) { |
438 if (star_pos >= 0) { |
430 jio_snprintf(pid, sizeof(pid), "%u", os::current_process_id()); |
439 jio_snprintf(pid, sizeof(pid), "%u", os::current_process_id()); |
431 buffer_length += strlen(pid); |
440 buffer_length += strlen(pid); |
440 strcat(buf, os::file_separator()); |
449 strcat(buf, os::file_separator()); |
441 nametail = basename; // completely skip directory prefix |
450 nametail = basename; // completely skip directory prefix |
442 } |
451 } |
443 |
452 |
444 if (star_pos >= 0) { |
453 if (star_pos >= 0) { |
445 // convert foo*bar.log to foo123bar.log |
454 // convert foo*bar.log or foo%pbar.log to foo123bar.log |
446 int buf_pos = (int) strlen(buf); |
455 int buf_pos = (int) strlen(buf); |
447 strncpy(&buf[buf_pos], nametail, star_pos); |
456 strncpy(&buf[buf_pos], nametail, star_pos); |
448 strcpy(&buf[buf_pos + star_pos], pid); |
457 strcpy(&buf[buf_pos + star_pos], pid); |
449 nametail += star_pos + 1; // skip prefix and star |
458 nametail += star_pos + skip; // skip prefix and pid format |
450 } |
459 } |
451 |
460 |
452 strcat(buf, nametail); // append rest of name, or all of name |
461 strcat(buf, nametail); // append rest of name, or all of name |
453 return buf; |
462 return buf; |
454 } |
463 } |
464 jio_snprintf(warnbuf, sizeof(warnbuf), |
473 jio_snprintf(warnbuf, sizeof(warnbuf), |
465 "Warning: Cannot open log file: %s\n", try_name); |
474 "Warning: Cannot open log file: %s\n", try_name); |
466 // Note: This feature is for maintainer use only. No need for L10N. |
475 // Note: This feature is for maintainer use only. No need for L10N. |
467 jio_print(warnbuf); |
476 jio_print(warnbuf); |
468 FREE_C_HEAP_ARRAY(char, try_name); |
477 FREE_C_HEAP_ARRAY(char, try_name); |
469 try_name = make_log_name("hs_pid*.log", os::get_temp_directory()); |
478 try_name = make_log_name("hs_pid%p.log", os::get_temp_directory()); |
470 jio_snprintf(warnbuf, sizeof(warnbuf), |
479 jio_snprintf(warnbuf, sizeof(warnbuf), |
471 "Warning: Forcing option -XX:LogFile=%s\n", try_name); |
480 "Warning: Forcing option -XX:LogFile=%s\n", try_name); |
472 jio_print(warnbuf); |
481 jio_print(warnbuf); |
473 delete file; |
482 delete file; |
474 file = new(ResourceObj::C_HEAP) fileStream(try_name); |
483 file = new(ResourceObj::C_HEAP) fileStream(try_name); |