Skip to content

started tackling restart on status #15

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions head_src/consolehead/consolehead.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ int main(int argc, char* argv[])
}

restartOnCrash = loadBool(RESTART_ON_CRASH);
int restartOnStatus = loadInt(RESTART_ON_STATUS);
DWORD dwExitCode;

do
Expand All @@ -85,11 +86,11 @@ int main(int argc, char* argv[])
break;
}

if (restartOnCrash && dwExitCode != 0)
if (dwExitCode != 0 && (restartOnCrash || dwExitCode == restartOnStatus))
{
debug("Exit code:\t%d, restarting the application!\n", dwExitCode);
}
} while (restartOnCrash && dwExitCode != 0);
} while (dwExitCode != 0 && (restartOnCrash || dwExitCode == restartOnStatus));

debug("Exit code:\t%d\n", dwExitCode);
closeLogFile();
Expand Down
8 changes: 5 additions & 3 deletions head_src/guihead/guihead.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,16 @@ int APIENTRY WinMain(HINSTANCE hInstance,
TranslateMessage(&msg);
DispatchMessage(&msg);
}

if (restartOnCrash && dwExitCode != 0)

int restartOnStatus = loadInt(RESTART_ON_STATUS);

if (dwExitCode != 0 && (restartOnCrash || dwExitCode == restartOnStatus))
{
debug("Exit code:\t%d, restarting the application!\n", dwExitCode);
}

closeProcessHandles();
} while (restartOnCrash && dwExitCode != 0);
} while (dwExitCode != 0 && (restartOnCrash || dwExitCode == restartOnStatus));

debug("Exit code:\t%d\n", dwExitCode);
closeLogFile();
Expand Down
5 changes: 3 additions & 2 deletions head_src/jniconsolehead_BETA/jniconsolehead.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ int main(int argc, char* argv[])
}

restartOnCrash = loadBool(RESTART_ON_CRASH);
int restartOnStatus = loadInt(RESTART_ON_STATUS);
DWORD dwExitCode;

do
Expand All @@ -87,11 +88,11 @@ int main(int argc, char* argv[])
break;
}

if (restartOnCrash && dwExitCode != 0)
if (dwExitCode != 0 && (restartOnCrash || dwExitCode == restartOnStatus))
{
debug("Exit code:\t%d, restarting the application!\n", dwExitCode);
}
} while (restartOnCrash && dwExitCode != 0);
} while (dwExitCode != 0 && (restartOnCrash || dwExitCode == restartOnStatus));

debug("Exit code:\t%d\n", dwExitCode);
closeLogFile();
Expand Down
8 changes: 5 additions & 3 deletions head_src/jniguihead_BETA/jniguihead.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,16 @@ int APIENTRY WinMain(HINSTANCE hInstance,
TranslateMessage(&msg);
DispatchMessage(&msg);
}

if (restartOnCrash && dwExitCode != 0)

int restartOnStatus = loadInt(RESTART_ON_STATUS);

if (dwExitCode != 0 && (restartOnCrash || dwExitCode == restartOnStatus))
{
debug("Exit code:\t%d, restarting the application!\n", dwExitCode);
}

closeProcessHandles();
} while (restartOnCrash && dwExitCode != 0);
} while (dwExitCode != 0 && (restartOnCrash || dwExitCode == restartOnStatus));

debug("Exit code:\t%d\n", dwExitCode);
closeLogFile();
Expand Down
1 change: 1 addition & 0 deletions head_src/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
#define RUNTIME_BITS 30
#define RESTART_ON_CRASH 31
#define BUNDLED_JRE_AS_FALLBACK 32
#define RESTART_ON_STATUS 33

#define STARTUP_ERR 101
#define BUNDLED_JRE_ERR 102
Expand Down
2 changes: 2 additions & 0 deletions src/net/sf/launch4j/RcBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public class RcBuilder {
public static final int RUNTIME_BITS = 30;
public static final int RESTART_ON_CRASH = 31;
public static final int BUNDLED_JRE_AS_FALLBACK = 32;
public static final int RESTART_ON_STATUS = 33;

public static final int STARTUP_ERR = 101;
public static final int BUNDLED_JRE_ERR = 102;
Expand Down Expand Up @@ -139,6 +140,7 @@ public File build(Config c) throws IOException {
addText(PRIORITY_CLASS, String.valueOf(c.getPriorityClass()));
addTrue(GUI_HEADER_STAYS_ALIVE, c.isStayAlive());
addTrue(RESTART_ON_CRASH, c.isRestartOnCrash());
addInteger(RESTART_ON_STATUS, c.getRestartOnStatus());
addSplash(c.getSplash());
addMessages(c);

Expand Down
11 changes: 11 additions & 0 deletions src/net/sf/launch4j/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public class Config implements IValidatable {
private String supportUrl;
private boolean stayAlive;
private boolean restartOnCrash;
private int restartOnStatus;
private File manifest;
private File icon;
private List<String> variables;
Expand Down Expand Up @@ -356,6 +357,16 @@ public boolean isRestartOnCrash() {
public void setRestartOnCrash(boolean restartOnCrash) {
this.restartOnCrash = restartOnCrash;
}

/** Restart the application whenever the java application returns the status given here **/
public int getRestartOnStatus() {
return restartOnStatus;
}

public void setRestartOnStatus(int status) {
if(status < 5 && status > 255) throw new NumberFormatException("Restart-Status needs to be between 5 and 255!");
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if there isn't a better place to check this. I assumed 5 is out of range of the predefined 0,1,2

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it not be or instead of and, i.e.

if(status < 5 || status > 255) ...

restartOnStatus = status;
}

public VersionInfo getVersionInfo() {
return versionInfo;
Expand Down