test: tweak privilege tests for two more tests

These tests require properly privileged root users, hence skip things
when we don't have CAP_SYS_ADMIN.

Fixes: #19746
This commit is contained in:
Lennart Poettering
2021-06-03 11:30:56 +02:00
parent 6da5d7de78
commit c75370cc18
2 changed files with 7 additions and 6 deletions
+2 -2
View File
@@ -924,8 +924,8 @@ int main(int argc, char *argv[]) {
can_unshare = have_namespaces();
/* It is needed otherwise cgroup creation fails */
if (getuid() != 0)
return log_tests_skipped("not root");
if (geteuid() != 0 || have_effective_cap(CAP_SYS_ADMIN) <= 0)
return log_tests_skipped("not privileged");
r = enter_cgroup_subroot(NULL);
if (r == -ENOMEDIUM)
+5 -4
View File
@@ -4,6 +4,7 @@
#include <sys/statvfs.h>
#include "alloc-util.h"
#include "capability-util.h"
#include "fd-util.h"
#include "fileio.h"
#include "mount-util.h"
@@ -75,8 +76,8 @@ static void test_bind_remount_recursive(void) {
_cleanup_free_ char *subdir = NULL;
const char *p;
if (geteuid() != 0) {
(void) log_tests_skipped("not running as root");
if (geteuid() != 0 || have_effective_cap(CAP_SYS_ADMIN) <= 0) {
(void) log_tests_skipped("not running privileged");
return;
}
@@ -128,8 +129,8 @@ static void test_bind_remount_recursive(void) {
static void test_bind_remount_one(void) {
pid_t pid;
if (geteuid() != 0) {
(void) log_tests_skipped("not running as root");
if (geteuid() != 0 || have_effective_cap(CAP_SYS_ADMIN) <= 0) {
(void) log_tests_skipped("not running privileged");
return;
}