4 This file is part of systemd.
6 Copyright 2010 Lennart Poettering
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
35 #include <sys/inotify.h>
36 #include <sys/socket.h>
38 #include <sys/statfs.h>
39 #include <sys/sysmacros.h>
40 #include <sys/types.h>
44 #include "formats-util.h"
47 #include "time-util.h"
49 size_t page_size(void) _pure_;
50 #define PAGE_ALIGN(l) ALIGN_TO((l), page_size())
52 static inline const char* yes_no(bool b) {
53 return b ? "yes" : "no";
56 static inline const char* true_false(bool b) {
57 return b ? "true" : "false";
60 static inline const char* one_zero(bool b) {
64 static inline const char* enable_disable(bool b) {
65 return b ? "enable" : "disable";
68 void execute_directories(const char* const* directories, usec_t timeout, char *argv[]);
70 #if 0 /// UNNEEDED by elogind
71 bool plymouth_running(void);
74 bool display_is_local(const char *display) _pure_;
75 int socket_from_display(const char *display, char **path);
77 #if 0 /// UNNEEDED by elogind
78 int block_get_whole_disk(dev_t d, dev_t *ret);
81 #define NULSTR_FOREACH(i, l) \
82 for ((i) = (l); (i) && *(i); (i) = strchr((i), 0)+1)
84 #define NULSTR_FOREACH_PAIR(i, j, l) \
85 for ((i) = (l), (j) = strchr((i), 0)+1; (i) && *(i); (i) = strchr((j), 0)+1, (j) = *(i) ? strchr((i), 0)+1 : (i))
87 extern int saved_argc;
88 extern char **saved_argv;
90 #if 0 /// UNNEEDED by elogind
91 bool kexec_loaded(void);
93 int prot_from_flags(int flags) _const_;
96 int fork_agent(pid_t *pid, const int except[], unsigned n_except, const char *path, ...);
99 void in_initrd_force(bool value);
101 #if 0 /// UNNEEDED by elogind
102 void *xbsearch_r(const void *key, const void *base, size_t nmemb, size_t size,
103 int (*compar) (const void *, const void *, void *),
108 * Normal qsort requires base to be nonnull. Here were require
109 * that only if nmemb > 0.
111 static inline void qsort_safe(void *base, size_t nmemb, size_t size, comparison_fn_t compar) {
116 qsort(base, nmemb, size, compar);
120 * Normal memcpy requires src to be nonnull. We do nothing if n is 0.
122 static inline void memcpy_safe(void *dst, const void *src, size_t n) {
129 #if 0 /// UNNEEDED by elogind
130 int on_ac_power(void);
133 #define memzero(x,l) (memset((x), 0, (l)))
134 #define zero(x) (memzero(&(x), sizeof(x)))
136 static inline void *mempset(void *s, int c, size_t n) {
138 return (uint8_t*)s + n;
141 static inline void _reset_errno_(int *saved_errno) {
142 errno = *saved_errno;
145 #define PROTECT_ERRNO _cleanup_(_reset_errno_) __attribute__((unused)) int _saved_errno_ = errno
147 static inline int negative_errno(void) {
148 /* This helper should be used to shut up gcc if you know 'errno' is
149 * negative. Instead of "return -errno;", use "return negative_errno();"
150 * It will suppress bogus gcc warnings in case it assumes 'errno' might
151 * be 0 and thus the caller's error-handling might not be triggered. */
152 assert_return(errno > 0, -EINVAL);
156 static inline unsigned u64log2(uint64_t n) {
157 #if __SIZEOF_LONG_LONG__ == 8
158 return (n > 1) ? (unsigned) __builtin_clzll(n) ^ 63U : 0;
164 static inline unsigned u32ctz(uint32_t n) {
165 #if __SIZEOF_INT__ == 4
166 return __builtin_ctz(n);
172 static inline unsigned log2i(int x) {
175 return __SIZEOF_INT__ * 8 - __builtin_clz(x) - 1;
178 static inline unsigned log2u(unsigned x) {
181 return sizeof(unsigned) * 8 - __builtin_clz(x) - 1;
184 static inline unsigned log2u_round_up(unsigned x) {
190 return log2u(x - 1) + 1;
193 #if 0 /// UNNEEDED by elogind
195 int container_get_leader(const char *machine, pid_t *pid);
197 int namespace_open(pid_t pid, int *pidns_fd, int *mntns_fd, int *netns_fd, int *userns_fd, int *root_fd);
198 int namespace_enter(int pidns_fd, int mntns_fd, int netns_fd, int userns_fd, int root_fd);
200 uint64_t physical_memory(void);
201 uint64_t physical_memory_scale(uint64_t v, uint64_t max);
203 uint64_t system_tasks_max(void);
204 uint64_t system_tasks_max_scale(uint64_t v, uint64_t max);
206 #if 0 /// UNNEEDED by elogind
208 int update_reboot_parameter_and_warn(const char *param);