X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fshared%2Futil.h;h=4cea627580fd86586acdb5bee5f966e3dde32b0a;hp=5b2a08389e5a5422ab6412ae87ee407ed0bfa45b;hb=f7cf3431c7260635d9d2fa0886af05e56261c5df;hpb=99a720797c7779625c23de456c85ed0b3056bca6 diff --git a/src/shared/util.h b/src/shared/util.h index 5b2a08389..4cea62758 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -352,10 +352,7 @@ char* dirname_malloc(const char *path); void sigset_add_many(sigset_t *ss, ...); int sigprocmask_many(int how, ...); -bool hostname_is_set(void); - char* lookup_uid(uid_t uid); -char* gethostname_malloc(void); char* getlogname_malloc(void); char* getusername_malloc(void); @@ -398,13 +395,11 @@ bool nulstr_contains(const char*nulstr, const char *needle); bool plymouth_running(void); -bool hostname_is_valid(const char *s) _pure_; -char* hostname_cleanup(char *s, bool lowercase); - bool machine_name_is_valid(const char *s) _pure_; char* strshorten(char *s, size_t l); +int symlink_idempotent(const char *from, const char *to); int symlink_atomic(const char *from, const char *to); int mknod_atomic(const char *path, mode_t mode, dev_t dev); @@ -779,12 +774,27 @@ int shall_restore_state(void); * Normal qsort requires base to be nonnull. Here were require * that only if nmemb > 0. */ -static inline void qsort_safe(void *base, size_t nmemb, size_t size, - int (*compar)(const void *, const void *)) { - if (nmemb) { - assert(base); - qsort(base, nmemb, size, compar); - } +static inline void qsort_safe(void *base, size_t nmemb, size_t size, comparison_fn_t compar) { + if (nmemb <= 0) + return; + + assert(base); + qsort(base, nmemb, size, compar); +} + +/* Normal memmem() requires haystack to be nonnull, which is annoying for zero-length buffers */ +static inline void *memmem_safe(const void *haystack, size_t haystacklen, const void *needle, size_t needlelen) { + + if (needlelen <= 0) + return (void*) haystack; + + if (haystacklen < needlelen) + return NULL; + + assert(haystack); + assert(needle); + + return memmem(haystack, haystacklen, needle, needlelen); } int proc_cmdline(char **ret); @@ -831,12 +841,11 @@ int tempfn_xxxxxx(const char *p, char **ret); int tempfn_random(const char *p, char **ret); int tempfn_random_child(const char *p, char **ret); -bool is_localhost(const char *hostname); - int take_password_lock(const char *root); int is_symlink(const char *path); int is_dir(const char *path, bool follow); +int is_device_node(const char *path); typedef enum UnquoteFlags { UNQUOTE_RELAX = 1, @@ -848,8 +857,6 @@ int unquote_many_words(const char **p, UnquoteFlags flags, ...) _sentinel_; int free_and_strdup(char **p, const char *s); -int sethostname_idempotent(const char *s); - #define INOTIFY_EVENT_MAX (sizeof(struct inotify_event) + NAME_MAX + 1) #define FOREACH_INOTIFY_EVENT(e, buffer, sz) \ @@ -881,20 +888,6 @@ int chattr_path(const char *p, unsigned value, unsigned mask); int read_attr_fd(int fd, unsigned *ret); int read_attr_path(const char *p, unsigned *ret); -typedef struct LockFile { - char *path; - int fd; - int operation; -} LockFile; - -int make_lock_file(const char *p, int operation, LockFile *ret); -int make_lock_file_for(const char *p, int operation, LockFile *ret); -void release_lock_file(LockFile *f); - -#define _cleanup_release_lock_file_ _cleanup_(release_lock_file) - -#define LOCK_FILE_INIT { .fd = -1, .path = NULL } - #define RLIMIT_MAKE_CONST(lim) ((struct rlimit) { lim, lim }) ssize_t sparse_write(int fd, const void *p, size_t sz, size_t run_length); @@ -911,3 +904,5 @@ int rename_noreplace(int olddirfd, const char *oldpath, int newdirfd, const char char *shell_maybe_quote(const char *s); int parse_mode(const char *s, mode_t *ret); + +int mount_move_root(const char *path);