-
Notifications
You must be signed in to change notification settings - Fork 757
Disable late attach to self by default #158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
package com.ibm.tools.attach.target; | ||
|
||
/******************************************************************************* | ||
* Copyright (c) 2009, 2015 IBM Corp. and others | ||
* Copyright (c) 2009, 2017 IBM Corp. and others | ||
* | ||
* This program and the accompanying materials are made available under | ||
* the terms of the Eclipse Public License 2.0 which accompanies this | ||
|
@@ -29,6 +29,8 @@ | |
import java.util.Properties; | ||
import java.util.Vector; | ||
|
||
import com.ibm.oti.vm.VM; | ||
|
||
/** | ||
* This class handles incoming attachment requests from other VMs. Must be | ||
* public because it is used by java.lang.System | ||
|
@@ -50,7 +52,7 @@ public class AttachHandler extends Thread { | |
/** | ||
* Time delay before we give up trying to terminate the wait loop. | ||
*/ | ||
static final long shutdownTimeoutMs = Integer.getInteger("com.ibm.tools.attach.shutdown_timeout", 10000); //$NON-NLS-1$ | ||
static final long shutdownTimeoutMs = Integer.getInteger("com.ibm.tools.attach.shutdown_timeout", 10000).longValue(); //$NON-NLS-1$ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure of the point of this change. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It avoids a warning about auto-unboxing. |
||
private enum AttachStateValues { | ||
ATTACH_UNINITIALIZED, ATTACH_TERMINATED, ATTACH_STARTING, ATTACH_INITIALIZED | ||
} | ||
|
@@ -60,7 +62,7 @@ private enum AttachStateValues { | |
*/ | ||
static AttachHandler mainHandler = new AttachHandler(); | ||
static volatile Thread currentAttachThread = mainHandler; /* Join on this when shutting down */ | ||
private Vector<Attachment> attachments = new Vector<Attachment>(); | ||
private Vector<Attachment> attachments = new Vector<>(); | ||
private static String vmId = ""; /* ID of the currently running VM *///$NON-NLS-1$ | ||
/** | ||
* Human-friendly name for VM | ||
|
@@ -70,13 +72,19 @@ private enum AttachStateValues { | |
private static boolean waitingForSemaphore = false; | ||
|
||
private static final class AttachStateSync { | ||
}; | ||
/** | ||
* Empty class for synchronization objects. | ||
*/ | ||
} | ||
|
||
private static AttachStateSync stateSync = new AttachStateSync(); | ||
|
||
private static int notificationCount; | ||
|
||
private static final class syncObject { | ||
/** | ||
* Empty class for synchronization objects. | ||
*/ | ||
} | ||
|
||
private static boolean doCancelNotify; | ||
|
@@ -102,10 +110,24 @@ private static final class syncObject { | |
private static String nameProperty; | ||
private static String pidProperty; | ||
private static int numberOfTargets; | ||
/** | ||
* As of Java 9, a VM cannot attach to itself unless explicitly enabled. | ||
* Grab the setting before the application has a chance to change it, | ||
* but parse it lazily because we rarely need the value. | ||
*/ | ||
public final static String allowAttachSelf = | ||
VM.getVMLangAccess().internalGetProperties().getProperty("jdk.attach.allowAttachSelf", //$NON-NLS-1$ | ||
/*[IF Sidecar19-SE]*/ | ||
"false" //$NON-NLS-1$ | ||
/*[ELSE] | ||
"true" //$NON-NLS-1$ | ||
/*[ENDIF]*/ | ||
); | ||
|
||
/* only the attach handler thread uses syncFileLock */ | ||
/* [PR Jazz 30075] Make syncFileLock an instance variable since it is accessed only by the attachHandler singleton. */ | ||
private FileLock syncFileLock; | ||
private FileLock syncFileLock; | ||
private PrintStream logStream; | ||
|
||
/** | ||
* Keep the constructor private | ||
|
@@ -127,20 +149,19 @@ static void initializeAttachAPI() { | |
setAttachState(AttachStateValues.ATTACH_TERMINATED); | ||
return; | ||
} | ||
|
||
/* | ||
* set default behaviour: | ||
* Java 6 R24 and later: disabled by default on z/OS, enabled on all other platforms | ||
* Java 5: disabled by default on all platforms | ||
*/ | ||
/*[PR Jazz 59196 LIR: Disable attach API by default on z/OS (31972)]*/ | ||
boolean enableAttach = true; | ||
String osName = com.ibm.oti.vm.VM.getVMLangAccess().internalGetProperties().getProperty("os.name"); //$NON-NLS-1$ | ||
if ((null != osName) && (osName.equalsIgnoreCase("z/OS"))) { //$NON-NLS-1$ | ||
enableAttach = false; | ||
} | ||
String enableAttachProp = com.ibm.oti.vm.VM.getVMLangAccess().internalGetProperties().getProperty("com.ibm.tools.attach.enable"); //$NON-NLS-1$ | ||
boolean enableAttach = true; | ||
String osName = com.ibm.oti.vm.VM.getVMLangAccess().internalGetProperties().getProperty("os.name"); //$NON-NLS-1$ | ||
if ((null != osName) && (osName.equalsIgnoreCase("z/OS"))) { //$NON-NLS-1$ | ||
enableAttach = false; | ||
} | ||
/* the system property overrides the default */ | ||
String enableAttachProp = com.ibm.oti.vm.VM.getVMLangAccess().internalGetProperties().getProperty("com.ibm.tools.attach.enable"); //$NON-NLS-1$ | ||
if (null != enableAttachProp) { | ||
if (enableAttachProp.equalsIgnoreCase("no")) { //$NON-NLS-1$ | ||
enableAttach = false; | ||
|
@@ -281,7 +302,8 @@ private boolean initialize() throws IOException { | |
if ((null == IPC.logStream) && (null != loggingProperty) | ||
&& loggingProperty.equalsIgnoreCase("yes")) { //$NON-NLS-1$ | ||
File logFile = new File(logName + pidProperty + ".log"); //$NON-NLS-1$ | ||
IPC.setLogStream(new PrintStream(logFile)); | ||
logStream = new PrintStream(logFile); | ||
IPC.setLogStream(logStream); | ||
IPC.loggingEnabled = true; | ||
IPC.setDefaultVmId(pidProperty); | ||
IPC.logMessage("AttachHandler initialize"); //$NON-NLS-1$ | ||
|
@@ -438,7 +460,7 @@ private Attachment waitForNotification(boolean retry) throws IOException { | |
return at; | ||
} | ||
|
||
private Attachment checkReplyAndCreateAttachment() throws IOException { | ||
private static Attachment checkReplyAndCreateAttachment() throws IOException { | ||
Attachment at = mainHandler.connectToAttacher(); | ||
/*[PR Jazz 41720 - Recreate notification directory if it is deleted. ]*/ | ||
if (!TargetDirectory.ensureMyAdvertisementExists(getVmId())) { | ||
|
@@ -512,6 +534,9 @@ protected boolean terminate(boolean wakeHandler) { | |
case ATTACH_STARTING: break; /*/* may be anywhere in the initialization code. Do the full shutdown */ | ||
case ATTACH_INITIALIZED: break; /* go through the full shutdown */ | ||
case ATTACH_TERMINATED: return false; /* already started terminating */ | ||
default: | ||
IPC.logMessage("Unrecognized synchronization state "+stateSync.toString()); //$NON-NLS-1$ | ||
break; | ||
} | ||
} | ||
currentAttachThread.interrupt(); /* do this after we change the attachState */ | ||
|
@@ -752,7 +777,7 @@ public static boolean waitForAttachApiInitialization() { | |
--waitCycles; | ||
try { | ||
/* assignments to stateSync cause a notifyAll on stateSync */ | ||
stateSync.wait((long) 100000); /* timeout value */ | ||
stateSync.wait(100000); /* timeout value */ | ||
currentState = getAttachState(); | ||
switch (currentState) { | ||
case ATTACH_STARTING: | ||
|
@@ -967,6 +992,9 @@ static void setFactoryException(Exception factoryException) { | |
AttachHandler.factoryException = factoryException; | ||
} | ||
|
||
/** | ||
* @return ignoreNotification sync object | ||
*/ | ||
public Object getIgnoreNotification() { | ||
return ignoreNotification; | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please update the preprocessor definition to match.