X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fshared%2Futil.h;h=11cc10ba3060f7425f8657cc1d24cf8ee925eefc;hb=30ab6a0fc1bb950c4dcd90dcd3dfe00a810c7fc1;hp=9271578d594e220e36aa0c8534d1ba660b640247;hpb=901cf821ac8c13c78e1acb884f59baf41316fb8f;p=elogind.git diff --git a/src/shared/util.h b/src/shared/util.h index 9271578d5..11cc10ba3 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -41,7 +41,6 @@ #include #include #include -#include #if SIZEOF_PID_T == 4 # define PID_PRI PRIi32 @@ -184,7 +183,6 @@ static inline char *startswith_no_case(const char *s, const char *prefix) { } char *endswith(const char *s, const char *postfix) _pure_; -char *endswith_no_case(const char *s, const char *postfix) _pure_; char *first_word(const char *s, const char *word) _pure_; @@ -268,6 +266,8 @@ const char* split(const char **state, size_t *l, const char *separator, bool quo #define _FOREACH_WORD(word, length, s, separator, quoted, state) \ for ((state) = (s), (word) = split(&(state), &(length), (separator), (quoted)); (word); (word) = split(&(state), &(length), (separator), (quoted))) +pid_t get_parent_of_pid(pid_t pid, pid_t *ppid); + char *strappend(const char *s, const char *suffix); char *strnappend(const char *s, const char *suffix, size_t length); @@ -291,6 +291,17 @@ char *file_in_same_dir(const char *path, const char *filename); int rmdir_parents(const char *path, const char *stop); +int get_process_state(pid_t pid); +int get_process_comm(pid_t pid, char **name); +int get_process_cmdline(pid_t pid, size_t max_length, bool comm_fallback, char **line); +int get_process_exe(pid_t pid, char **name); +int get_process_uid(pid_t pid, uid_t *uid); +int get_process_gid(pid_t pid, gid_t *gid); +int get_process_capeff(pid_t pid, char **capeff); +int get_process_cwd(pid_t pid, char **cwd); +int get_process_root(pid_t pid, char **root); +int get_process_environ(pid_t pid, char **environ); + char hexchar(int x) _const_; int unhexchar(char c) _const_; char octchar(int x) _const_; @@ -299,15 +310,9 @@ char decchar(int x) _const_; int undecchar(char c) _const_; char *cescape(const char *s); -size_t cescape_char(char c, char *buf); - -typedef enum UnescapeFlags { - UNESCAPE_RELAX = 1, -} UnescapeFlags; - -int cunescape(const char *s, UnescapeFlags flags, char **ret); -int cunescape_length(const char *s, size_t length, UnescapeFlags flags, char **ret); -int cunescape_length_with_prefix(const char *s, size_t length, const char *prefix, UnescapeFlags flags, char **ret); +char *cunescape(const char *s); +char *cunescape_length(const char *s, size_t length); +char *cunescape_length_with_prefix(const char *s, size_t length, const char *prefix); char *xescape(const char *s, const char *bad); @@ -435,6 +440,8 @@ bool is_device_path(const char *path); int dir_is_empty(const char *path); char* dirname_malloc(const char *path); +void rename_process(const char name[8]); + void sigset_add_many(sigset_t *ss, ...); int sigprocmask_many(int how, ...); @@ -454,8 +461,12 @@ int get_ctty(pid_t, dev_t *_devnr, char **r); int chmod_and_chown(const char *path, mode_t mode, uid_t uid, gid_t gid); int fchmod_and_fchown(int fd, mode_t mode, uid_t uid, gid_t gid); -bool is_temporary_fs(const struct statfs *s) _pure_; -int fd_is_temporary_fs(int fd); +int is_fd_on_temporary_fs(int fd); + +int rm_rf_children(int fd, bool only_dirs, bool honour_sticky, struct stat *root_dev); +int rm_rf_children_dangerous(int fd, bool only_dirs, bool honour_sticky, struct stat *root_dev); +int rm_rf(const char *path, bool only_dirs, bool delete_root, bool honour_sticky); +int rm_rf_dangerous(const char *path, bool only_dirs, bool delete_root, bool honour_sticky); int pipe_eof(int fd); @@ -509,6 +520,12 @@ char *ellipsize_mem(const char *s, size_t old_length, size_t new_length, unsigne int touch_file(const char *path, bool parents, usec_t stamp, uid_t uid, gid_t gid, mode_t mode); int touch(const char *path); +char *unquote(const char *s, const char *quotes); +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, bool check_exit_code); + noreturn void freeze(void); bool null_or_empty(struct stat *st) _pure_; @@ -528,6 +545,8 @@ const char *default_term_for_tty(const char *tty); void execute_directories(const char* const* directories, usec_t timeout, char *argv[]); +int kill_and_sigcont(pid_t pid, int sig); + bool nulstr_contains(const char*nulstr, const char *needle); bool plymouth_running(void); @@ -626,6 +645,8 @@ int fd_wait_for_event(int fd, int event, usec_t timeout); void* memdup(const void *p, size_t l) _alloc_(2); +int is_kernel_thread(pid_t pid); + int fd_inc_sndbuf(int fd, size_t n); int fd_inc_rcvbuf(int fd, size_t n); @@ -633,6 +654,8 @@ int fork_agent(pid_t *pid, const int except[], unsigned n_except, const char *pa int setrlimit_closest(int resource, const struct rlimit *rlim); +int getenv_for_pid(pid_t pid, const char *field, char **_value); + bool http_url_is_valid(const char *url) _pure_; bool documentation_url_is_valid(const char *url) _pure_; @@ -909,6 +932,19 @@ int unlink_noerrno(const char *path); _d_; \ }) +#define procfs_file_alloca(pid, field) \ + ({ \ + pid_t _pid_ = (pid); \ + const char *_r_; \ + if (_pid_ == 0) { \ + _r_ = ("/proc/self/" field); \ + } else { \ + _r_ = alloca(strlen("/proc/") + DECIMAL_STR_MAX(pid_t) + 1 + sizeof(field)); \ + sprintf((char*) _r_, "/proc/"PID_FMT"/" field, _pid_); \ + } \ + _r_; \ + }) + bool id128_is_valid(const char *s) _pure_; int split_pair(const char *s, const char *sep, char **l, char **r); @@ -936,6 +972,9 @@ 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 *root_fd); int namespace_enter(int pidns_fd, int mntns_fd, int netns_fd, int root_fd); +bool pid_is_alive(pid_t pid); +bool pid_is_unwaited(pid_t pid); + int getpeercred(int fd, struct ucred *ucred); int getpeersec(int fd, char **ret); @@ -978,7 +1017,7 @@ int take_password_lock(const char *root); int is_symlink(const char *path); int is_dir(const char *path, bool follow); -typedef enum UnquoteFlags { +typedef enum UnquoteFlags{ UNQUOTE_RELAX = 1, UNQUOTE_CUNESCAPE = 2, } UnquoteFlags; @@ -1015,8 +1054,9 @@ int fd_getcrtime(int fd, usec_t *usec); int path_getcrtime(const char *p, usec_t *usec); int fd_getcrtime_at(int dirfd, const char *name, usec_t *usec, int flags); -int chattr_fd(int fd, unsigned value, unsigned mask); -int chattr_path(const char *p, unsigned value, unsigned mask); +int chattr_fd(int fd, bool b, unsigned mask); +int chattr_path(const char *p, bool b, unsigned mask); +int change_attr_fd(int fd, unsigned value, unsigned mask); int read_attr_fd(int fd, unsigned *ret); int read_attr_path(const char *p, unsigned *ret); @@ -1047,7 +1087,3 @@ int syslog_parse_priority(const char **p, int *priority, bool with_facility); void cmsg_close_all(struct msghdr *mh); int rename_noreplace(int olddirfd, const char *oldpath, int newdirfd, const char *newpath); - -char *shell_maybe_quote(const char *s); - -int parse_mode(const char *s, mode_t *ret);