X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fshared%2Futil.h;h=338d79c7ac5822be36c0c1b312df422b1aeef1c6;hb=96415cad2fdd8d280ae94b02651b5f826a2f7f3d;hp=1d178260cbe2d8e702fe98afebd268736448ab9c;hpb=5232c42ec43e86f90a850d965a33bb413b9e5a00;p=elogind.git diff --git a/src/shared/util.h b/src/shared/util.h index 1d178260c..338d79c7a 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -44,12 +44,6 @@ #include "macro.h" #include "time-util.h" -union dirent_storage { - struct dirent de; - uint8_t storage[offsetof(struct dirent, d_name) + - ((NAME_MAX + 1 + sizeof(long)) & ~(sizeof(long) - 1))]; -}; - /* What is interpreted as whitespace? */ #define WHITESPACE " \t\n\r" #define NEWLINE "\n\r" @@ -255,8 +249,19 @@ int make_stdio(int fd); int make_null_stdio(void); int make_console_stdio(void); -unsigned long long random_ull(void); -unsigned random_u(void); +void random_bytes(void *p, size_t n); + +static inline uint64_t random_u64(void) { + uint64_t u; + random_bytes(&u, sizeof(u)); + return u; +} + +static inline uint32_t random_u32(void) { + uint32_t u; + random_bytes(&u, sizeof(u)); + return u; +} /* For basic lookup tables with strictly enumerated entries */ #define __DEFINE_STRING_TABLE_LOOKUP(name,type,scope) \ @@ -426,7 +431,7 @@ char *normalize_env_assignment(const char *s); int wait_for_terminate(pid_t pid, siginfo_t *status); int wait_for_terminate_and_warn(const char *name, pid_t pid); -_noreturn_ void freeze(void); +noreturn void freeze(void); bool null_or_empty(struct stat *st) _pure_; int null_or_empty_path(const char *fn); @@ -804,3 +809,5 @@ int container_get_leader(const char *machine, pid_t *pid); int namespace_open(pid_t pid, int *pidns_fd, int *mntns_fd, int *root_fd); int namespace_enter(int pidns_fd, int mntns_fd, int root_fd); + +bool pid_valid(pid_t pid);