2016-12-09 07:18:27 +00:00
|
|
|
/* Common extra functions.
|
2023-01-06 21:08:04 +00:00
|
|
|
Copyright (C) 2016-2023 Free Software Foundation, Inc.
|
2021-10-06 19:05:48 +00:00
|
|
|
Copyright The GNU Toolchain Authors.
|
2016-12-09 07:18:27 +00:00
|
|
|
This file is part of the GNU C Library.
|
|
|
|
|
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
The GNU C Library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with the GNU C Library; if not, see
|
Prefer https to http for gnu.org and fsf.org URLs
Also, change sources.redhat.com to sourceware.org.
This patch was automatically generated by running the following shell
script, which uses GNU sed, and which avoids modifying files imported
from upstream:
sed -ri '
s,(http|ftp)(://(.*\.)?(gnu|fsf|sourceware)\.org($|[^.]|\.[^a-z])),https\2,g
s,(http|ftp)(://(.*\.)?)sources\.redhat\.com($|[^.]|\.[^a-z]),https\2sourceware.org\4,g
' \
$(find $(git ls-files) -prune -type f \
! -name '*.po' \
! -name 'ChangeLog*' \
! -path COPYING ! -path COPYING.LIB \
! -path manual/fdl-1.3.texi ! -path manual/lgpl-2.1.texi \
! -path manual/texinfo.tex ! -path scripts/config.guess \
! -path scripts/config.sub ! -path scripts/install-sh \
! -path scripts/mkinstalldirs ! -path scripts/move-if-change \
! -path INSTALL ! -path locale/programs/charmap-kw.h \
! -path po/libc.pot ! -path sysdeps/gnu/errlist.c \
! '(' -name configure \
-execdir test -f configure.ac -o -f configure.in ';' ')' \
! '(' -name preconfigure \
-execdir test -f preconfigure.ac ';' ')' \
-print)
and then by running 'make dist-prepare' to regenerate files built
from the altered files, and then executing the following to cleanup:
chmod a+x sysdeps/unix/sysv/linux/riscv/configure
# Omit irrelevant whitespace and comment-only changes,
# perhaps from a slightly-different Autoconf version.
git checkout -f \
sysdeps/csky/configure \
sysdeps/hppa/configure \
sysdeps/riscv/configure \
sysdeps/unix/sysv/linux/csky/configure
# Omit changes that caused a pre-commit check to fail like this:
# remote: *** error: sysdeps/powerpc/powerpc64/ppc-mcount.S: trailing lines
git checkout -f \
sysdeps/powerpc/powerpc64/ppc-mcount.S \
sysdeps/unix/sysv/linux/s390/s390-64/syscall.S
# Omit change that caused a pre-commit check to fail like this:
# remote: *** error: sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S: last line does not end in newline
git checkout -f sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S
2019-09-07 05:40:42 +00:00
|
|
|
<https://www.gnu.org/licenses/>. */
|
2016-12-09 07:18:27 +00:00
|
|
|
|
|
|
|
/* This header file should only contain definitions compatible with
|
|
|
|
C90. (Using __attribute__ is fine because <features.h> provides a
|
|
|
|
fallback.) */
|
|
|
|
|
|
|
|
#ifndef SUPPORT_H
|
|
|
|
#define SUPPORT_H
|
|
|
|
|
io: Return UNSUPPORTED if filesystem do not support 64 bit timestamps
Some Linux filesystems might not fully support 64 bit timestamps [1],
which make some Linux specific tests to fail when they check for the
functionality.
This patch adds a new libsupport function, support_path_support_time64,
that returns whether the target file supports or not 64 bit timestamps.
The support is checked by issuing a utimensat and verifying both the
last access and last modification time against a statx call.
The tests that might fail are also adjusted to check the file support
as well:
$ dd if=/dev/zero of=loopbackfile.img bs=100M count=1
1+0 records in
1+0 records out
104857600 bytes (105 MB, 100 MiB) copied, 0,0589568 s, 1,8 GB/s
$ sudo losetup -fP loopbackfile.img
$ mkfs.xfs loopbackfile.img
meta-data=loopbackfile.img isize=512 agcount=4, agsize=6400 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=0
= reflink=1
data = bsize=4096 blocks=25600, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1
log =internal log bsize=4096 blocks=1368, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
$ mkdir loopfs
$ sudo mount -o loop /dev/loop0 loopfs/
$ sudo chown -R azanella:azanella loopfs
$ TMPDIR=loopfs/ ./testrun.sh misc/tst-utimes
error: ../sysdeps/unix/sysv/linux/tst-utimes.c:55: File loopfs//utimesfECsK1 does not support 64-bit timestamps
[1] https://bugzilla.redhat.com/show_bug.cgi?id=1795576
2021-03-11 12:30:33 +00:00
|
|
|
#include <stdbool.h>
|
2021-06-16 16:44:03 +00:00
|
|
|
#include <stdint.h>
|
2016-12-09 07:18:27 +00:00
|
|
|
#include <stddef.h>
|
|
|
|
#include <sys/cdefs.h>
|
2018-07-06 05:10:41 +00:00
|
|
|
/* For mode_t. */
|
|
|
|
#include <sys/stat.h>
|
2018-08-31 20:07:47 +00:00
|
|
|
/* For ssize_t and off64_t. */
|
|
|
|
#include <sys/types.h>
|
2020-05-18 17:36:19 +00:00
|
|
|
/* For locale_t. */
|
|
|
|
#include <locale.h>
|
2016-12-09 07:18:27 +00:00
|
|
|
|
|
|
|
__BEGIN_DECLS
|
|
|
|
|
|
|
|
/* Write a message to standard output. Can be used in signal
|
|
|
|
handlers. */
|
|
|
|
void write_message (const char *message) __attribute__ ((nonnull (1)));
|
|
|
|
|
|
|
|
/* Avoid all the buffer overflow messages on stderr. */
|
|
|
|
void ignore_stderr (void);
|
|
|
|
|
|
|
|
/* Set fortification error handler. Used when tests want to verify that bad
|
|
|
|
code is caught by the library. */
|
|
|
|
void set_fortify_handler (void (*handler) (int sig));
|
|
|
|
|
|
|
|
/* Report an out-of-memory error for the allocation of SIZE bytes in
|
|
|
|
FUNCTION, terminating the process. */
|
|
|
|
void oom_error (const char *function, size_t size)
|
|
|
|
__attribute__ ((nonnull (1)));
|
|
|
|
|
2017-06-02 13:50:36 +00:00
|
|
|
/* Return a pointer to a memory region of SIZE bytes. The memory is
|
|
|
|
initialized to zero and will be shared with subprocesses (across
|
|
|
|
fork). The returned pointer must be freed using
|
|
|
|
support_shared_free; it is not compatible with the malloc
|
|
|
|
functions. */
|
|
|
|
void *support_shared_allocate (size_t size);
|
|
|
|
|
|
|
|
/* Deallocate a pointer returned by support_shared_allocate. */
|
|
|
|
void support_shared_free (void *);
|
|
|
|
|
|
|
|
/* Write CONTENTS to the file PATH. Create or truncate the file as
|
|
|
|
needed. The file mode is 0666 masked by the umask. Terminate the
|
|
|
|
process on error. */
|
|
|
|
void support_write_file_string (const char *path, const char *contents);
|
|
|
|
|
2018-05-16 15:00:35 +00:00
|
|
|
/* Quote the contents of the byte array starting at BLOB, of LENGTH
|
|
|
|
bytes, in such a way that the result string can be included in a C
|
|
|
|
literal (in single/double quotes, without putting the quotes into
|
|
|
|
the result). */
|
|
|
|
char *support_quote_blob (const void *blob, size_t length);
|
|
|
|
|
2021-10-12 13:48:39 +00:00
|
|
|
/* Quote the contents of the wide character array starting at BLOB, of
|
|
|
|
LENGTH wide characters, in such a way that the result string can be
|
|
|
|
included in a C wide string literal (in single/double quotes,
|
|
|
|
without putting the quotes into the result). */
|
|
|
|
char *support_quote_blob_wide (const void *blob, size_t length);
|
|
|
|
|
2018-11-28 06:00:48 +00:00
|
|
|
/* Quote the contents of the string, in such a way that the result
|
2018-11-27 20:35:56 +00:00
|
|
|
string can be included in a C literal (in single/double quotes,
|
|
|
|
without putting the quotes into the result). */
|
2018-11-28 06:00:48 +00:00
|
|
|
char *support_quote_string (const char *);
|
2018-11-27 20:35:56 +00:00
|
|
|
|
2018-08-21 10:56:53 +00:00
|
|
|
/* Returns non-zero if the file descriptor is a regular file on a file
|
|
|
|
system which supports holes (that is, seeking and writing does not
|
|
|
|
allocate storage for the range of zeros). FD must refer to a
|
|
|
|
regular file open for writing, and initially empty. */
|
|
|
|
int support_descriptor_supports_holes (int fd);
|
|
|
|
|
2022-03-29 03:53:33 +00:00
|
|
|
/* Predicates that a test requires a working /proc filesystem. This
|
|
|
|
call will exit with UNSUPPORTED if /proc is not available, printing
|
|
|
|
WHY_MSG as part of the diagnostic. */
|
|
|
|
void support_need_proc (const char *why_msg);
|
|
|
|
|
2016-12-09 07:18:27 +00:00
|
|
|
/* Error-checking wrapper functions which terminate the process on
|
|
|
|
error. */
|
|
|
|
|
2021-07-28 07:33:27 +00:00
|
|
|
extern void *xmalloc (size_t n)
|
|
|
|
__attribute_malloc__ __attribute_alloc_size__ ((1)) __attr_dealloc_free
|
|
|
|
__returns_nonnull;
|
|
|
|
extern void *xcalloc (size_t n, size_t s)
|
|
|
|
__attribute_malloc__ __attribute_alloc_size__ ((1, 2)) __attr_dealloc_free
|
|
|
|
__returns_nonnull;
|
|
|
|
extern void *xrealloc (void *o, size_t n)
|
|
|
|
__attribute_malloc__ __attribute_alloc_size__ ((2)) __attr_dealloc_free;
|
|
|
|
extern char *xstrdup (const char *) __attribute_malloc__ __attr_dealloc_free
|
|
|
|
__returns_nonnull;
|
|
|
|
void *xposix_memalign (size_t alignment, size_t n)
|
2021-10-06 19:05:48 +00:00
|
|
|
__attribute_malloc__ __attribute_alloc_align__ ((1))
|
|
|
|
__attribute_alloc_size__ ((2)) __attr_dealloc_free __returns_nonnull;
|
2016-12-09 07:18:27 +00:00
|
|
|
char *xasprintf (const char *format, ...)
|
2021-07-28 07:33:27 +00:00
|
|
|
__attribute__ ((format (printf, 1, 2), malloc)) __attr_dealloc_free
|
|
|
|
__returns_nonnull;
|
|
|
|
char *xstrdup (const char *) __attr_dealloc_free __returns_nonnull;
|
|
|
|
char *xstrndup (const char *, size_t) __attr_dealloc_free __returns_nonnull;
|
2019-11-11 13:57:23 +00:00
|
|
|
char *xsetlocale (int category, const char *locale);
|
2020-05-18 17:36:19 +00:00
|
|
|
locale_t xnewlocale (int category_mask, const char *locale, locale_t base);
|
|
|
|
char *xuselocale (locale_t newloc);
|
2016-12-09 07:18:27 +00:00
|
|
|
|
2018-07-06 05:10:41 +00:00
|
|
|
/* These point to the TOP of the source/build tree, not your (or
|
|
|
|
support's) subdirectory. */
|
|
|
|
extern const char support_srcdir_root[];
|
|
|
|
extern const char support_objdir_root[];
|
|
|
|
|
2018-10-04 11:07:29 +00:00
|
|
|
/* Corresponds to the path to the runtime linker used by the testsuite,
|
|
|
|
e.g. OBJDIR_PATH/elf/ld-linux-x86-64.so.2 */
|
|
|
|
extern const char support_objdir_elf_ldso[];
|
|
|
|
|
2018-07-06 05:10:41 +00:00
|
|
|
/* Corresponds to the --prefix= passed to configure. */
|
|
|
|
extern const char support_install_prefix[];
|
|
|
|
/* Corresponds to the install's lib/ or lib64/ directory. */
|
|
|
|
extern const char support_libdir_prefix[];
|
2019-05-13 16:57:37 +00:00
|
|
|
/* Corresponds to the install's bin/ directory. */
|
|
|
|
extern const char support_bindir_prefix[];
|
2019-05-13 17:31:53 +00:00
|
|
|
/* Corresponds to the install's sbin/ directory. */
|
2019-05-20 19:08:40 +00:00
|
|
|
extern const char support_sbindir_prefix[];
|
2020-12-11 16:24:08 +00:00
|
|
|
/* Corresponds to the install's system /lib or /lib64 directory. */
|
|
|
|
extern const char support_slibdir_prefix[];
|
2019-05-20 19:08:40 +00:00
|
|
|
/* Corresponds to the install's sbin/ directory (without prefix). */
|
2019-05-13 17:31:53 +00:00
|
|
|
extern const char support_install_rootsbindir[];
|
2020-01-08 18:24:42 +00:00
|
|
|
/* Corresponds to the install's compiled locale directory. */
|
|
|
|
extern const char support_complocaledir_prefix[];
|
2018-07-06 05:10:41 +00:00
|
|
|
|
2020-11-26 15:59:44 +00:00
|
|
|
/* Copies the file at the path FROM to TO. If TO does not exist, it
|
|
|
|
is created. If TO is a regular file, it is truncated before
|
|
|
|
copying. The file mode is copied, but the permissions are not. */
|
|
|
|
extern void support_copy_file (const char *from, const char *to);
|
|
|
|
|
2018-08-31 20:07:47 +00:00
|
|
|
extern ssize_t support_copy_file_range (int, off64_t *, int, off64_t *,
|
|
|
|
size_t, unsigned int);
|
|
|
|
|
2021-03-19 16:44:20 +00:00
|
|
|
/* Return true if PATH supports 64-bit time_t interfaces for file
|
io: Return UNSUPPORTED if filesystem do not support 64 bit timestamps
Some Linux filesystems might not fully support 64 bit timestamps [1],
which make some Linux specific tests to fail when they check for the
functionality.
This patch adds a new libsupport function, support_path_support_time64,
that returns whether the target file supports or not 64 bit timestamps.
The support is checked by issuing a utimensat and verifying both the
last access and last modification time against a statx call.
The tests that might fail are also adjusted to check the file support
as well:
$ dd if=/dev/zero of=loopbackfile.img bs=100M count=1
1+0 records in
1+0 records out
104857600 bytes (105 MB, 100 MiB) copied, 0,0589568 s, 1,8 GB/s
$ sudo losetup -fP loopbackfile.img
$ mkfs.xfs loopbackfile.img
meta-data=loopbackfile.img isize=512 agcount=4, agsize=6400 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=0
= reflink=1
data = bsize=4096 blocks=25600, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1
log =internal log bsize=4096 blocks=1368, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
$ mkdir loopfs
$ sudo mount -o loop /dev/loop0 loopfs/
$ sudo chown -R azanella:azanella loopfs
$ TMPDIR=loopfs/ ./testrun.sh misc/tst-utimes
error: ../sysdeps/unix/sysv/linux/tst-utimes.c:55: File loopfs//utimesfECsK1 does not support 64-bit timestamps
[1] https://bugzilla.redhat.com/show_bug.cgi?id=1795576
2021-03-11 12:30:33 +00:00
|
|
|
operations (such as fstatat or utimensat). */
|
2021-03-19 16:44:20 +00:00
|
|
|
extern bool support_path_support_time64_value (const char *path, int64_t at,
|
|
|
|
int64_t mt);
|
|
|
|
static __inline bool support_path_support_time64 (const char *path)
|
|
|
|
{
|
|
|
|
/* 1s and 2s after y2038 limit. */
|
|
|
|
return support_path_support_time64_value (path, 0x80000001ULL,
|
|
|
|
0x80000002ULL);
|
|
|
|
}
|
io: Return UNSUPPORTED if filesystem do not support 64 bit timestamps
Some Linux filesystems might not fully support 64 bit timestamps [1],
which make some Linux specific tests to fail when they check for the
functionality.
This patch adds a new libsupport function, support_path_support_time64,
that returns whether the target file supports or not 64 bit timestamps.
The support is checked by issuing a utimensat and verifying both the
last access and last modification time against a statx call.
The tests that might fail are also adjusted to check the file support
as well:
$ dd if=/dev/zero of=loopbackfile.img bs=100M count=1
1+0 records in
1+0 records out
104857600 bytes (105 MB, 100 MiB) copied, 0,0589568 s, 1,8 GB/s
$ sudo losetup -fP loopbackfile.img
$ mkfs.xfs loopbackfile.img
meta-data=loopbackfile.img isize=512 agcount=4, agsize=6400 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=0
= reflink=1
data = bsize=4096 blocks=25600, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1
log =internal log bsize=4096 blocks=1368, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
$ mkdir loopfs
$ sudo mount -o loop /dev/loop0 loopfs/
$ sudo chown -R azanella:azanella loopfs
$ TMPDIR=loopfs/ ./testrun.sh misc/tst-utimes
error: ../sysdeps/unix/sysv/linux/tst-utimes.c:55: File loopfs//utimesfECsK1 does not support 64-bit timestamps
[1] https://bugzilla.redhat.com/show_bug.cgi?id=1795576
2021-03-11 12:30:33 +00:00
|
|
|
|
2021-08-19 14:47:07 +00:00
|
|
|
/* Return true if the setitimer and getitimer syscalls support 64-bit time_t
|
|
|
|
values without resulting in overflow. This is not true on some linux systems
|
|
|
|
which have 64-bit time_t due to legacy kernel API's. */
|
|
|
|
static __inline bool support_itimer_support_time64 (void)
|
|
|
|
{
|
|
|
|
#ifdef __KERNEL_OLD_TIMEVAL_MATCHES_TIMEVAL64
|
|
|
|
return __KERNEL_OLD_TIMEVAL_MATCHES_TIMEVAL64;
|
|
|
|
#else
|
|
|
|
return sizeof (__time_t) == 8;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2021-06-10 08:09:51 +00:00
|
|
|
/* Return true if stat supports nanoseconds resolution. PATH is used
|
|
|
|
for tests and its ctime may change. */
|
2021-03-29 17:40:30 +00:00
|
|
|
extern bool support_stat_nanoseconds (const char *path);
|
2021-03-17 13:03:52 +00:00
|
|
|
|
2021-04-09 13:02:30 +00:00
|
|
|
/* Return true if select modify the timeout to reflect the amount of time
|
|
|
|
no slept. */
|
|
|
|
extern bool support_select_modifies_timeout (void);
|
|
|
|
|
2021-04-09 13:05:13 +00:00
|
|
|
/* Return true if select normalize the timeout input by taking in account
|
|
|
|
tv_usec larger than 1000000. */
|
|
|
|
extern bool support_select_normalizes_timeout (void);
|
|
|
|
|
2021-12-13 14:36:42 +00:00
|
|
|
/* Return true if socket FD supports 64-bit timestamps with the SOL_SOCKET
|
|
|
|
and SO_TIMESTAMP/SO_TIMESTAMPNS. */
|
|
|
|
extern bool support_socket_so_timestamp_time64 (int fd);
|
|
|
|
|
2021-06-16 16:44:03 +00:00
|
|
|
/* Create a timer that trigger after SEC seconds and NSEC nanoseconds. If
|
|
|
|
REPEAT is true the timer will repeat indefinitely. If CALLBACK is not
|
|
|
|
NULL, the function will be called when the timer expires; otherwise a
|
|
|
|
dummy empty function is used instead.
|
|
|
|
This is implemented with POSIX per-process timer with SIGEV_SIGNAL. */
|
|
|
|
timer_t support_create_timer (uint64_t sec, long int nsec, bool repeat,
|
|
|
|
void (*callback)(int));
|
|
|
|
/* Disable the timer TIMER. */
|
|
|
|
void support_delete_timer (timer_t timer);
|
|
|
|
|
2021-08-30 11:43:56 +00:00
|
|
|
/* Wait until all threads except the current thread have exited (as
|
|
|
|
far as the kernel is concerned). */
|
|
|
|
void support_wait_for_thread_exit (void);
|
|
|
|
|
2021-03-10 15:26:29 +00:00
|
|
|
struct support_stack
|
|
|
|
{
|
|
|
|
void *stack;
|
|
|
|
size_t size;
|
|
|
|
size_t guardsize;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Allocate stack suitable to used with xclone or sigaltstack call. The stack
|
|
|
|
will have a minimum size of SIZE + MINSIGSTKSZ bytes, rounded up to a whole
|
|
|
|
number of pages. There will be a large (at least 1 MiB) inaccessible guard
|
|
|
|
bands on either side of it.
|
|
|
|
The returned value on ALLOC_BASE and ALLOC_SIZE will be the usable stack
|
|
|
|
region, excluding the GUARD_SIZE allocated area.
|
|
|
|
It also terminates the process on error. */
|
|
|
|
struct support_stack support_stack_alloc (size_t size);
|
|
|
|
|
|
|
|
/* Deallocate the STACK. */
|
|
|
|
void support_stack_free (struct support_stack *stack);
|
|
|
|
|
2021-08-24 19:12:24 +00:00
|
|
|
|
|
|
|
/* Create a range of NUM opened '/dev/null' file descriptors using FLAGS and
|
|
|
|
MODE. The function takes care of restarting the open range if a file
|
|
|
|
descriptor is found within the specified range and also increases
|
|
|
|
RLIMIT_NOFILE if required.
|
|
|
|
The returned value is the lowest file descriptor number. */
|
|
|
|
int support_open_dev_null_range (int num, int flags, mode_t mode);
|
|
|
|
|
2016-12-09 07:18:27 +00:00
|
|
|
__END_DECLS
|
|
|
|
|
|
|
|
#endif /* SUPPORT_H */
|