From c46aa2e809ffdd92a84407dff30e76072deff83a Mon Sep 17 00:00:00 2001 From: Nir Soffer Date: Jan 15 2018 16:30:04 +0000 Subject: Normalize sanlock exit code Normalize sanlock exit code, so it exit with EXIT_FAILURE on all failures. Previously sanlock terminated with exit code 255 if lockfile() failed, 145 if client cannot connect to the daemon, or any other number depending on return value of failing function. Exit codes above 128 should be returned only when the process was terminated by signal (typically 128 + signo), and using them for other errors may confuse applications managing sanlock. Since sanlock exit code is not documented, this change should not break any user code. Signed-off-by: Nir Soffer --- diff --git a/src/main.c b/src/main.c index 1f879b0..9340ef7 100644 --- a/src/main.c +++ b/src/main.c @@ -3314,6 +3314,6 @@ int main(int argc, char *argv[]) break; }; out: - return rv; + return rv == 0 ? EXIT_SUCCESS : EXIT_FAILURE; } diff --git a/tests/daemon_test.py b/tests/daemon_test.py index 1c304ae..af1e890 100644 --- a/tests/daemon_test.py +++ b/tests/daemon_test.py @@ -93,7 +93,7 @@ def test_single_instance(sanlock_daemon): except TimeoutExpired: p.kill() p.wait() - assert p.returncode == 255 # exit code -1 + assert p.returncode == 1 def test_start_after_kill(): @@ -108,6 +108,13 @@ def test_start_after_kill(): assert p.returncode == -signal.SIGKILL +def test_client_failure(): + # No daemon is running, client must fail + with pytest.raises(subprocess.CalledProcessError) as e: + run(SANLOCK, "client", "status") + assert e.value.returncode == 1 + + def test_init_lockspace(tmpdir, sanlock_daemon): path = tmpdir.join("lockspace") with io.open(str(path), "wb") as f: