summaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests/bpf/unpriv_helpers.c
blob: 2a6efbd0401e5b55a913ab7032aa99380a6d86b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// SPDX-License-Identifier: GPL-2.0-only

#include <stdbool.h>
#include <stdlib.h>
#include <error.h>
#include <stdio.h>

#include "unpriv_helpers.h"

bool get_unpriv_disabled(void)
{
	bool disabled;
	char buf[2];
	FILE *fd;

	fd = fopen("/proc/sys/" UNPRIV_SYSCTL, "r");
	if (fd) {
		disabled = (fgets(buf, 2, fd) == buf && atoi(buf));
		fclose(fd);
	} else {
		perror("fopen /proc/sys/" UNPRIV_SYSCTL);
		disabled = true;
	}

	return disabled;
}