summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorTobias Roeser <le.petit.fou@web.de>2019-02-25 11:07:28 +0100
committerTobias Roeser <le.petit.fou@web.de>2019-02-25 11:07:28 +0100
commitb19b5a4d36ed5015eb59d621dab13e9742408805 (patch)
treedbd4a5715155066ea46dae368314dfc9e3ea4a36 /main
parentd1d9d5ff7f4ca5bc44c383d5e1000674c2b4c2e2 (diff)
downloadmill-b19b5a4d36ed5015eb59d621dab13e9742408805.tar.gz
mill-b19b5a4d36ed5015eb59d621dab13e9742408805.tar.bz2
mill-b19b5a4d36ed5015eb59d621dab13e9742408805.zip
Reviewed exitCode handling
Propagate server stop because of version change as exit code.
Diffstat (limited to 'main')
-rw-r--r--main/client/src/MillClientMain.java17
-rw-r--r--main/src/main/MillServerMain.scala10
2 files changed, 19 insertions, 8 deletions
diff --git a/main/client/src/MillClientMain.java b/main/client/src/MillClientMain.java
index 3857caff..dc144f99 100644
--- a/main/client/src/MillClientMain.java
+++ b/main/client/src/MillClientMain.java
@@ -10,6 +10,12 @@ import java.nio.channels.FileChannel;
import java.util.*;
public class MillClientMain {
+
+ // use methods instead of constants to avoid inlining by compiler
+ public static final int ExitClientCodeCannotReadFromExitCodeFile() { return 1; }
+ public static final int ExitServerCodeWhenIdle() { return 0; }
+ public static final int ExitServerCodeWhenVersionMismatch() { return 101; }
+
static void initServer(String lockBase, boolean setJnaNoSys) throws IOException,URISyntaxException{
String[] selfJars = System.getProperty("MILL_CLASSPATH").split(",");
@@ -56,7 +62,8 @@ public class MillClientMain {
System.setProperty("jna.nosys", "true");
}
int index = 0;
- while (index < 5) {
+ final int processLimit = 5;
+ while (index < processLimit) {
index += 1;
String lockBase = "out/mill-worker-" + index;
new java.io.File(lockBase).mkdirs();
@@ -91,7 +98,7 @@ public class MillClientMain {
}
}
- throw new Exception("Reached max process limit: " + 5);
+ throw new Exception("Reached max process limit: " + processLimit);
}
public static int run(String lockBase,
@@ -151,10 +158,10 @@ public class MillClientMain {
locks.serverLock.await();
- try(FileInputStream fos = new FileInputStream(lockBase + "/exitCode")){
- return Integer.parseInt(new BufferedReader(new InputStreamReader(fos)).readLine());
+ try(FileInputStream fis = new FileInputStream(lockBase + "/exitCode")){
+ return Integer.parseInt(new BufferedReader(new InputStreamReader(fis)).readLine());
} catch(Throwable e){
- return 1;
+ return ExitClientCodeCannotReadFromExitCodeFile();
} finally{
ioSocket.close();
}
diff --git a/main/src/main/MillServerMain.scala b/main/src/main/MillServerMain.scala
index 55cef632..862daaf7 100644
--- a/main/src/main/MillServerMain.scala
+++ b/main/src/main/MillServerMain.scala
@@ -37,9 +37,9 @@ object MillServerMain extends mill.main.MillServerMain[Evaluator.State]{
def handle(sig: Signal) = {} // do nothing
})
new Server(
- args0(0),
+ lockBase = args0(0),
this,
- () => System.exit(0),
+ () => System.exit(MillClientMain.ExitServerCodeWhenIdle()),
300000,
mill.main.client.Locks.files(args0(0))
).run()
@@ -124,7 +124,11 @@ class Server[T](lockBase: String,
if (clientMillVersion != serverMillVersion) {
// FIXME: exiting with 0 isn't correct, see https://github.com/lihaoyi/mill/issues/557
stdout.println(s"Mill version changed ($serverMillVersion -> $clientMillVersion), re-starting server")
- System.exit(0)
+ java.nio.file.Files.write(
+ java.nio.file.Paths.get(lockBase + "/exitCode"),
+ s"${MillClientMain.ExitServerCodeWhenVersionMismatch()}".getBytes()
+ )
+ System.exit(MillClientMain.ExitServerCodeWhenVersionMismatch())
}
val args = Util.parseArgs(argStream)
val env = Util.parseMap(argStream)