|
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 |
#ifndef HAS_CPUCLOCK
|
|
Packit |
6c4009 |
static long int
|
|
Packit |
6c4009 |
has_cpuclock (int name)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
# if defined __NR_clock_getres || HP_TIMING_AVAIL
|
|
Packit |
6c4009 |
/* If we have HP_TIMING, we will fall back on that if the system
|
|
Packit |
6c4009 |
call does not work, so we support it either way. */
|
|
Packit |
6c4009 |
# if !HP_TIMING_AVAIL
|
|
Packit |
6c4009 |
/* Check using the clock_getres system call. */
|
|
Packit |
6c4009 |
struct timespec ts;
|
|
Packit |
6c4009 |
INTERNAL_SYSCALL_DECL (err);
|
|
Packit |
6c4009 |
int r = INTERNAL_SYSCALL (clock_getres, err, 2,
|
|
Packit |
6c4009 |
(name == _SC_CPUTIME
|
|
Packit |
6c4009 |
? CLOCK_PROCESS_CPUTIME_ID
|
|
Packit |
6c4009 |
: CLOCK_THREAD_CPUTIME_ID),
|
|
Packit |
6c4009 |
&ts);
|
|
Packit |
6c4009 |
if (INTERNAL_SYSCALL_ERROR_P (r, err))
|
|
Packit |
6c4009 |
return -1;
|
|
Packit |
6c4009 |
# endif
|
|
Packit |
6c4009 |
return _POSIX_VERSION;
|
|
Packit |
6c4009 |
# else
|
|
Packit |
6c4009 |
return -1;
|
|
Packit |
6c4009 |
# endif
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
# define HAS_CPUCLOCK(name) has_cpuclock (name)
|
|
Packit |
6c4009 |
#endif
|
|
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 |
struct rlimit rlimit;
|
|
Packit |
6c4009 |
#ifdef __NR_clock_getres
|
|
Packit |
6c4009 |
case _SC_MONOTONIC_CLOCK:
|
|
Packit |
6c4009 |
/* Check using the clock_getres system call. */
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
struct timespec ts;
|
|
Packit |
6c4009 |
INTERNAL_SYSCALL_DECL (err);
|
|
Packit |
6c4009 |
int r;
|
|
Packit |
6c4009 |
r = INTERNAL_SYSCALL (clock_getres, err, 2, CLOCK_MONOTONIC, &ts);
|
|
Packit |
6c4009 |
return INTERNAL_SYSCALL_ERROR_P (r, err) ? -1 : _POSIX_VERSION;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
#endif
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
case _SC_CPUTIME:
|
|
Packit |
6c4009 |
case _SC_THREAD_CPUTIME:
|
|
Packit |
6c4009 |
return HAS_CPUCLOCK (name);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
case _SC_ARG_MAX:
|
|
Packit |
6c4009 |
/* Use getrlimit to get the stack limit. */
|
|
Packit |
6c4009 |
if (__getrlimit (RLIMIT_STACK, &rlimit) == 0)
|
|
Packit |
6c4009 |
return MAX (legacy_ARG_MAX, rlimit.rlim_cur / 4);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
return legacy_ARG_MAX;
|
|
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 |
6c4009 |
if (__getrlimit (RLIMIT_SIGPENDING, &rlimit) == 0)
|
|
Packit |
6c4009 |
return rlimit.rlim_cur;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* The /proc/sys/kernel/rtsig-max file contains the answer. */
|
|
Packit |
6c4009 |
procfname = "/proc/sys/kernel/rtsig-max";
|
|
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>
|