Commit 6e28ce28 authored by Simon McVittie's avatar Simon McVittie

tests: Don't assume that unprivileged uids are bound by RLIMIT_NPROC

Some CI platforms invoke tests as euid != 0, but with capabilities that
include CAP_SYS_RESOURCE and/or CAP_SYS_ADMIN. If we detect this,
we can't test what happens if our RLIMIT_NPROC is too low to create a
thread, because RLIMIT_NPROC is bypassed in these cases.
Signed-off-by: Simon McVittie's avatarSimon McVittie <>
Fixes: #2029
parent d6886d89
......@@ -138,12 +138,6 @@ test_thread4 (void)
GError *error;
gint ret;
/* Linux CAP_SYS_RESOURCE overrides RLIMIT_NPROC, and probably similar
* things are true on other systems.
if (getuid () == 0 || geteuid () == 0)
getrlimit (RLIMIT_NPROC, &nl);
nl.rlim_cur = 1;
......@@ -152,9 +146,26 @@ test_thread4 (void)
error = NULL;
thread = g_thread_try_new ("a", thread1_func, NULL, &error);
g_assert (thread == NULL);
g_assert_error (error, G_THREAD_ERROR, G_THREAD_ERROR_AGAIN);
g_error_free (error);
if (thread != NULL)
gpointer result;
/* Privileged processes might be able to create new threads even
* though the rlimit is too low. There isn't much we can do about
* this; we just can't test this failure mode in this situation. */
g_test_skip ("Unable to test g_thread_try_new() failing with EAGAIN "
"while privileged (CAP_SYS_RESOURCE, CAP_SYS_ADMIN or "
"euid 0?)");
result = g_thread_join (thread);
g_assert_cmpint (GPOINTER_TO_INT (result), ==, 1);
g_assert (thread == NULL);
g_assert_error (error, G_THREAD_ERROR, G_THREAD_ERROR_AGAIN);
g_error_free (error);
if ((ret = prlimit (getpid (), RLIMIT_NPROC, &ol, NULL)) != 0)
g_error ("resetting RLIMIT_NPROC failed: %s", g_strerror (errno));
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment