1.1 --- a/src/os/linux/vm/attachListener_linux.cpp Wed Jul 10 15:49:15 2013 +0000 1.2 +++ b/src/os/linux/vm/attachListener_linux.cpp Fri Jul 12 18:43:27 2013 +0200 1.3 @@ -1,5 +1,5 @@ 1.4 /* 1.5 - * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. 1.6 + * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. 1.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.8 * 1.9 * This code is free software; you can redistribute it and/or modify it 1.10 @@ -432,6 +432,30 @@ 1.11 return op; 1.12 } 1.13 1.14 + 1.15 +// Performs initialization at vm startup 1.16 +// For Linux we remove any stale .java_pid file which could cause 1.17 +// an attaching process to think we are ready to receive on the 1.18 +// domain socket before we are properly initialized 1.19 + 1.20 +void AttachListener::vm_start() { 1.21 + char fn[UNIX_PATH_MAX]; 1.22 + struct stat64 st; 1.23 + int ret; 1.24 + 1.25 + int n = snprintf(fn, UNIX_PATH_MAX, "%s/.java_pid%d", 1.26 + os::get_temp_directory(), os::current_process_id()); 1.27 + assert(n < (int)UNIX_PATH_MAX, "java_pid file name buffer overflow"); 1.28 + 1.29 + RESTARTABLE(::stat64(fn, &st), ret); 1.30 + if (ret == 0) { 1.31 + ret = ::unlink(fn); 1.32 + if (ret == -1) { 1.33 + debug_only(warning("failed to remove stale attach pid file at %s", fn)); 1.34 + } 1.35 + } 1.36 +} 1.37 + 1.38 int AttachListener::pd_init() { 1.39 JavaThread* thread = JavaThread::current(); 1.40 ThreadBlockInVM tbivm(thread);