From 242d350fcf473aedd3b0c45295e600743615fd3b Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 4 Aug 2014 15:22:25 +0200 Subject: [PATCH] libnm-util/test: fix tests not to write a core file test_libnm_linking() executes ./test-libnm-linking which is supposed to crash. When the user set `ulimit -c unlimited` before, this will leave a left-over core file. In case of `make distcheck`, this is quite bad because it lets the make target fail: ERROR: files left in build directory after distclean: ./libnm-util/tests/core.31481 Fix this by setting the (soft) rlimit for writing core files to 0 before executing the test binary. Signed-off-by: Thomas Haller --- libnm-util/tests/test-general.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/libnm-util/tests/test-general.c b/libnm-util/tests/test-general.c index 26fba2e27a..468cdf21e8 100644 --- a/libnm-util/tests/test-general.c +++ b/libnm-util/tests/test-general.c @@ -25,6 +25,7 @@ #include #include #include +#include #include @@ -2446,6 +2447,26 @@ test_connection_normalize_virtual_iface_name (void) g_object_unref (con); } +static void +_test_libnm_linking_setup_child_process (gpointer user_data) +{ + int val; + struct rlimit limit; + + /* the child process is supposed to crash. We don't want it + * to write a core dump. */ + + val = getrlimit (RLIMIT_CORE, &limit); + if (val == 0) { + limit.rlim_cur = 0; + val = setrlimit (RLIMIT_CORE, &limit); + if (val == 0) + return; + } + /* on error, do not crash or fail assertion. Instead just exit */ + exit (1); +} + static void test_libnm_linking (void) { @@ -2454,7 +2475,8 @@ test_libnm_linking (void) int status; GError *error = NULL; - g_spawn_sync (BUILD_DIR, argv, NULL, 0 /*G_SPAWN_DEFAULT*/, NULL, NULL, + g_spawn_sync (BUILD_DIR, argv, NULL, 0 /*G_SPAWN_DEFAULT*/, + _test_libnm_linking_setup_child_process, NULL, &out, &err, &status, &error); g_assert_no_error (error);