mirror of
https://github.com/systemd/systemd
synced 2026-04-01 04:34:51 +02:00
Compare commits
6 Commits
a2366debce
...
3b3113b87c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3b3113b87c | ||
|
|
6b656a5b40 | ||
|
|
9b55c4b859 | ||
|
|
907ce9c315 | ||
|
|
361beb82a5 | ||
|
|
b2a2f670ae |
@ -1,6 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||||
|
|
||||||
#include <linux/prctl.h>
|
|
||||||
#include <stdatomic.h>
|
#include <stdatomic.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/prctl.h>
|
#include <sys/prctl.h>
|
||||||
|
|||||||
@ -5,6 +5,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "dirent-util.h"
|
#include "dirent-util.h"
|
||||||
#include "env-util.h"
|
#include "env-util.h"
|
||||||
@ -54,6 +55,7 @@ static char* normalize_locale(const char *name) {
|
|||||||
return strdup(name);
|
return strdup(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __GLIBC__
|
||||||
static int add_locales_from_archive(Set *locales) {
|
static int add_locales_from_archive(Set *locales) {
|
||||||
/* Stolen from glibc... */
|
/* Stolen from glibc... */
|
||||||
|
|
||||||
@ -182,6 +184,34 @@ static int add_locales_from_libdir(Set *locales) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
static int add_locales_for_musl(Set *locales) {
|
||||||
|
int r;
|
||||||
|
|
||||||
|
assert(locales);
|
||||||
|
|
||||||
|
_cleanup_closedir_ DIR *dir = opendir("/usr/share/i18n/locales/musl/");
|
||||||
|
if (!dir)
|
||||||
|
return errno == ENOENT ? 0 : -errno;
|
||||||
|
|
||||||
|
FOREACH_DIRENT(de, dir, return -errno) {
|
||||||
|
if (de->d_type != DT_REG)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
char *z = normalize_locale(de->d_name);
|
||||||
|
if (!z)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
|
r = set_consume(locales, z);
|
||||||
|
if (r < 0)
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
int get_locales(char ***ret) {
|
int get_locales(char ***ret) {
|
||||||
_cleanup_set_free_ Set *locales = NULL;
|
_cleanup_set_free_ Set *locales = NULL;
|
||||||
int r;
|
int r;
|
||||||
@ -190,6 +220,7 @@ int get_locales(char ***ret) {
|
|||||||
if (!locales)
|
if (!locales)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
|
#ifdef __GLIBC__
|
||||||
r = add_locales_from_archive(locales);
|
r = add_locales_from_archive(locales);
|
||||||
if (r < 0 && r != -ENOENT)
|
if (r < 0 && r != -ENOENT)
|
||||||
return r;
|
return r;
|
||||||
@ -197,6 +228,11 @@ int get_locales(char ***ret) {
|
|||||||
r = add_locales_from_libdir(locales);
|
r = add_locales_from_libdir(locales);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
#else
|
||||||
|
r = add_locales_for_musl(locales);
|
||||||
|
if (r < 0)
|
||||||
|
return r;
|
||||||
|
#endif
|
||||||
|
|
||||||
char *locale;
|
char *locale;
|
||||||
SET_FOREACH(locale, locales) {
|
SET_FOREACH(locale, locales) {
|
||||||
@ -264,11 +300,25 @@ int locale_is_installed(const char *name) {
|
|||||||
if (STR_IN_SET(name, "C", "POSIX")) /* These ones are always OK */
|
if (STR_IN_SET(name, "C", "POSIX")) /* These ones are always OK */
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
#ifdef __GLIBC__
|
||||||
_cleanup_(freelocalep) locale_t loc = newlocale(LC_ALL_MASK, name, (locale_t) 0);
|
_cleanup_(freelocalep) locale_t loc = newlocale(LC_ALL_MASK, name, (locale_t) 0);
|
||||||
if (loc == (locale_t) 0)
|
if (loc == (locale_t) 0)
|
||||||
return errno == ENOMEM ? -ENOMEM : false;
|
return errno == ENOMEM ? -ENOMEM : false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
#else
|
||||||
|
/* musl also has C.UTF-8 as builtin */
|
||||||
|
if (streq(name, "C.UTF-8"))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
/* musl's newlocale() always succeeds and provides a fake locale object even when the locale does
|
||||||
|
* not exist. Hence, we need to explicitly check if the locale file exists. */
|
||||||
|
_cleanup_free_ char *p = path_join("/usr/share/i18n/locales/musl/", name);
|
||||||
|
if (!p)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
|
return access(p, F_OK) >= 0;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool is_locale_utf8_impl(void) {
|
static bool is_locale_utf8_impl(void) {
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||||
|
|
||||||
#include <grp.h>
|
#include <grp.h>
|
||||||
#include <linux/prctl.h>
|
|
||||||
#include <linux/sched.h>
|
#include <linux/sched.h>
|
||||||
#include <linux/securebits.h>
|
#include <linux/securebits.h>
|
||||||
#include <poll.h>
|
#include <poll.h>
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||||
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <linux/prctl.h>
|
|
||||||
#include <poll.h>
|
#include <poll.h>
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#include <sys/mount.h>
|
#include <sys/mount.h>
|
||||||
|
|||||||
@ -1,10 +1,9 @@
|
|||||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <features.h>
|
|
||||||
#include <linux/if.h> /* IWYU pragma: export */
|
#include <linux/if.h> /* IWYU pragma: export */
|
||||||
|
|
||||||
#define IF_NAMESIZE 16
|
#define IF_NAMESIZE 16
|
||||||
|
|
||||||
extern unsigned int if_nametoindex(const char *__ifname) __THROW;
|
extern unsigned int if_nametoindex(const char *__ifname);
|
||||||
extern char *if_indextoname(unsigned int __ifindex, char __ifname[IF_NAMESIZE]) __THROW;
|
extern char *if_indextoname(unsigned int __ifindex, char __ifname[IF_NAMESIZE]);
|
||||||
|
|||||||
@ -2,7 +2,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <features.h>
|
|
||||||
#include <linux/fs.h>
|
#include <linux/fs.h>
|
||||||
#include <linux/mount.h> /* IWYU pragma: export */
|
#include <linux/mount.h> /* IWYU pragma: export */
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
@ -29,20 +28,20 @@ enum
|
|||||||
};
|
};
|
||||||
|
|
||||||
/* Mount a filesystem. */
|
/* Mount a filesystem. */
|
||||||
extern int mount(const char *__special_file, const char *__dir, const char *__fstype, unsigned long int __rwflag, const void *__data) __THROW;
|
extern int mount(const char *__special_file, const char *__dir, const char *__fstype, unsigned long int __rwflag, const void *__data);
|
||||||
|
|
||||||
/* Unmount a filesystem. */
|
/* Unmount a filesystem. */
|
||||||
extern int umount(const char *__special_file) __THROW;
|
extern int umount(const char *__special_file);
|
||||||
|
|
||||||
/* Unmount a filesystem. Force unmounting if FLAGS is set to MNT_FORCE. */
|
/* Unmount a filesystem. Force unmounting if FLAGS is set to MNT_FORCE. */
|
||||||
extern int umount2(const char *__special_file, int __flags) __THROW;
|
extern int umount2(const char *__special_file, int __flags);
|
||||||
|
|
||||||
/* Open the filesystem referenced by FS_NAME so it can be configured for
|
/* Open the filesystem referenced by FS_NAME so it can be configured for
|
||||||
mouting. */
|
mouting. */
|
||||||
/* Defined since glibc-2.36.
|
/* Defined since glibc-2.36.
|
||||||
* Supported since kernel v5.2 (24dcb3d90a1f67fe08c68a004af37df059d74005). */
|
* Supported since kernel v5.2 (24dcb3d90a1f67fe08c68a004af37df059d74005). */
|
||||||
#if HAVE_FSOPEN
|
#if HAVE_FSOPEN
|
||||||
extern int fsopen(const char *__fs_name, unsigned int __flags) __THROW;
|
extern int fsopen(const char *__fs_name, unsigned int __flags);
|
||||||
#else
|
#else
|
||||||
int missing_fsopen(const char *fsname, unsigned flags);
|
int missing_fsopen(const char *fsname, unsigned flags);
|
||||||
# define fsopen missing_fsopen
|
# define fsopen missing_fsopen
|
||||||
@ -53,7 +52,7 @@ int missing_fsopen(const char *fsname, unsigned flags);
|
|||||||
/* Defined since glibc-2.36.
|
/* Defined since glibc-2.36.
|
||||||
* Supported since kernel v5.2 (93766fbd2696c2c4453dd8e1070977e9cd4e6b6d). */
|
* Supported since kernel v5.2 (93766fbd2696c2c4453dd8e1070977e9cd4e6b6d). */
|
||||||
#if HAVE_FSMOUNT
|
#if HAVE_FSMOUNT
|
||||||
extern int fsmount(int __fd, unsigned int __flags, unsigned int __ms_flags) __THROW;
|
extern int fsmount(int __fd, unsigned int __flags, unsigned int __ms_flags);
|
||||||
#else
|
#else
|
||||||
int missing_fsmount(int fd, unsigned flags, unsigned ms_flags);
|
int missing_fsmount(int fd, unsigned flags, unsigned ms_flags);
|
||||||
# define fsmount missing_fsmount
|
# define fsmount missing_fsmount
|
||||||
@ -65,7 +64,7 @@ int missing_fsmount(int fd, unsigned flags, unsigned ms_flags);
|
|||||||
/* Defined since glibc-2.36.
|
/* Defined since glibc-2.36.
|
||||||
* Supported since kernel v5.2 (2db154b3ea8e14b04fee23e3fdfd5e9d17fbc6ae). */
|
* Supported since kernel v5.2 (2db154b3ea8e14b04fee23e3fdfd5e9d17fbc6ae). */
|
||||||
#if HAVE_MOVE_MOUNT
|
#if HAVE_MOVE_MOUNT
|
||||||
extern int move_mount(int __from_dfd, const char *__from_pathname, int __to_dfd, const char *__to_pathname, unsigned int flags) __THROW;
|
extern int move_mount(int __from_dfd, const char *__from_pathname, int __to_dfd, const char *__to_pathname, unsigned int flags);
|
||||||
#else
|
#else
|
||||||
int missing_move_mount(int from_dfd, const char *from_pathname, int to_dfd, const char *to_pathname, unsigned flags);
|
int missing_move_mount(int from_dfd, const char *from_pathname, int to_dfd, const char *to_pathname, unsigned flags);
|
||||||
# define move_mount missing_move_mount
|
# define move_mount missing_move_mount
|
||||||
@ -76,7 +75,7 @@ int missing_move_mount(int from_dfd, const char *from_pathname, int to_dfd, cons
|
|||||||
/* Defined since glibc-2.36.
|
/* Defined since glibc-2.36.
|
||||||
* Supported since kernel v5.2 (ecdab150fddb42fe6a739335257949220033b782). */
|
* Supported since kernel v5.2 (ecdab150fddb42fe6a739335257949220033b782). */
|
||||||
#if HAVE_FSCONFIG
|
#if HAVE_FSCONFIG
|
||||||
extern int fsconfig(int __fd, unsigned int __cmd, const char *__key, const void *__value, int __aux) __THROW;
|
extern int fsconfig(int __fd, unsigned int __cmd, const char *__key, const void *__value, int __aux);
|
||||||
#else
|
#else
|
||||||
int missing_fsconfig(int fd, unsigned cmd, const char *key, const void *value, int aux);
|
int missing_fsconfig(int fd, unsigned cmd, const char *key, const void *value, int aux);
|
||||||
# define fsconfig missing_fsconfig
|
# define fsconfig missing_fsconfig
|
||||||
@ -86,7 +85,7 @@ int missing_fsconfig(int fd, unsigned cmd, const char *key, const void *value, i
|
|||||||
/* Defined since glibc-2.36.
|
/* Defined since glibc-2.36.
|
||||||
* Supported since kernel v5.2 (a07b20004793d8926f78d63eb5980559f7813404). */
|
* Supported since kernel v5.2 (a07b20004793d8926f78d63eb5980559f7813404). */
|
||||||
#if HAVE_OPEN_TREE
|
#if HAVE_OPEN_TREE
|
||||||
extern int open_tree(int __dfd, const char *__filename, unsigned int __flags) __THROW;
|
extern int open_tree(int __dfd, const char *__filename, unsigned int __flags);
|
||||||
#else
|
#else
|
||||||
int missing_open_tree(int dfd, const char *filename, unsigned flags);
|
int missing_open_tree(int dfd, const char *filename, unsigned flags);
|
||||||
# define open_tree missing_open_tree
|
# define open_tree missing_open_tree
|
||||||
@ -100,7 +99,7 @@ int missing_open_tree(int dfd, const char *filename, unsigned flags);
|
|||||||
/* Defined since glibc-2.36.
|
/* Defined since glibc-2.36.
|
||||||
* Supported since kernel v5.12 (2a1867219c7b27f928e2545782b86daaf9ad50bd). */
|
* Supported since kernel v5.12 (2a1867219c7b27f928e2545782b86daaf9ad50bd). */
|
||||||
#if HAVE_MOUNT_SETATTR
|
#if HAVE_MOUNT_SETATTR
|
||||||
extern int mount_setattr(int __dfd, const char *__path, unsigned int __flags, struct mount_attr *__uattr, size_t __usize) __THROW;
|
extern int mount_setattr(int __dfd, const char *__path, unsigned int __flags, struct mount_attr *__uattr, size_t __usize);
|
||||||
#else
|
#else
|
||||||
int missing_mount_setattr(int dfd, const char *path, unsigned flags, struct mount_attr *attr, size_t size);
|
int missing_mount_setattr(int dfd, const char *path, unsigned flags, struct mount_attr *attr, size_t size);
|
||||||
# define mount_setattr missing_mount_setattr
|
# define mount_setattr missing_mount_setattr
|
||||||
@ -109,7 +108,7 @@ int missing_mount_setattr(int dfd, const char *path, unsigned flags, struct moun
|
|||||||
/* Not defined in glibc yet as of glibc-2.41.
|
/* Not defined in glibc yet as of glibc-2.41.
|
||||||
* Supported since kernel v6.15 (c4a16820d90199409c9bf01c4f794e1e9e8d8fd8). */
|
* Supported since kernel v6.15 (c4a16820d90199409c9bf01c4f794e1e9e8d8fd8). */
|
||||||
#if HAVE_OPEN_TREE_ATTR
|
#if HAVE_OPEN_TREE_ATTR
|
||||||
extern int open_tree_attr(int __dfd, const char *__filename, unsigned int __flags, struct mount_attr *__uattr, size_t __usize) __THROW;
|
extern int open_tree_attr(int __dfd, const char *__filename, unsigned int __flags, struct mount_attr *__uattr, size_t __usize);
|
||||||
#else
|
#else
|
||||||
int missing_open_tree_attr(int dfd, const char *filename, unsigned int flags, struct mount_attr *attr, size_t size);
|
int missing_open_tree_attr(int dfd, const char *filename, unsigned int flags, struct mount_attr *attr, size_t size);
|
||||||
# define open_tree_attr missing_open_tree_attr
|
# define open_tree_attr missing_open_tree_attr
|
||||||
|
|||||||
@ -229,9 +229,7 @@ TEST(sd_bus_error_set_errnof) {
|
|||||||
|
|
||||||
assert_se(sd_bus_error_set_errnof(&error, EACCES, NULL) == -EACCES);
|
assert_se(sd_bus_error_set_errnof(&error, EACCES, NULL) == -EACCES);
|
||||||
assert_se(sd_bus_error_has_name(&error, SD_BUS_ERROR_ACCESS_DENIED));
|
assert_se(sd_bus_error_has_name(&error, SD_BUS_ERROR_ACCESS_DENIED));
|
||||||
errno = EACCES;
|
ASSERT_STREQ(error.message, STRERROR(EACCES));
|
||||||
assert_se(asprintf(&str, "%m") >= 0);
|
|
||||||
assert_se(streq(error.message, str));
|
|
||||||
assert_se(error._need_free == 0);
|
assert_se(error._need_free == 0);
|
||||||
|
|
||||||
str = mfree(str);
|
str = mfree(str);
|
||||||
@ -239,9 +237,7 @@ TEST(sd_bus_error_set_errnof) {
|
|||||||
|
|
||||||
assert_se(sd_bus_error_set_errnof(&error, ENOANO, NULL) == -ENOANO);
|
assert_se(sd_bus_error_set_errnof(&error, ENOANO, NULL) == -ENOANO);
|
||||||
assert_se(sd_bus_error_has_name(&error, "System.Error.ENOANO"));
|
assert_se(sd_bus_error_has_name(&error, "System.Error.ENOANO"));
|
||||||
errno = ENOANO;
|
ASSERT_STREQ(error.message, STRERROR(ENOANO));
|
||||||
assert_se(asprintf(&str, "%m") >= 0);
|
|
||||||
assert_se(streq(error.message, str));
|
|
||||||
assert_se(error._need_free == 1);
|
assert_se(error._need_free == 1);
|
||||||
|
|
||||||
str = mfree(str);
|
str = mfree(str);
|
||||||
@ -249,9 +245,7 @@ TEST(sd_bus_error_set_errnof) {
|
|||||||
|
|
||||||
assert_se(sd_bus_error_set_errnof(&error, 100000, NULL) == -100000);
|
assert_se(sd_bus_error_set_errnof(&error, 100000, NULL) == -100000);
|
||||||
assert_se(sd_bus_error_has_name(&error, SD_BUS_ERROR_FAILED));
|
assert_se(sd_bus_error_has_name(&error, SD_BUS_ERROR_FAILED));
|
||||||
errno = 100000;
|
ASSERT_STREQ(error.message, STRERROR(100000));
|
||||||
assert_se(asprintf(&str, "%m") >= 0);
|
|
||||||
assert_se(streq(error.message, str));
|
|
||||||
assert_se(error._need_free == 1);
|
assert_se(error._need_free == 1);
|
||||||
|
|
||||||
str = mfree(str);
|
str = mfree(str);
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||||
|
|
||||||
#include <linux/prctl.h>
|
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||||
|
|
||||||
#include <fnmatch.h>
|
#include <fnmatch.h>
|
||||||
#include <linux/prctl.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <sys/mount.h>
|
#include <sys/mount.h>
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||||
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <linux/prctl.h>
|
|
||||||
#include <sched.h>
|
#include <sched.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <sys/prctl.h>
|
#include <sys/prctl.h>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user