|
Packit |
6c4009 |
/* Get file-specific information about a file. Linux version.
|
|
Packit |
6c4009 |
Copyright (C) 2003-2018 Free Software Foundation, Inc.
|
|
Packit |
6c4009 |
This file is part of the GNU C Library.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit |
6c4009 |
modify it under the terms of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License as published by the Free Software Foundation; either
|
|
Packit |
6c4009 |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit |
6c4009 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
6c4009 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
6c4009 |
Lesser General Public License for more details.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
You should have received a copy of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License along with the GNU C Library; if not, see
|
|
Packit |
6c4009 |
<http://www.gnu.org/licenses/>. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <errno.h>
|
|
Packit |
6c4009 |
#include <fcntl.h>
|
|
Packit |
6c4009 |
#include <stdlib.h>
|
|
Packit |
6c4009 |
#include <sysdep.h>
|
|
Packit |
6c4009 |
#include <time.h>
|
|
Packit |
6c4009 |
#include <unistd.h>
|
|
Packit |
6c4009 |
#include <sys/resource.h>
|
|
Packit |
6c4009 |
#include <sys/param.h>
|
|
Packit |
6c4009 |
#include <not-cancel.h>
|
|
Packit |
6c4009 |
#include <ldsodefs.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Legacy value of ARG_MAX. The macro is now not defined since the
|
|
Packit |
6c4009 |
actual value varies based on the stack size. */
|
|
Packit |
6c4009 |
#define legacy_ARG_MAX 131072
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
static long int posix_sysconf (int name);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Get the value of the system variable NAME. */
|
|
Packit |
6c4009 |
long int
|
|
Packit |
6c4009 |
__sysconf (int name)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
const char *procfname = NULL;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
switch (name)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
case _SC_MONOTONIC_CLOCK:
|
|
Packit |
6c4009 |
case _SC_CPUTIME:
|
|
Packit |
6c4009 |
case _SC_THREAD_CPUTIME:
|
|
Packit Service |
9843bb |
return _POSIX_VERSION;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
case _SC_ARG_MAX:
|
|
Packit Service |
9843bb |
{
|
|
Packit Service |
9843bb |
struct rlimit rlimit;
|
|
Packit Service |
9843bb |
/* Use getrlimit to get the stack limit. */
|
|
Packit Service |
9843bb |
if (__getrlimit (RLIMIT_STACK, &rlimit) == 0)
|
|
Packit Service |
9843bb |
return MAX (legacy_ARG_MAX, rlimit.rlim_cur / 4);
|
|
Packit |
6c4009 |
|
|
Packit Service |
9843bb |
return legacy_ARG_MAX;
|
|
Packit Service |
9843bb |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
case _SC_NGROUPS_MAX:
|
|
Packit |
6c4009 |
/* Try to read the information from the /proc/sys/kernel/ngroups_max
|
|
Packit |
6c4009 |
file. */
|
|
Packit |
6c4009 |
procfname = "/proc/sys/kernel/ngroups_max";
|
|
Packit |
6c4009 |
break;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
case _SC_SIGQUEUE_MAX:
|
|
Packit Service |
9843bb |
{
|
|
Packit Service |
9843bb |
struct rlimit rlimit;
|
|
Packit Service |
9843bb |
if (__getrlimit (RLIMIT_SIGPENDING, &rlimit) == 0)
|
|
Packit Service |
9843bb |
return rlimit.rlim_cur;
|
|
Packit |
6c4009 |
|
|
Packit Service |
9843bb |
/* The /proc/sys/kernel/rtsig-max file contains the answer. */
|
|
Packit Service |
9843bb |
procfname = "/proc/sys/kernel/rtsig-max";
|
|
Packit Service |
9843bb |
}
|
|
Packit |
6c4009 |
break;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
default:
|
|
Packit |
6c4009 |
break;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
if (procfname != NULL)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
int fd = __open_nocancel (procfname, O_RDONLY);
|
|
Packit |
6c4009 |
if (fd != -1)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
/* This is more than enough, the file contains a single integer. */
|
|
Packit |
6c4009 |
char buf[32];
|
|
Packit |
6c4009 |
ssize_t n;
|
|
Packit |
6c4009 |
n = TEMP_FAILURE_RETRY (__read_nocancel (fd, buf, sizeof (buf) - 1));
|
|
Packit |
6c4009 |
__close_nocancel_nostatus (fd);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
if (n > 0)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
/* Terminate the string. */
|
|
Packit |
6c4009 |
buf[n] = '\0';
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
char *endp;
|
|
Packit |
6c4009 |
long int res = strtol (buf, &endp, 10);
|
|
Packit |
6c4009 |
if (endp != buf && (*endp == '\0' || *endp == '\n'))
|
|
Packit |
6c4009 |
return res;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
return posix_sysconf (name);
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Now the POSIX version. */
|
|
Packit |
6c4009 |
#undef __sysconf
|
|
Packit |
6c4009 |
#define __sysconf static posix_sysconf
|
|
Packit |
6c4009 |
#include <sysdeps/posix/sysconf.c>
|