From 206f06f3f99712bd07884dde7a163c463563cde7 Mon Sep 17 00:00:00 2001 From: Jeremy Lakeman Date: Mon, 11 Apr 2016 13:36:35 +0930 Subject: [PATCH] Throw exceptions in java server start for any failures --- server.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/server.c b/server.c index 98115a20..3f210310 100644 --- a/server.c +++ b/server.c @@ -157,9 +157,9 @@ JNIEXPORT jint JNICALL Java_org_servalproject_servaldna_ServalDCommand_server( int pid = server_pid(); if (pid < 0) - return -1; + return Throw(env, "java/lang/IllegalStateException", "Failed to read server pid "+pid); if (pid>0) - return 1; + return Throw(env, "java/lang/IllegalStateException", "Server already running on pid "+pid); cf_reload_strict(); @@ -192,20 +192,26 @@ JNIEXPORT jint JNICALL Java_org_servalproject_servaldna_ServalDCommand_server( } } - if (keyring_seed(keyring) == -1) + if (keyring_seed(keyring) == -1){ + Throw(env, "java/lang/IllegalStateException", "Failed to seed keyring"); goto end; + } - if (server_env) + if (server_env){ + Throw(env, "java/lang/IllegalStateException", "Server java env variable already set"); goto end; + } server_env = env; JniCallback = (*env)->NewGlobalRef(env, callback); ret = server_bind(); - if (ret==-1) + if (ret==-1){ + Throw(env, "java/lang/IllegalStateException", "Failed to bind sockets"); goto end; - + } + { jstring str = (jstring)(*env)->NewStringUTF(env, instance_path()); (*env)->CallVoidMethod(env, callback, started, str, getpid(), mdp_loopback_port, httpd_server_port);