xref: /openbmc/linux/tools/testing/selftests/bpf/unpriv_helpers.c (revision 34d6f206a88c2651d216bd3487ac956a40b2ba8e)
1 // SPDX-License-Identifier: GPL-2.0-only
2 
3 #include <stdbool.h>
4 #include <stdlib.h>
5 #include <stdio.h>
6 
7 #include "unpriv_helpers.h"
8 
get_unpriv_disabled(void)9 bool get_unpriv_disabled(void)
10 {
11 	bool disabled;
12 	char buf[2];
13 	FILE *fd;
14 
15 	fd = fopen("/proc/sys/" UNPRIV_SYSCTL, "r");
16 	if (fd) {
17 		disabled = (fgets(buf, 2, fd) == buf && atoi(buf));
18 		fclose(fd);
19 	} else {
20 		perror("fopen /proc/sys/" UNPRIV_SYSCTL);
21 		disabled = true;
22 	}
23 
24 	return disabled;
25 }
26