Skip to content

Commit

Permalink
Merge pull request #63 from segrey/keep-initialization-error-message
Browse files Browse the repository at this point in the history
rethrow initialization error in Native.sendCtrlC (#56)
  • Loading branch information
oleg-nenashev authored Feb 25, 2019
2 parents fdcd406 + f9abd2b commit 875fbe9
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/main/java/org/jvnet/winp/Native.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class Native {
private static final String DLL_TARGET = "winp.folder.preferred";
private static final String UNPACK_DLL_TO_PARENT_DIR = "winp.unpack.dll.to.parent.dir";

private static String ctrlCExePath;
private static volatile String ctrlCExePath;

/**
* Sends Ctrl+C to the process.
Expand All @@ -82,16 +82,26 @@ class Native {
*/
@CheckReturnValue
public static boolean sendCtrlC(int pid) throws WinpException {
if (loadFailure != null) {
throw new WinpException("Cannot send the CtrlC signal to the process: winp init failed", loadFailure);
}
if (ctrlCExePath == null) {
LOGGER.log(Level.WARNING, "Cannot send the CtrlC signal to the process. Cannot find the executable {0}.dll", CTRLCEXE_NAME);
return false;
}
return CtrlCSender.sendCtrlC(pid, ctrlCExePath);
}

private static volatile Throwable loadFailure;

static {
File exeFile = load();
ctrlCExePath = (exeFile == null) ? null : exeFile.getPath();
try {
File exeFile = load();
ctrlCExePath = (exeFile == null) ? null : exeFile.getPath();
} catch (Throwable t) {
loadFailure = t;
LOGGER.log(Level.SEVERE, "Cannot init winp native", t);
}
}

private static String md5(URL res) {
Expand Down

0 comments on commit 875fbe9

Please sign in to comment.