]>
Commit | Line | Data |
---|---|---|
2f9046fb | 1 | /* Support functions handling ptrace_scope. |
2b778ceb | 2 | Copyright (C) 2019-2021 Free Software Foundation, Inc. |
2f9046fb SL |
3 | This file is part of the GNU C Library. |
4 | ||
5 | The GNU C Library is free software; you can redistribute it and/or | |
6 | modify it under the terms of the GNU Lesser General Public | |
7 | License as published by the Free Software Foundation; either | |
8 | version 2.1 of the License, or (at your option) any later version. | |
9 | ||
10 | The GNU C Library is distributed in the hope that it will be useful, | |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | Lesser General Public License for more details. | |
14 | ||
15 | You should have received a copy of the GNU Lesser General Public | |
16 | License along with the GNU C Library; if not, see | |
17 | <https://www.gnu.org/licenses/>. */ | |
18 | ||
19 | #include <support/check.h> | |
20 | #include <support/xstdio.h> | |
21 | #include <support/xptrace.h> | |
2f9046fb SL |
22 | |
23 | int | |
24 | support_ptrace_scope (void) | |
25 | { | |
26 | int ptrace_scope = -1; | |
27 | ||
28 | #ifdef __linux__ | |
29 | /* YAMA may be not enabled. Otherwise it contains a value from 0 to 3: | |
30 | - 0 classic ptrace permissions | |
31 | - 1 restricted ptrace | |
32 | - 2 admin-only attach | |
33 | - 3 no attach */ | |
34 | FILE *f = fopen ("/proc/sys/kernel/yama/ptrace_scope", "r"); | |
35 | if (f != NULL) | |
36 | { | |
37 | TEST_COMPARE (fscanf (f, "%d", &ptrace_scope), 1); | |
38 | xfclose (f); | |
39 | } | |
40 | #endif | |
41 | ||
42 | return ptrace_scope; | |
43 | } |