[gcr/wip/dueno/gitlab-ci: 2/4] test-secure-memory: Skip oversized tests when running as root



commit 7719b58b8ef844c5788cd886796cb79d0dc46bcb
Author: Daiki Ueno <dueno src gnome org>
Date:   Thu Jun 14 16:12:35 2018 +0200

    test-secure-memory: Skip oversized tests when running as root
    
    If the test program is running as a privileged user, it is not
    possible to set the limit of mlock().

 gcr/test-secure-memory.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
---
diff --git a/gcr/test-secure-memory.c b/gcr/test-secure-memory.c
index 7ef5b2f..2b9061c 100644
--- a/gcr/test-secure-memory.c
+++ b/gcr/test-secure-memory.c
@@ -32,6 +32,8 @@
 #include <stdio.h>
 #include <string.h>
 #include <sys/resource.h>
+#include <unistd.h>
+#include <sys/types.h>
 
 #define IS_ZERO -1
 
@@ -55,6 +57,15 @@ get_rlimit_memlock (void)
 {
        struct rlimit memlock;
 
+       /* If the test program is running as a privileged user, it is
+        * not possible to set the limit. Skip the test entirely.
+        * FIXME: make this check more accurate, e.g., using capabilities
+        */
+       if (getuid () == 0) {
+               g_test_skip ("test cannot run as root");
+               return 0;
+       }
+
        if (getrlimit (RLIMIT_MEMLOCK, &memlock) != 0)
                g_error ("getrlimit() failed: %s", strerror (errno));
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]