Skip to content

Commit

Permalink
0003242: Running DS as a Windows Service in a folder path that contains
Browse files Browse the repository at this point in the history
whitespace causes error
  • Loading branch information
jaredfrees committed May 13, 2019
1 parent 7d8feb0 commit 54631b8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
Expand Up @@ -354,7 +354,7 @@ public void install() {
service = advapi.CreateService(manager, config.getName(), config.getDisplayName(), Winsvc.SERVICE_ALL_ACCESS,
WinsvcEx.SERVICE_WIN32_OWN_PROCESS, config.isAutoStart() || config.isDelayStart() ? WinsvcEx.SERVICE_AUTO_START
: WinsvcEx.SERVICE_DEMAND_START, WinsvcEx.SERVICE_ERROR_NORMAL,
commandToString(getWrapperCommand("init")), null, null, dependencies, null, null);
commandToString(getWrapperCommand("init", true)), null, null, dependencies, null, null);

if (service != null) {
Advapi32Ex.SERVICE_DESCRIPTION desc = new Advapi32Ex.SERVICE_DESCRIPTION(config.getDescription());
Expand Down
Expand Up @@ -23,6 +23,7 @@
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URLDecoder;

public class Wrapper {

Expand All @@ -35,7 +36,8 @@ public static void main(String[] args) throws Exception {

String appDir = null;
String configFile = null;
String jarFile = Wrapper.class.getProtectionDomain().getCodeSource().getLocation().getFile();
// Decode spaces and other special characters
String jarFile = Wrapper.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath();

if (args.length == 2) {
configFile = args[1];
Expand Down
Expand Up @@ -73,7 +73,7 @@ public void start() {

stopProcesses(true);
System.out.println("Waiting for server to start");
ArrayList<String> cmdLine = getWrapperCommand("exec");
ArrayList<String> cmdLine = getWrapperCommand("exec", false);
Process process = null;
boolean success = false;
int rc = 0;
Expand Down Expand Up @@ -346,15 +346,18 @@ protected String commandToString(ArrayList<String> cmd) {
return sb.toString();
}

protected ArrayList<String> getWrapperCommand(String arg) {
protected ArrayList<String> getWrapperCommand(String arg, boolean isQuotedArguments) {
ArrayList<String> cmd = new ArrayList<String>();
String quote = getWrapperCommandQuote();

String quote = isQuotedArguments ? getWrapperCommandQuote() : "";

cmd.add(quote + config.getJavaCommand() + quote);
cmd.add("-Djava.io.tmpdir="+quote+System.getProperty("java.io.tmpdir")+quote);
cmd.add("-jar");
cmd.add(quote + config.getWrapperJarPath() + quote);
cmd.add(arg);
cmd.add(quote + config.getConfigFile() + quote);

return cmd;
}

Expand Down

0 comments on commit 54631b8

Please sign in to comment.