X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fbasic%2Futil.h;h=75631c436bdc560edc0395246ada2f6814e96b33;hp=179505de8588482b14e13a866d46956e4eecb907;hb=d96290d8fd01ba77eec7f4a5fb493bc1ff80a98b;hpb=07045a1a92c839fd2af80bd0c060a595021bc3b3 diff --git a/src/basic/util.h b/src/basic/util.h index 179505de8..75631c436 100644 --- a/src/basic/util.h +++ b/src/basic/util.h @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -60,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[]); #if 0 /// UNNEEDED by elogind @@ -91,6 +96,7 @@ int prot_from_flags(int flags) _const_; int fork_agent(pid_t *pid, const int except[], unsigned n_except, const char *path, ...); bool in_initrd(void); +void in_initrd_force(bool value); #if 0 /// UNNEEDED by elogind void *xbsearch_r(const void *key, const void *base, size_t nmemb, size_t size, @@ -110,6 +116,16 @@ static inline void qsort_safe(void *base, size_t nmemb, size_t size, comparison_ qsort(base, nmemb, size, compar); } +/** + * Normal memcpy requires src to be nonnull. We do nothing if n is 0. + */ +static inline void memcpy_safe(void *dst, const void *src, size_t n) { + if (n == 0) + return; + assert(src); + memcpy(dst, src, n); +} + #if 0 /// UNNEEDED by elogind int on_ac_power(void); #endif // 0 @@ -128,7 +144,6 @@ static inline void _reset_errno_(int *saved_errno) { #define PROTECT_ERRNO _cleanup_(_reset_errno_) __attribute__((unused)) int _saved_errno_ = errno -#if 0 /// UNNEEDED by elogind static inline int negative_errno(void) { /* This helper should be used to shut up gcc if you know 'errno' is * negative. Instead of "return -errno;", use "return negative_errno();" @@ -137,7 +152,6 @@ static inline int negative_errno(void) { assert_return(errno > 0, -EINVAL); return -errno; } -#endif // 0 static inline unsigned u64log2(uint64_t n) { #if __SIZEOF_LONG_LONG__ == 8 @@ -177,18 +191,20 @@ static inline unsigned log2u_round_up(unsigned x) { } #if 0 /// UNNEEDED by elogind -bool id128_is_valid(const char *s) _pure_; #endif // 0 - int container_get_leader(const char *machine, pid_t *pid); int namespace_open(pid_t pid, int *pidns_fd, int *mntns_fd, int *netns_fd, int *userns_fd, int *root_fd); int namespace_enter(int pidns_fd, int mntns_fd, int netns_fd, int userns_fd, int root_fd); uint64_t physical_memory(void); +uint64_t physical_memory_scale(uint64_t v, uint64_t max); + +uint64_t system_tasks_max(void); +uint64_t system_tasks_max_scale(uint64_t v, uint64_t max); #if 0 /// UNNEEDED by elogind -int update_reboot_param_file(const char *param); #endif // 0 +int update_reboot_parameter_and_warn(const char *param); int version(void);