Browse code

t_server_null: print error when server startup fails

Use "&" to background so that the exit code and all output can be
obtained in all failure cases.

Change-Id: I39dc6b08952a06dae7901e468f9487c8541d83c3
Signed-off-by: Samuli Seppänen <samuli.seppanen@gmail.com>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20250618141328.4600-1-gert@greenie.muc.de>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg31932.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>

Samuli Seppänen authored on 2025/06/18 23:13:21
Showing 2 changed files
... ...
@@ -38,7 +38,7 @@ SERVER_KILL_FAIL_FILE=".t_server_null_server.kill_failed"
38 38
 MAX_CLIENTS="10"
39 39
 CLIENT_MATCH="Test-Client"
40 40
 SERVER_EXEC="${top_builddir}/src/openvpn/openvpn"
41
-SERVER_BASE_OPTS="--daemon --local 127.0.0.1 --dev tun --topology subnet --max-clients $MAX_CLIENTS --persist-tun --verb 3 --duplicate-cn"
41
+SERVER_BASE_OPTS="--local 127.0.0.1 --dev tun --topology subnet --max-clients $MAX_CLIENTS --persist-tun --verb 3 --duplicate-cn"
42 42
 SERVER_CIPHER_OPTS=""
43 43
 SERVER_CERT_OPTS="--ca ${CA} --cert ${SERVER_CERT} --key ${SERVER_KEY} --tls-auth ${TA} 0"
44 44
 SERVER_CONF_BASE="${SERVER_BASE_OPTS} ${SERVER_CIPHER_OPTS} ${SERVER_CERT_OPTS}"
... ...
@@ -11,20 +11,18 @@ launch_server() {
11 11
     # Allow reading this file even umask values are strict
12 12
     touch "$log"
13 13
 
14
-    if [ -z "${RUN_SUDO}" ]; then
15
-        "${server_exec}" \
16
-         $server_conf \
17
-         --status "${status}" 1 \
18
-         --log "${log}" \
19
-         --writepid "${pid}" \
20
-         --explicit-exit-notify 3
21
-    else
22
-        $RUN_SUDO "${server_exec}" \
23
-                   $server_conf \
24
-                   --status "${status}" 1 \
25
-                   --log "${log}" \
26
-                   --writepid "${pid}" \
27
-                   --explicit-exit-notify 3
14
+    # Try to launch the server
15
+    $RUN_SUDO "${server_exec}" \
16
+               $server_conf \
17
+               --status "${status}" 1 \
18
+               --writepid "${pid}" \
19
+               --explicit-exit-notify 3 > "$log" 2>&1 &
20
+
21
+    sleep 1
22
+
23
+    if ! [ -r "$pid" ] || [ -z "$pid" ]; then
24
+        echo "ERROR: failed to start server $server_name"
25
+        tail -n 20 "$log"
28 26
     fi
29 27
 }
30 28