1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
6 This file is part of systemd.
8 Copyright 2010 Lennart Poettering
10 systemd is free software; you can redistribute it and/or modify it
11 under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
15 systemd is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
20 You should have received a copy of the GNU Lesser General Public License
21 along with systemd; If not, see <http://www.gnu.org/licenses/>.
34 #include <sys/inotify.h>
35 #include <sys/socket.h>
37 #include <sys/statfs.h>
38 #include <sys/types.h>
42 #include "formats-util.h"
45 #include "time-util.h"
47 size_t page_size(void) _pure_;
48 #define PAGE_ALIGN(l) ALIGN_TO((l), page_size())
50 static inline const char* yes_no(bool b) {
51 return b ? "yes" : "no";
54 static inline const char* true_false(bool b) {
55 return b ? "true" : "false";
58 static inline const char* one_zero(bool b) {
62 void execute_directories(const char* const* directories, usec_t timeout, char *argv[]);
64 #if 0 /// UNNEEDED by elogind
65 bool plymouth_running(void);
68 bool display_is_local(const char *display) _pure_;
69 int socket_from_display(const char *display, char **path);
71 #if 0 /// UNNEEDED by elogind
72 int block_get_whole_disk(dev_t d, dev_t *ret);
75 #define NULSTR_FOREACH(i, l) \
76 for ((i) = (l); (i) && *(i); (i) = strchr((i), 0)+1)
78 #define NULSTR_FOREACH_PAIR(i, j, l) \
79 for ((i) = (l), (j) = strchr((i), 0)+1; (i) && *(i); (i) = strchr((j), 0)+1, (j) = *(i) ? strchr((i), 0)+1 : (i))
81 extern int saved_argc;
82 extern char **saved_argv;
84 #if 0 /// UNNEEDED by elogind
85 bool kexec_loaded(void);
87 int prot_from_flags(int flags) _const_;
90 int fork_agent(pid_t *pid, const int except[], unsigned n_except, const char *path, ...);
94 #if 0 /// UNNEEDED by elogind
95 void *xbsearch_r(const void *key, const void *base, size_t nmemb, size_t size,
96 int (*compar) (const void *, const void *, void *),
101 * Normal qsort requires base to be nonnull. Here were require
102 * that only if nmemb > 0.
104 static inline void qsort_safe(void *base, size_t nmemb, size_t size, comparison_fn_t compar) {
109 qsort(base, nmemb, size, compar);
112 #if 0 /// UNNEEDED by elogind
113 int on_ac_power(void);
116 #define memzero(x,l) (memset((x), 0, (l)))
117 #define zero(x) (memzero(&(x), sizeof(x)))
119 static inline void *mempset(void *s, int c, size_t n) {
121 return (uint8_t*)s + n;
124 static inline void _reset_errno_(int *saved_errno) {
125 errno = *saved_errno;
128 #define PROTECT_ERRNO _cleanup_(_reset_errno_) __attribute__((unused)) int _saved_errno_ = errno
130 #if 0 /// UNNEEDED by elogind
131 static inline int negative_errno(void) {
132 /* This helper should be used to shut up gcc if you know 'errno' is
133 * negative. Instead of "return -errno;", use "return negative_errno();"
134 * It will suppress bogus gcc warnings in case it assumes 'errno' might
135 * be 0 and thus the caller's error-handling might not be triggered. */
136 assert_return(errno > 0, -EINVAL);
141 static inline unsigned u64log2(uint64_t n) {
142 #if __SIZEOF_LONG_LONG__ == 8
143 return (n > 1) ? (unsigned) __builtin_clzll(n) ^ 63U : 0;
149 static inline unsigned u32ctz(uint32_t n) {
150 #if __SIZEOF_INT__ == 4
151 return __builtin_ctz(n);
157 static inline unsigned log2i(int x) {
160 return __SIZEOF_INT__ * 8 - __builtin_clz(x) - 1;
163 static inline unsigned log2u(unsigned x) {
166 return sizeof(unsigned) * 8 - __builtin_clz(x) - 1;
169 static inline unsigned log2u_round_up(unsigned x) {
175 return log2u(x - 1) + 1;
178 #if 0 /// UNNEEDED by elogind
179 bool id128_is_valid(const char *s) _pure_;
182 int container_get_leader(const char *machine, pid_t *pid);
184 int namespace_open(pid_t pid, int *pidns_fd, int *mntns_fd, int *netns_fd, int *userns_fd, int *root_fd);
185 int namespace_enter(int pidns_fd, int mntns_fd, int netns_fd, int userns_fd, int root_fd);
187 uint64_t physical_memory(void);
189 #if 0 /// UNNEEDED by elogind
190 int update_reboot_param_file(const char *param);