summaryrefslogtreecommitdiff
path: root/src/libsystemd-basic/include/systemd-basic
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@sbcglobal.net>2016-12-17 03:11:52 -0500
committerLuke Shumaker <lukeshu@sbcglobal.net>2016-12-17 03:11:52 -0500
commitb849891b5dde5ee14ab8b7b7db74e65a4a38d993 (patch)
tree29bb0e6fda9b4b170041913de495da057bbe3621 /src/libsystemd-basic/include/systemd-basic
parent004efebf9cc559ea131bb9460ee0ee198e2d5da7 (diff)
parent881228ff72434a0e3401a16bd87f179ef0ab1619 (diff)
Merge branch 'notsystemd/postmove' into notsystemd/master
# Conflicts: # src/grp-journal/libjournal-core/.gitignore # src/grp-system/libcore/include/core/mount.h
Diffstat (limited to 'src/libsystemd-basic/include/systemd-basic')
-rw-r--r--src/libsystemd-basic/include/systemd-basic/alloc-util.h8
-rw-r--r--src/libsystemd-basic/include/systemd-basic/architecture.h12
-rw-r--r--src/libsystemd-basic/include/systemd-basic/calendarspec.h1
-rw-r--r--src/libsystemd-basic/include/systemd-basic/cgroup-util.h26
-rw-r--r--src/libsystemd-basic/include/systemd-basic/def.h2
-rw-r--r--src/libsystemd-basic/include/systemd-basic/exit-status.h14
-rw-r--r--src/libsystemd-basic/include/systemd-basic/fileio.h2
-rw-r--r--src/libsystemd-basic/include/systemd-basic/fs-util.h5
-rw-r--r--src/libsystemd-basic/include/systemd-basic/list.h2
-rw-r--r--src/libsystemd-basic/include/systemd-basic/log.h10
-rw-r--r--src/libsystemd-basic/include/systemd-basic/missing.h61
-rw-r--r--src/libsystemd-basic/include/systemd-basic/mount-util.h11
-rw-r--r--src/libsystemd-basic/include/systemd-basic/parse-util.h3
-rw-r--r--src/libsystemd-basic/include/systemd-basic/path-util.h3
-rw-r--r--src/libsystemd-basic/include/systemd-basic/proc-cmdline.h4
-rw-r--r--src/libsystemd-basic/include/systemd-basic/process-util.h5
-rw-r--r--src/libsystemd-basic/include/systemd-basic/set.h8
-rw-r--r--src/libsystemd-basic/include/systemd-basic/socket-util.h4
-rw-r--r--src/libsystemd-basic/include/systemd-basic/special.h3
-rw-r--r--src/libsystemd-basic/include/systemd-basic/string-util.h7
-rw-r--r--src/libsystemd-basic/include/systemd-basic/strv.h16
-rw-r--r--src/libsystemd-basic/include/systemd-basic/terminal-util.h53
-rw-r--r--src/libsystemd-basic/include/systemd-basic/time-util.h5
-rw-r--r--src/libsystemd-basic/include/systemd-basic/user-util.h24
-rw-r--r--src/libsystemd-basic/include/systemd-basic/util.h4
-rw-r--r--src/libsystemd-basic/include/systemd-basic/virt.h2
26 files changed, 227 insertions, 68 deletions
diff --git a/src/libsystemd-basic/include/systemd-basic/alloc-util.h b/src/libsystemd-basic/include/systemd-basic/alloc-util.h
index ceeee519b7..a44dd473c1 100644
--- a/src/libsystemd-basic/include/systemd-basic/alloc-util.h
+++ b/src/libsystemd-basic/include/systemd-basic/alloc-util.h
@@ -43,6 +43,14 @@ static inline void *mfree(void *memory) {
return NULL;
}
+#define free_and_replace(a, b) \
+ ({ \
+ free(a); \
+ (a) = (b); \
+ (b) = NULL; \
+ 0; \
+ })
+
void* memdup(const void *p, size_t l) _alloc_(2);
static inline void freep(void *p) {
diff --git a/src/libsystemd-basic/include/systemd-basic/architecture.h b/src/libsystemd-basic/include/systemd-basic/architecture.h
index b3e4d85906..5a77c31932 100644
--- a/src/libsystemd-basic/include/systemd-basic/architecture.h
+++ b/src/libsystemd-basic/include/systemd-basic/architecture.h
@@ -58,6 +58,8 @@ enum {
ARCHITECTURE_TILEGX,
ARCHITECTURE_CRIS,
ARCHITECTURE_NIOS2,
+ ARCHITECTURE_RISCV32,
+ ARCHITECTURE_RISCV64,
_ARCHITECTURE_MAX,
_ARCHITECTURE_INVALID = -1
};
@@ -191,6 +193,16 @@ int uname_architecture(void);
#elif defined(__nios2__)
# define native_architecture() ARCHITECTURE_NIOS2
# define LIB_ARCH_TUPLE "nios2-linux-gnu"
+#elif defined(__riscv__)
+# if __SIZEOF_POINTER__ == 4
+# define native_architecture() ARCHITECTURE_RISCV32
+# define LIB_ARCH_TUPLE "riscv32-linux-gnu"
+# elif __SIZEOF_POINTER__ == 8
+# define native_architecture() ARCHITECTURE_RISCV64
+# define LIB_ARCH_TUPLE "riscv64-linux-gnu"
+# else
+# error "Unrecognized riscv architecture variant"
+# endif
#else
# error "Please register your architecture here!"
#endif
diff --git a/src/libsystemd-basic/include/systemd-basic/calendarspec.h b/src/libsystemd-basic/include/systemd-basic/calendarspec.h
index f6472c1244..c6087228fd 100644
--- a/src/libsystemd-basic/include/systemd-basic/calendarspec.h
+++ b/src/libsystemd-basic/include/systemd-basic/calendarspec.h
@@ -37,6 +37,7 @@ typedef struct CalendarComponent {
typedef struct CalendarSpec {
int weekdays_bits;
bool utc;
+ int dst;
CalendarComponent *year;
CalendarComponent *month;
diff --git a/src/libsystemd-basic/include/systemd-basic/cgroup-util.h b/src/libsystemd-basic/include/systemd-basic/cgroup-util.h
index 14ebde5fc9..0aa27c4cd7 100644
--- a/src/libsystemd-basic/include/systemd-basic/cgroup-util.h
+++ b/src/libsystemd-basic/include/systemd-basic/cgroup-util.h
@@ -23,6 +23,7 @@
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
+#include <sys/statfs.h>
#include <sys/types.h>
#include "def.h"
@@ -112,6 +113,17 @@ static inline bool CGROUP_BLKIO_WEIGHT_IS_OK(uint64_t x) {
(x >= CGROUP_BLKIO_WEIGHT_MIN && x <= CGROUP_BLKIO_WEIGHT_MAX);
}
+/* Default resource limits */
+#define DEFAULT_TASKS_MAX_PERCENTAGE 15U /* 15% of PIDs, 4915 on default settings */
+#define DEFAULT_USER_TASKS_MAX_PERCENTAGE 33U /* 33% of PIDs, 10813 on default settings */
+
+typedef enum CGroupUnified {
+ CGROUP_UNIFIED_UNKNOWN = -1,
+ CGROUP_UNIFIED_NONE = 0, /* Both systemd and controllers on legacy */
+ CGROUP_UNIFIED_SYSTEMD = 1, /* Only systemd on unified */
+ CGROUP_UNIFIED_ALL = 2, /* Both systemd and controllers on unified */
+} CGroupUnified;
+
/*
* General rules:
*
@@ -169,10 +181,14 @@ int cg_create_and_attach(const char *controller, const char *path, pid_t pid);
int cg_set_attribute(const char *controller, const char *path, const char *attribute, const char *value);
int cg_get_attribute(const char *controller, const char *path, const char *attribute, char **ret);
+int cg_get_keyed_attribute(const char *controller, const char *path, const char *attribute, const char **keys, char **values);
int cg_set_group_access(const char *controller, const char *path, mode_t mode, uid_t uid, gid_t gid);
int cg_set_task_access(const char *controller, const char *path, mode_t mode, uid_t uid, gid_t gid);
+int cg_set_xattr(const char *controller, const char *path, const char *name, const void *value, size_t size, int flags);
+int cg_get_xattr(const char *controller, const char *path, const char *name, void *value, size_t size);
+
int cg_install_release_agent(const char *controller, const char *agent);
int cg_uninstall_release_agent(const char *controller);
@@ -222,11 +238,16 @@ int cg_mask_supported(CGroupMask *ret);
int cg_kernel_controllers(Set *controllers);
-int cg_unified(void);
+bool cg_ns_supported(void);
+
+int cg_all_unified(void);
+int cg_unified(const char *controller);
void cg_unified_flush(void);
bool cg_is_unified_wanted(void);
bool cg_is_legacy_wanted(void);
+bool cg_is_unified_systemd_controller_wanted(void);
+bool cg_is_legacy_systemd_controller_wanted(void);
const char* cgroup_controller_to_string(CGroupController c) _const_;
CGroupController cgroup_controller_from_string(const char *s) _pure_;
@@ -234,3 +255,6 @@ CGroupController cgroup_controller_from_string(const char *s) _pure_;
int cg_weight_parse(const char *s, uint64_t *ret);
int cg_cpu_shares_parse(const char *s, uint64_t *ret);
int cg_blkio_weight_parse(const char *s, uint64_t *ret);
+
+bool is_cgroup_fs(const struct statfs *s);
+bool fd_is_cgroup_fs(int fd);
diff --git a/src/libsystemd-basic/include/systemd-basic/def.h b/src/libsystemd-basic/include/systemd-basic/def.h
index 1a7a0f4928..2266eff650 100644
--- a/src/libsystemd-basic/include/systemd-basic/def.h
+++ b/src/libsystemd-basic/include/systemd-basic/def.h
@@ -79,7 +79,7 @@
#endif
/* Return a nulstr for a standard cascade of configuration paths,
- * suitable to pass to conf_files_list_nulstr() or config_parse_many()
+ * suitable to pass to conf_files_list_nulstr() or config_parse_many_nulstr()
* to implement drop-in directories for extending configuration
* files. */
#define CONF_PATHS_NULSTR(n) \
diff --git a/src/libsystemd-basic/include/systemd-basic/exit-status.h b/src/libsystemd-basic/include/systemd-basic/exit-status.h
index 2309f68815..0cfdfd7891 100644
--- a/src/libsystemd-basic/include/systemd-basic/exit-status.h
+++ b/src/libsystemd-basic/include/systemd-basic/exit-status.h
@@ -31,7 +31,7 @@
* https://refspecs.linuxbase.org/LSB_5.0.0/LSB-Core-generic/LSB-Core-generic/iniscrptact.html
*/
-typedef enum ExitStatus {
+enum {
/* EXIT_SUCCESS defined by libc */
/* EXIT_FAILURE defined by libc */
EXIT_INVALIDARGUMENT = 2,
@@ -82,7 +82,7 @@ typedef enum ExitStatus {
EXIT_MAKE_STARTER,
EXIT_CHOWN,
EXIT_SMACK_PROCESS_LABEL,
-} ExitStatus;
+};
typedef enum ExitStatusLevel {
EXIT_STATUS_MINIMAL, /* only cover libc EXIT_STATUS/EXIT_FAILURE */
@@ -96,10 +96,14 @@ typedef struct ExitStatusSet {
Set *signal;
} ExitStatusSet;
-const char* exit_status_to_string(ExitStatus status, ExitStatusLevel level) _const_;
+const char* exit_status_to_string(int status, ExitStatusLevel level) _const_;
-bool is_clean_exit(int code, int status, ExitStatusSet *success_status);
-bool is_clean_exit_lsb(int code, int status, ExitStatusSet *success_status);
+typedef enum ExitClean {
+ EXIT_CLEAN_DAEMON,
+ EXIT_CLEAN_COMMAND,
+} ExitClean;
+
+bool is_clean_exit(int code, int status, ExitClean clean, ExitStatusSet *success_status);
void exit_status_set_free(ExitStatusSet *x);
bool exit_status_set_is_empty(ExitStatusSet *x);
diff --git a/src/libsystemd-basic/include/systemd-basic/fileio.h b/src/libsystemd-basic/include/systemd-basic/fileio.h
index 9ac497d9eb..b58c83e64a 100644
--- a/src/libsystemd-basic/include/systemd-basic/fileio.h
+++ b/src/libsystemd-basic/include/systemd-basic/fileio.h
@@ -71,7 +71,7 @@ int search_and_fopen_nulstr(const char *path, const char *mode, const char *root
int fflush_and_check(FILE *f);
int fopen_temporary(const char *path, FILE **_f, char **_temp_path);
-int mkostemp_safe(char *pattern, int flags);
+int mkostemp_safe(char *pattern);
int tempfn_xxxxxx(const char *p, const char *extra, char **ret);
int tempfn_random(const char *p, const char *extra, char **ret);
diff --git a/src/libsystemd-basic/include/systemd-basic/fs-util.h b/src/libsystemd-basic/include/systemd-basic/fs-util.h
index 075e5942b1..31df47cf1e 100644
--- a/src/libsystemd-basic/include/systemd-basic/fs-util.h
+++ b/src/libsystemd-basic/include/systemd-basic/fs-util.h
@@ -61,7 +61,8 @@ int mkfifo_atomic(const char *path, mode_t mode);
int get_files_in_directory(const char *path, char ***list);
-int var_tmp(char **ret);
+int tmp_dir(const char **ret);
+int var_tmp_dir(const char **ret);
#define INOTIFY_EVENT_MAX (sizeof(struct inotify_event) + NAME_MAX + 1)
@@ -76,3 +77,5 @@ union inotify_event_buffer {
};
int inotify_add_watch_fd(int fd, int what, uint32_t mask);
+
+int chase_symlinks(const char *path, const char *_root, char **ret);
diff --git a/src/libsystemd-basic/include/systemd-basic/list.h b/src/libsystemd-basic/include/systemd-basic/list.h
index 5962aa4211..c3771a177f 100644
--- a/src/libsystemd-basic/include/systemd-basic/list.h
+++ b/src/libsystemd-basic/include/systemd-basic/list.h
@@ -142,6 +142,8 @@
} else { \
if ((_b->name##_prev = _a->name##_prev)) \
_b->name##_prev->name##_next = _b; \
+ else \
+ *_head = _b; \
_b->name##_next = _a; \
_a->name##_prev = _b; \
} \
diff --git a/src/libsystemd-basic/include/systemd-basic/log.h b/src/libsystemd-basic/include/systemd-basic/log.h
index d2a22b5829..f5f62e1c23 100644
--- a/src/libsystemd-basic/include/systemd-basic/log.h
+++ b/src/libsystemd-basic/include/systemd-basic/log.h
@@ -100,18 +100,22 @@ int log_object_internal(
const char *func,
const char *object_field,
const char *object,
- const char *format, ...) _printf_(8,9);
+ const char *extra_field,
+ const char *extra,
+ const char *format, ...) _printf_(10,11);
int log_object_internalv(
int level,
int error,
- const char*file,
+ const char *file,
int line,
const char *func,
const char *object_field,
const char *object,
+ const char *extra_field,
+ const char *extra,
const char *format,
- va_list ap) _printf_(8,0);
+ va_list ap) _printf_(9,0);
int log_struct_internal(
int level,
diff --git a/src/libsystemd-basic/include/systemd-basic/missing.h b/src/libsystemd-basic/include/systemd-basic/missing.h
index 8721b075bb..85d086eb9b 100644
--- a/src/libsystemd-basic/include/systemd-basic/missing.h
+++ b/src/libsystemd-basic/include/systemd-basic/missing.h
@@ -446,6 +446,10 @@ struct btrfs_ioctl_quota_ctl_args {
#define CGROUP2_SUPER_MAGIC 0x63677270
#endif
+#ifndef CLONE_NEWCGROUP
+#define CLONE_NEWCGROUP 0x02000000
+#endif
+
#ifndef TMPFS_MAGIC
#define TMPFS_MAGIC 0x01021994
#endif
@@ -470,24 +474,44 @@ struct btrfs_ioctl_quota_ctl_args {
#define MS_MOVE 8192
#endif
+#ifndef MS_REC
+#define MS_REC 16384
+#endif
+
#ifndef MS_PRIVATE
-#define MS_PRIVATE (1 << 18)
+#define MS_PRIVATE (1<<18)
#endif
-#ifndef SCM_SECURITY
-#define SCM_SECURITY 0x03
+#ifndef MS_REC
+#define MS_REC (1<<19)
+#endif
+
+#ifndef MS_SHARED
+#define MS_SHARED (1<<20)
+#endif
+
+#ifndef MS_RELATIME
+#define MS_RELATIME (1<<21)
+#endif
+
+#ifndef MS_KERNMOUNT
+#define MS_KERNMOUNT (1<<22)
+#endif
+
+#ifndef MS_I_VERSION
+#define MS_I_VERSION (1<<23)
#endif
#ifndef MS_STRICTATIME
-#define MS_STRICTATIME (1<<24)
+#define MS_STRICTATIME (1<<24)
#endif
-#ifndef MS_REC
-#define MS_REC 16384
+#ifndef MS_LAZYTIME
+#define MS_LAZYTIME (1<<25)
#endif
-#ifndef MS_SHARED
-#define MS_SHARED (1<<20)
+#ifndef SCM_SECURITY
+#define SCM_SECURITY 0x03
#endif
#ifndef PR_SET_NO_NEW_PRIVS
@@ -534,12 +558,21 @@ struct btrfs_ioctl_quota_ctl_args {
# define DRM_IOCTL_DROP_MASTER _IO('d', 0x1f)
#endif
-#if defined(__i386__) || defined(__x86_64__)
-
-/* The precise definition of __O_TMPFILE is arch specific, so let's
- * just define this on x86 where we know the value. */
+/* The precise definition of __O_TMPFILE is arch specific; use the
+ * values defined by the kernel (note: some are hexa, some are octal,
+ * duplicated as-is from the kernel definitions):
+ * - alpha, parisc, sparc: each has a specific value;
+ * - others: they use the "generic" value.
+ */
#ifndef __O_TMPFILE
+#if defined(__alpha__)
+#define __O_TMPFILE 0100000000
+#elif defined(__parisc__) || defined(__hppa__)
+#define __O_TMPFILE 0400000000
+#elif defined(__sparc__) || defined(__sparc64__)
+#define __O_TMPFILE 0x2000000
+#else
#define __O_TMPFILE 020000000
#endif
@@ -1040,6 +1073,10 @@ typedef int32_t key_serial_t;
#define ETHERTYPE_LLDP 0x88cc
#endif
+#ifndef IFA_F_MCAUTOJOIN
+#define IFA_F_MCAUTOJOIN 0x400
+#endif
+
#endif
#include "missing_syscall.h"
diff --git a/src/libsystemd-basic/include/systemd-basic/mount-util.h b/src/libsystemd-basic/include/systemd-basic/mount-util.h
index f46989ebb3..4f305df19f 100644
--- a/src/libsystemd-basic/include/systemd-basic/mount-util.h
+++ b/src/libsystemd-basic/include/systemd-basic/mount-util.h
@@ -35,7 +35,7 @@ int path_is_mount_point(const char *path, int flags);
int repeat_unmount(const char *path, int flags);
int umount_recursive(const char *target, int flags);
-int bind_remount_recursive(const char *prefix, bool ro);
+int bind_remount_recursive(const char *prefix, bool ro, char **blacklist);
int mount_move_root(const char *path);
@@ -52,3 +52,12 @@ union file_handle_union {
const char* mode_to_inaccessible_node(mode_t mode);
#define FILE_HANDLE_INIT { .handle.handle_bytes = MAX_HANDLE_SZ }
+
+int mount_verbose(
+ int error_log_level,
+ const char *what,
+ const char *where,
+ const char *type,
+ unsigned long flags,
+ const char *options);
+int umount_verbose(const char *where);
diff --git a/src/libsystemd-basic/include/systemd-basic/parse-util.h b/src/libsystemd-basic/include/systemd-basic/parse-util.h
index 73441bb6fd..461e1cd4d8 100644
--- a/src/libsystemd-basic/include/systemd-basic/parse-util.h
+++ b/src/libsystemd-basic/include/systemd-basic/parse-util.h
@@ -106,4 +106,7 @@ int safe_atod(const char *s, double *ret_d);
int parse_fractional_part_u(const char **s, size_t digits, unsigned *res);
+int parse_percent_unbounded(const char *p);
int parse_percent(const char *p);
+
+int parse_nice(const char *p, int *ret);
diff --git a/src/libsystemd-basic/include/systemd-basic/path-util.h b/src/libsystemd-basic/include/systemd-basic/path-util.h
index a27c13fcc3..66545f52d9 100644
--- a/src/libsystemd-basic/include/systemd-basic/path-util.h
+++ b/src/libsystemd-basic/include/systemd-basic/path-util.h
@@ -125,3 +125,6 @@ char *file_in_same_dir(const char *path, const char *filename);
bool hidden_or_backup_file(const char *filename) _pure_;
bool is_device_path(const char *path);
+bool is_deviceallow_pattern(const char *path);
+
+int systemd_installation_has_version(const char *root, unsigned minimal_version);
diff --git a/src/libsystemd-basic/include/systemd-basic/proc-cmdline.h b/src/libsystemd-basic/include/systemd-basic/proc-cmdline.h
index 452642a2f5..6d6ee95c11 100644
--- a/src/libsystemd-basic/include/systemd-basic/proc-cmdline.h
+++ b/src/libsystemd-basic/include/systemd-basic/proc-cmdline.h
@@ -20,7 +20,9 @@
***/
int proc_cmdline(char **ret);
-int parse_proc_cmdline(int (*parse_word)(const char *key, const char *value));
+int parse_proc_cmdline(int (*parse_item)(const char *key, const char *value, void *data),
+ void *data,
+ bool strip_prefix);
int get_proc_cmdline_key(const char *parameter, char **value);
int shall_restore_state(void);
diff --git a/src/libsystemd-basic/include/systemd-basic/process-util.h b/src/libsystemd-basic/include/systemd-basic/process-util.h
index 9f75088796..aa51357172 100644
--- a/src/libsystemd-basic/include/systemd-basic/process-util.h
+++ b/src/libsystemd-basic/include/systemd-basic/process-util.h
@@ -25,6 +25,7 @@
#include <stddef.h>
#include <stdio.h>
#include <string.h>
+#include <sys/resource.h>
#include <sys/types.h>
#include "formats-util.h"
@@ -103,3 +104,7 @@ int sched_policy_from_string(const char *s);
void valgrind_summary_hack(void);
int pid_compare_func(const void *a, const void *b);
+
+static inline bool nice_is_valid(int n) {
+ return n >= PRIO_MIN && n < PRIO_MAX;
+}
diff --git a/src/libsystemd-basic/include/systemd-basic/set.h b/src/libsystemd-basic/include/systemd-basic/set.h
index 12f64a8c57..a5f8beb0c4 100644
--- a/src/libsystemd-basic/include/systemd-basic/set.h
+++ b/src/libsystemd-basic/include/systemd-basic/set.h
@@ -23,8 +23,8 @@
#include "hashmap.h"
#include "macro.h"
-Set *internal_set_new(const struct hash_ops *hash_ops HASHMAP_DEBUG_PARAMS);
-#define set_new(ops) internal_set_new(ops HASHMAP_DEBUG_SRC_ARGS)
+Set *internal_set_new(const struct hash_ops *hash_ops HASHMAP_DEBUG_PARAMS);
+#define set_new(ops) internal_set_new(ops HASHMAP_DEBUG_SRC_ARGS)
static inline Set *set_free(Set *s) {
internal_hashmap_free(HASHMAP_BASE(s));
@@ -42,8 +42,8 @@ static inline Set *set_copy(Set *s) {
return (Set*) internal_hashmap_copy(HASHMAP_BASE(s));
}
-int internal_set_ensure_allocated(Set **s, const struct hash_ops *hash_ops HASHMAP_DEBUG_PARAMS);
-#define set_ensure_allocated(h, ops) internal_set_ensure_allocated(h, ops HASHMAP_DEBUG_SRC_ARGS)
+int internal_set_ensure_allocated(Set **s, const struct hash_ops *hash_ops HASHMAP_DEBUG_PARAMS);
+#define set_ensure_allocated(h, ops) internal_set_ensure_allocated(h, ops HASHMAP_DEBUG_SRC_ARGS)
int set_put(Set *s, const void *key);
/* no set_update */
diff --git a/src/libsystemd-basic/include/systemd-basic/socket-util.h b/src/libsystemd-basic/include/systemd-basic/socket-util.h
index 2b717a91d4..f0f12c8c2e 100644
--- a/src/libsystemd-basic/include/systemd-basic/socket-util.h
+++ b/src/libsystemd-basic/include/systemd-basic/socket-util.h
@@ -143,6 +143,8 @@ int flush_accept(int fd);
#define CMSG_FOREACH(cmsg, mh) \
for ((cmsg) = CMSG_FIRSTHDR(mh); (cmsg); (cmsg) = CMSG_NXTHDR((mh), (cmsg)))
+struct cmsghdr* cmsg_find(struct msghdr *mh, int level, int type, socklen_t length);
+
/* Covers only file system and abstract AF_UNIX socket addresses, but not unnamed socket addresses. */
#define SOCKADDR_UN_LEN(sa) \
({ \
@@ -153,3 +155,5 @@ int flush_accept(int fd);
1 + strnlen(_sa->sun_path+1, sizeof(_sa->sun_path)-1) : \
strnlen(_sa->sun_path, sizeof(_sa->sun_path))); \
})
+
+int socket_ioctl_fd(void);
diff --git a/src/libsystemd-basic/include/systemd-basic/special.h b/src/libsystemd-basic/include/systemd-basic/special.h
index 084d3dfa23..5276bcf598 100644
--- a/src/libsystemd-basic/include/systemd-basic/special.h
+++ b/src/libsystemd-basic/include/systemd-basic/special.h
@@ -117,3 +117,6 @@
/* The scope unit systemd itself lives in. */
#define SPECIAL_INIT_SCOPE "init.scope"
+
+/* The root directory. */
+#define SPECIAL_ROOT_MOUNT "-.mount"
diff --git a/src/libsystemd-basic/include/systemd-basic/string-util.h b/src/libsystemd-basic/include/systemd-basic/string-util.h
index 1209e1e2e1..d029d538bd 100644
--- a/src/libsystemd-basic/include/systemd-basic/string-util.h
+++ b/src/libsystemd-basic/include/systemd-basic/string-util.h
@@ -70,6 +70,10 @@ static inline const char *empty_to_null(const char *p) {
return isempty(p) ? NULL : p;
}
+static inline const char *strdash_if_empty(const char *str) {
+ return isempty(str) ? "-" : str;
+}
+
static inline char *startswith(const char *s, const char *prefix) {
size_t l;
@@ -137,6 +141,9 @@ char ascii_tolower(char x);
char *ascii_strlower(char *s);
char *ascii_strlower_n(char *s, size_t n);
+char ascii_toupper(char x);
+char *ascii_strupper(char *s);
+
int ascii_strcasecmp_n(const char *a, const char *b, size_t n);
int ascii_strcasecmp_nn(const char *a, size_t n, const char *b, size_t m);
diff --git a/src/libsystemd-basic/include/systemd-basic/strv.h b/src/libsystemd-basic/include/systemd-basic/strv.h
index 683ce83a2a..385ad17779 100644
--- a/src/libsystemd-basic/include/systemd-basic/strv.h
+++ b/src/libsystemd-basic/include/systemd-basic/strv.h
@@ -96,10 +96,13 @@ bool strv_overlap(char **a, char **b) _pure_;
#define STRV_FOREACH(s, l) \
for ((s) = (l); (s) && *(s); (s)++)
-#define STRV_FOREACH_BACKWARDS(s, l) \
- STRV_FOREACH(s, l) \
- ; \
- for ((s)--; (l) && ((s) >= (l)); (s)--)
+#define STRV_FOREACH_BACKWARDS(s, l) \
+ for (s = ({ \
+ char **_l = l; \
+ _l ? _l + strv_length(_l) - 1U : NULL; \
+ }); \
+ (l) && ((s) >= (l)); \
+ (s)--)
#define STRV_FOREACH_PAIR(x, y, l) \
for ((x) = (l), (y) = (x+1); (x) && *(x) && *(y); (x) += 2, (y) = (x + 1))
@@ -141,6 +144,11 @@ void strv_print(char **l);
})
#define STR_IN_SET(x, ...) strv_contains(STRV_MAKE(__VA_ARGS__), x)
+#define STRPTR_IN_SET(x, ...) \
+ ({ \
+ const char* _x = (x); \
+ _x && strv_contains(STRV_MAKE(__VA_ARGS__), _x); \
+ })
#define FOREACH_STRING(x, ...) \
for (char **_l = ({ \
diff --git a/src/libsystemd-basic/include/systemd-basic/terminal-util.h b/src/libsystemd-basic/include/systemd-basic/terminal-util.h
index 169ab772ff..b862bfaf05 100644
--- a/src/libsystemd-basic/include/systemd-basic/terminal-util.h
+++ b/src/libsystemd-basic/include/systemd-basic/terminal-util.h
@@ -36,6 +36,10 @@
#define ANSI_HIGHLIGHT_YELLOW "\x1B[0;1;33m"
#define ANSI_HIGHLIGHT_BLUE "\x1B[0;1;34m"
#define ANSI_HIGHLIGHT_UNDERLINE "\x1B[0;1;4m"
+#define ANSI_HIGHLIGHT_RED_UNDERLINE "\x1B[0;1;4;31m"
+#define ANSI_HIGHLIGHT_GREEN_UNDERLINE "\x1B[0;1;4;32m"
+#define ANSI_HIGHLIGHT_YELLOW_UNDERLINE "\x1B[0;1;4;33m"
+#define ANSI_HIGHLIGHT_BLUE_UNDERLINE "\x1B[0;1;4;34m"
#define ANSI_NORMAL "\x1B[0m"
#define ANSI_ERASE_TO_END_OF_LINE "\x1B[K"
@@ -83,37 +87,24 @@ bool on_tty(void);
bool terminal_is_dumb(void);
bool colors_enabled(void);
-static inline const char *ansi_underline(void) {
- return colors_enabled() ? ANSI_UNDERLINE : "";
-}
-
-static inline const char *ansi_highlight(void) {
- return colors_enabled() ? ANSI_HIGHLIGHT : "";
-}
-
-static inline const char *ansi_highlight_underline(void) {
- return colors_enabled() ? ANSI_HIGHLIGHT_UNDERLINE : "";
-}
-
-static inline const char *ansi_highlight_red(void) {
- return colors_enabled() ? ANSI_HIGHLIGHT_RED : "";
-}
-
-static inline const char *ansi_highlight_green(void) {
- return colors_enabled() ? ANSI_HIGHLIGHT_GREEN : "";
-}
-
-static inline const char *ansi_highlight_yellow(void) {
- return colors_enabled() ? ANSI_HIGHLIGHT_YELLOW : "";
-}
-
-static inline const char *ansi_highlight_blue(void) {
- return colors_enabled() ? ANSI_HIGHLIGHT_BLUE : "";
-}
-
-static inline const char *ansi_normal(void) {
- return colors_enabled() ? ANSI_NORMAL : "";
-}
+#define DEFINE_ANSI_FUNC(name, NAME) \
+ static inline const char *ansi_##name(void) { \
+ return colors_enabled() ? ANSI_##NAME : ""; \
+ } \
+ struct __useless_struct_to_allow_trailing_semicolon__
+
+DEFINE_ANSI_FUNC(underline, UNDERLINE);
+DEFINE_ANSI_FUNC(highlight, HIGHLIGHT);
+DEFINE_ANSI_FUNC(highlight_underline, HIGHLIGHT_UNDERLINE);
+DEFINE_ANSI_FUNC(highlight_red, HIGHLIGHT_RED);
+DEFINE_ANSI_FUNC(highlight_green, HIGHLIGHT_GREEN);
+DEFINE_ANSI_FUNC(highlight_yellow, HIGHLIGHT_YELLOW);
+DEFINE_ANSI_FUNC(highlight_blue, HIGHLIGHT_BLUE);
+DEFINE_ANSI_FUNC(highlight_red_underline, HIGHLIGHT_RED_UNDERLINE);
+DEFINE_ANSI_FUNC(highlight_green_underline, HIGHLIGHT_GREEN_UNDERLINE);
+DEFINE_ANSI_FUNC(highlight_yellow_underline, HIGHLIGHT_YELLOW_UNDERLINE);
+DEFINE_ANSI_FUNC(highlight_blue_underline, HIGHLIGHT_BLUE_UNDERLINE);
+DEFINE_ANSI_FUNC(normal, NORMAL);
int get_ctty_devnr(pid_t pid, dev_t *d);
int get_ctty(pid_t, dev_t *_devnr, char **r);
diff --git a/src/libsystemd-basic/include/systemd-basic/time-util.h b/src/libsystemd-basic/include/systemd-basic/time-util.h
index aef64d2c8d..977f7b6bc5 100644
--- a/src/libsystemd-basic/include/systemd-basic/time-util.h
+++ b/src/libsystemd-basic/include/systemd-basic/time-util.h
@@ -70,7 +70,9 @@ typedef struct triple_timestamp {
#define USEC_PER_YEAR ((usec_t) (31557600ULL*USEC_PER_SEC))
#define NSEC_PER_YEAR ((nsec_t) (31557600ULL*NSEC_PER_SEC))
-#define FORMAT_TIMESTAMP_MAX ((4*4+1)+11+9+4+1) /* weekdays can be unicode */
+/* We assume a maximum timezone length of 6. TZNAME_MAX is not defined on Linux, but glibc internally initializes this
+ * to 6. Let's rely on that. */
+#define FORMAT_TIMESTAMP_MAX (3+1+10+1+8+1+6+1+6+1)
#define FORMAT_TIMESTAMP_WIDTH 28 /* when outputting, assume this width */
#define FORMAT_TIMESTAMP_RELATIVE_MAX 256
#define FORMAT_TIMESPAN_MAX 64
@@ -111,6 +113,7 @@ static inline bool triple_timestamp_is_set(triple_timestamp *ts) {
usec_t triple_timestamp_by_clock(triple_timestamp *ts, clockid_t clock);
usec_t timespec_load(const struct timespec *ts) _pure_;
+nsec_t timespec_load_nsec(const struct timespec *ts) _pure_;
struct timespec *timespec_store(struct timespec *ts, usec_t u);
usec_t timeval_load(const struct timeval *tv) _pure_;
diff --git a/src/libsystemd-basic/include/systemd-basic/user-util.h b/src/libsystemd-basic/include/systemd-basic/user-util.h
index 8026eca3f4..dfea561bde 100644
--- a/src/libsystemd-basic/include/systemd-basic/user-util.h
+++ b/src/libsystemd-basic/include/systemd-basic/user-util.h
@@ -20,6 +20,7 @@
***/
#include <stdbool.h>
+#include <stdint.h>
#include <sys/types.h>
#include <unistd.h>
@@ -39,6 +40,7 @@ char* getlogname_malloc(void);
char* getusername_malloc(void);
int get_user_creds(const char **username, uid_t *uid, gid_t *gid, const char **home, const char **shell);
+int get_user_creds_clean(const char **username, uid_t *uid, gid_t *gid, const char **home, const char **shell);
int get_group_creds(const char **groupname, gid_t *gid);
char* uid_to_name(uid_t uid);
@@ -57,8 +59,19 @@ int take_etc_passwd_lock(const char *root);
#define UID_INVALID ((uid_t) -1)
#define GID_INVALID ((gid_t) -1)
-/* The following macros add 1 when converting things, since UID 0 is a
- * valid UID, while the pointer NULL is special */
+/* Let's pick a UIDs within the 16bit range, so that we are compatible with containers using 16bit
+ * user namespacing. At least on Fedora normal users are allocated until UID 60000, hence do not
+ * allocate from below this. Also stay away from the upper end of the range as that is often used
+ * for overflow/nobody users. */
+#define DYNAMIC_UID_MIN ((uid_t) UINT32_C(0x0000EF00))
+#define DYNAMIC_UID_MAX ((uid_t) UINT32_C(0x0000FFEF))
+
+static inline bool uid_is_dynamic(uid_t uid) {
+ return DYNAMIC_UID_MIN <= uid && uid <= DYNAMIC_UID_MAX;
+}
+
+/* The following macros add 1 when converting things, since UID 0 is a valid UID, while the pointer
+ * NULL is special */
#define PTR_TO_UID(p) ((uid_t) (((uintptr_t) (p))-1))
#define UID_TO_PTR(u) ((void*) (((uintptr_t) (u))+1))
@@ -68,3 +81,10 @@ int take_etc_passwd_lock(const char *root);
static inline bool userns_supported(void) {
return access("/proc/self/uid_map", F_OK) >= 0;
}
+
+bool valid_user_group_name(const char *u);
+bool valid_user_group_name_or_id(const char *u);
+bool valid_gecos(const char *d);
+bool valid_home(const char *p);
+
+int maybe_setgroups(size_t size, const gid_t *list);
diff --git a/src/libsystemd-basic/include/systemd-basic/util.h b/src/libsystemd-basic/include/systemd-basic/util.h
index 44497dcd78..bb2fc318ef 100644
--- a/src/libsystemd-basic/include/systemd-basic/util.h
+++ b/src/libsystemd-basic/include/systemd-basic/util.h
@@ -61,6 +61,10 @@ static inline const char* one_zero(bool b) {
return b ? "1" : "0";
}
+static inline const char* enable_disable(bool b) {
+ return b ? "enable" : "disable";
+}
+
void execute_directories(const char* const* directories, usec_t timeout, char *argv[]);
bool plymouth_running(void);
diff --git a/src/libsystemd-basic/include/systemd-basic/virt.h b/src/libsystemd-basic/include/systemd-basic/virt.h
index a538f07f6b..7d15169112 100644
--- a/src/libsystemd-basic/include/systemd-basic/virt.h
+++ b/src/libsystemd-basic/include/systemd-basic/virt.h
@@ -37,6 +37,7 @@ enum {
VIRTUALIZATION_MICROSOFT,
VIRTUALIZATION_ZVM,
VIRTUALIZATION_PARALLELS,
+ VIRTUALIZATION_BHYVE,
VIRTUALIZATION_VM_OTHER,
VIRTUALIZATION_VM_LAST = VIRTUALIZATION_VM_OTHER,
@@ -66,6 +67,7 @@ int detect_vm(void);
int detect_container(void);
int detect_virtualization(void);
+int running_in_userns(void);
int running_in_chroot(void);
const char *virtualization_to_string(int v) _const_;