]>
Commit | Line | Data |
---|---|---|
ad0e8eb0 | 1 | /* Get file-specific information about a file. Linux version. |
04277e02 | 2 | Copyright (C) 2003-2019 Free Software Foundation, Inc. |
ad0e8eb0 UD |
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 | |
59ba27a6 | 16 | License along with the GNU C Library; if not, see |
5a82c748 | 17 | <https://www.gnu.org/licenses/>. */ |
ad0e8eb0 | 18 | |
bf067910 | 19 | #include <errno.h> |
d024596d | 20 | #include <fcntl.h> |
4c771a3b | 21 | #include <stdlib.h> |
ad0e8eb0 UD |
22 | #include <sysdep.h> |
23 | #include <time.h> | |
24 | #include <unistd.h> | |
7c22c7ec | 25 | #include <sys/resource.h> |
ca06321d | 26 | #include <sys/param.h> |
5db7adc4 | 27 | #include <not-cancel.h> |
7c22c7ec | 28 | #include <ldsodefs.h> |
ad0e8eb0 | 29 | |
f96853be UD |
30 | /* Legacy value of ARG_MAX. The macro is now not defined since the |
31 | actual value varies based on the stack size. */ | |
32 | #define legacy_ARG_MAX 131072 | |
33 | ||
34 | ||
ad0e8eb0 UD |
35 | static long int posix_sysconf (int name); |
36 | ||
ad0e8eb0 UD |
37 | |
38 | /* Get the value of the system variable NAME. */ | |
39 | long int | |
40 | __sysconf (int name) | |
41 | { | |
3bd1aa47 UD |
42 | const char *procfname = NULL; |
43 | ||
ad0e8eb0 UD |
44 | switch (name) |
45 | { | |
ad0e8eb0 | 46 | case _SC_MONOTONIC_CLOCK: |
182ed12e RM |
47 | case _SC_CPUTIME: |
48 | case _SC_THREAD_CPUTIME: | |
77b6f553 | 49 | return _POSIX_VERSION; |
182ed12e | 50 | |
7c22c7ec | 51 | case _SC_ARG_MAX: |
77b6f553 AZ |
52 | { |
53 | struct rlimit rlimit; | |
54 | /* Use getrlimit to get the stack limit. */ | |
55 | if (__getrlimit (RLIMIT_STACK, &rlimit) == 0) | |
56 | return MAX (legacy_ARG_MAX, rlimit.rlim_cur / 4); | |
7c22c7ec | 57 | |
77b6f553 AZ |
58 | return legacy_ARG_MAX; |
59 | } | |
7c22c7ec | 60 | |
d024596d | 61 | case _SC_NGROUPS_MAX: |
3bd1aa47 UD |
62 | /* Try to read the information from the /proc/sys/kernel/ngroups_max |
63 | file. */ | |
64 | procfname = "/proc/sys/kernel/ngroups_max"; | |
65 | break; | |
66 | ||
67 | case _SC_SIGQUEUE_MAX: | |
77b6f553 AZ |
68 | { |
69 | struct rlimit rlimit; | |
70 | if (__getrlimit (RLIMIT_SIGPENDING, &rlimit) == 0) | |
71 | return rlimit.rlim_cur; | |
5be0a688 | 72 | |
77b6f553 AZ |
73 | /* The /proc/sys/kernel/rtsig-max file contains the answer. */ |
74 | procfname = "/proc/sys/kernel/rtsig-max"; | |
75 | } | |
d024596d UD |
76 | break; |
77 | ||
ad0e8eb0 | 78 | default: |
d024596d | 79 | break; |
ad0e8eb0 | 80 | } |
3bd1aa47 UD |
81 | |
82 | if (procfname != NULL) | |
83 | { | |
c2284574 | 84 | int fd = __open_nocancel (procfname, O_RDONLY); |
3bd1aa47 UD |
85 | if (fd != -1) |
86 | { | |
87 | /* This is more than enough, the file contains a single integer. */ | |
88 | char buf[32]; | |
89 | ssize_t n; | |
a748eb31 | 90 | n = TEMP_FAILURE_RETRY (__read_nocancel (fd, buf, sizeof (buf) - 1)); |
c181840c | 91 | __close_nocancel_nostatus (fd); |
3bd1aa47 UD |
92 | |
93 | if (n > 0) | |
94 | { | |
95 | /* Terminate the string. */ | |
96 | buf[n] = '\0'; | |
97 | ||
98 | char *endp; | |
99 | long int res = strtol (buf, &endp, 10); | |
100 | if (endp != buf && (*endp == '\0' || *endp == '\n')) | |
101 | return res; | |
102 | } | |
103 | } | |
104 | } | |
105 | ||
d024596d | 106 | return posix_sysconf (name); |
ad0e8eb0 | 107 | } |
bf067910 UD |
108 | |
109 | /* Now the POSIX version. */ | |
110 | #undef __sysconf | |
111 | #define __sysconf static posix_sysconf | |
112 | #include <sysdeps/posix/sysconf.c> |