util.h revision fdb9161cd3e1a64eb9a653a6bf69596670d6e942
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering This file is part of systemd.
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering Copyright 2010 Lennart Poettering
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering systemd is free software; you can redistribute it and/or modify it
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering under the terms of the GNU Lesser General Public License as published by
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering (at your option) any later version.
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering systemd is distributed in the hope that it will be useful, but
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering Lesser General Public License for more details.
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering You should have received a copy of the GNU Lesser General Public License
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering/* What is interpreted as whitespace? */
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering#define ANSI_HIGHLIGHT_RED_ON "\x1B[1;31m"
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering#define ANSI_HIGHLIGHT_GREEN_ON "\x1B[1;32m"
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering#define ANSI_HIGHLIGHT_YELLOW_ON "\x1B[1;33m"
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering#define ANSI_HIGHLIGHT_BLUE_ON "\x1B[1;34m"
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering#define ANSI_ERASE_TO_END_OF_LINE "\x1B[K"
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering#define PAGE_ALIGN(l) ALIGN_TO((l), page_size())
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering#define strneq(a, b, n) (strncmp((a), (b), (n)) == 0)
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering#define strcaseeq(a,b) (strcasecmp((a),(b)) == 0)
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering#define strncaseeq(a, b, n) (strncasecmp((a), (b), (n)) == 0)
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringbool streq_ptr(const char *a, const char *b) _pure_;
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering#define new(t, n) ((t*) malloc_multiply(sizeof(t), (n)))
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering#define new0(t, n) ((t*) calloc((n), sizeof(t)))
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering#define newa(t, n) ((t*) alloca(sizeof(t)*(n)))
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering#define newdup(t, p, n) ((t*) memdup_multiply(p, sizeof(t), (n)))
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringstatic inline const char* yes_no(bool b) {
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringstatic inline const char* true_false(bool b) {
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringstatic inline const char* strempty(const char *s) {
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering return s ? s : "";
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringstatic inline const char* strnull(const char *s) {
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering return s ? s : "(null)";
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringstatic inline const char *strna(const char *s) {
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering return s ? s : "n/a";
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringstatic inline bool isempty(const char *p) {
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering return !p || !p[0];
83f6936a018b08880670838756e0f4e9ea98b4a7Lennart Poetteringstatic inline const char *startswith(const char *s, const char *prefix) {
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering if (strncmp(s, prefix, strlen(prefix)) == 0)
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringstatic inline const char *startswith_no_case(const char *s, const char *prefix) {
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering if (strncasecmp(s, prefix, strlen(prefix)) == 0)
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringchar *endswith(const char *s, const char *postfix) _pure_;
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringbool first_word(const char *s, const char *word) _pure_;
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringvoid close_many(const int fds[], unsigned n_fd);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringint parse_bytes(const char *t, off_t *bytes);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringint parse_pid(const char *s, pid_t* ret_pid);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringint parse_uid(const char *s, uid_t* ret_uid);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering#define parse_gid(s, ret_uid) parse_uid(s, ret_uid)
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringint safe_atou(const char *s, unsigned *ret_u);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringint safe_atollu(const char *s, unsigned long long *ret_u);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringint safe_atolli(const char *s, long long int *ret_i);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringint safe_atod(const char *s, double *ret_d);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringstatic inline int safe_atolu(const char *s, unsigned long *ret_u) {
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering assert_cc(sizeof(unsigned long) == sizeof(unsigned));
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringstatic inline int safe_atoli(const char *s, long int *ret_u) {
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering assert_cc(sizeof(long int) == sizeof(int));
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringstatic inline int safe_atolu(const char *s, unsigned long *ret_u) {
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering assert_cc(sizeof(unsigned long) == sizeof(unsigned long long));
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering return safe_atollu(s, (unsigned long long*) ret_u);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringstatic inline int safe_atoli(const char *s, long int *ret_u) {
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering assert_cc(sizeof(long int) == sizeof(long long int));
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering return safe_atolli(s, (long long int*) ret_u);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringstatic inline int safe_atou32(const char *s, uint32_t *ret_u) {
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering assert_cc(sizeof(uint32_t) == sizeof(unsigned));
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringstatic inline int safe_atoi32(const char *s, int32_t *ret_i) {
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering assert_cc(sizeof(int32_t) == sizeof(int));
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringstatic inline int safe_atou64(const char *s, uint64_t *ret_u) {
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering assert_cc(sizeof(uint64_t) == sizeof(unsigned long long));
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering return safe_atollu(s, (unsigned long long*) ret_u);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringstatic inline int safe_atoi64(const char *s, int64_t *ret_i) {
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering assert_cc(sizeof(int64_t) == sizeof(long long int));
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering return safe_atolli(s, (long long int*) ret_i);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringchar *split(const char *c, size_t *l, const char *separator, bool quoted, char **state);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering#define FOREACH_WORD(word, length, s, state) \
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering _FOREACH_WORD(word, length, s, WHITESPACE, false, state)
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering#define FOREACH_WORD_SEPARATOR(word, length, s, separator, state) \
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering _FOREACH_WORD(word, length, s, separator, false, state)
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering#define FOREACH_WORD_QUOTED(word, length, s, state) \
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering _FOREACH_WORD(word, length, s, WHITESPACE, true, state)
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering#define FOREACH_WORD_SEPARATOR_QUOTED(word, length, s, separator, state) \
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering _FOREACH_WORD(word, length, s, separator, true, state)
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering#define _FOREACH_WORD(word, length, s, separator, quoted, state) \
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering for ((state) = NULL, (word) = split((s), &(length), (separator), (quoted), &(state)); (word); (word) = split((s), &(length), (separator), (quoted), &(state)))
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringpid_t get_parent_of_pid(pid_t pid, pid_t *ppid);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringint get_starttime_of_pid(pid_t pid, unsigned long long *st);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringchar *strappend(const char *s, const char *suffix);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringchar *strnappend(const char *s, const char *suffix, size_t length);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringchar *replace_env(const char *format, char **env);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringchar **replace_env_argv(char **argv, char **env);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringint readlink_malloc(const char *p, char **r);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringint readlink_and_make_absolute(const char *p, char **r);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringint readlink_and_canonicalize(const char *p, char **r);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringchar *delete_chars(char *s, const char *bad);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringchar *file_in_same_dir(const char *path, const char *filename);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringint rmdir_parents(const char *path, const char *stop);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringint get_process_comm(pid_t pid, char **name);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringint get_process_cmdline(pid_t pid, size_t max_length, bool comm_fallback, char **line);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringint get_process_exe(pid_t pid, char **name);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringint get_process_uid(pid_t pid, uid_t *uid);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringint get_process_gid(pid_t pid, gid_t *gid);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringint get_process_capeff(pid_t pid, char **capeff);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringchar *cescape(const char *s);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringchar *cunescape(const char *s);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringchar *cunescape_length(const char *s, size_t length);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringchar *cunescape_length_with_prefix(const char *s, size_t length, const char *prefix);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringchar *xescape(const char *s, const char *bad);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringbool dirent_is_file(const struct dirent *de) _pure_;
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringbool dirent_is_file_with_suffix(const struct dirent *de, const char *suffix) _pure_;
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringbool ignore_file(const char *filename) _pure_;
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringbool chars_intersect(const char *a, const char *b) _pure_;
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering/* For basic lookup tables with strictly enumerated entries */
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering#define __DEFINE_STRING_TABLE_LOOKUP(name,type,scope) \
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering scope const char *name##_to_string(type i) { \
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering if (i < 0 || i >= (type) ELEMENTSOF(name##_table)) \
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering scope type name##_from_string(const char *s) { \
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering for (i = 0; i < (type)ELEMENTSOF(name##_table); i++) \
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering struct __useless_struct_to_allow_trailing_semicolon__
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering#define DEFINE_STRING_TABLE_LOOKUP(name,type) __DEFINE_STRING_TABLE_LOOKUP(name,type,)
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering#define DEFINE_PRIVATE_STRING_TABLE_LOOKUP(name,type) __DEFINE_STRING_TABLE_LOOKUP(name,type,static)
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering/* For string conversions where numbers are also acceptable */
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering#define DEFINE_STRING_TABLE_LOOKUP_WITH_FALLBACK(name,type,max) \
80343dc19a9bcd703275ad2ad88f43e5310559d6Zbigniew Jędrzejewski-Szmek int name##_to_string_alloc(type i, char **str) { \
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering if (i < 0 || i > max) \
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering if (i < (type) ELEMENTSOF(name##_table)) { \
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering type name##_from_string(const char *s) { \
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering unsigned u = 0; \
80343dc19a9bcd703275ad2ad88f43e5310559d6Zbigniew Jędrzejewski-Szmek for (i = 0; i < (type)ELEMENTSOF(name##_table); i++) \
80343dc19a9bcd703275ad2ad88f43e5310559d6Zbigniew Jędrzejewski-Szmek struct __useless_struct_to_allow_trailing_semicolon__
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringint close_all_fds(const int except[], unsigned n_except);
83f6936a018b08880670838756e0f4e9ea98b4a7Lennart Poetteringbool fstype_is_network(const char *fstype);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringint read_one_char(FILE *f, char *ret, usec_t timeout, bool *need_nl);
80343dc19a9bcd703275ad2ad88f43e5310559d6Zbigniew Jędrzejewski-Szmekint ask(char *ret, const char *replies, const char *text, ...) _printf_(3, 4);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringint reset_terminal_fd(int fd, bool switch_to_text);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringint open_terminal(const char *name, int mode);
80343dc19a9bcd703275ad2ad88f43e5310559d6Zbigniew Jędrzejewski-Szmekint acquire_terminal(const char *name, bool fail, bool force, bool ignore_tiocstty_eperm, usec_t timeout);
80343dc19a9bcd703275ad2ad88f43e5310559d6Zbigniew Jędrzejewski-Szmekint default_signals(int sig, ...);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringint sigaction_many(const struct sigaction *sa, ...);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringint fopen_temporary(const char *path, FILE **_f, char **_temp_path);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringssize_t loop_read(int fd, void *buf, size_t nbytes, bool do_poll);
80343dc19a9bcd703275ad2ad88f43e5310559d6Zbigniew Jędrzejewski-Szmekssize_t loop_write(int fd, const void *buf, size_t nbytes, bool do_poll);
80343dc19a9bcd703275ad2ad88f43e5310559d6Zbigniew Jędrzejewski-Szmekvoid rename_process(const char name[8]);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringint get_ctty(pid_t, dev_t *_devnr, char **r);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringint chmod_and_chown(const char *path, mode_t mode, uid_t uid, gid_t gid);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringint fchmod_and_fchown(int fd, mode_t mode, uid_t uid, gid_t gid);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringint rm_rf_children(int fd, bool only_dirs, bool honour_sticky, struct stat *root_dev);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringint rm_rf_children_dangerous(int fd, bool only_dirs, bool honour_sticky, struct stat *root_dev);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringint rm_rf(const char *path, bool only_dirs, bool delete_root, bool honour_sticky);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringint rm_rf_dangerous(const char *path, bool only_dirs, bool delete_root, bool honour_sticky);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringcpu_set_t* cpu_set_malloc(unsigned *ncpus);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringint status_vprintf(const char *status, bool ellipse, bool ephemeral, const char *format, va_list ap) _printf_(4,0);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringint status_printf(const char *status, bool ellipse, bool ephemeral, const char *format, ...) _printf_(4,5);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringvoid columns_lines_cache_reset(int _unused_ signum);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringstatic inline const char *ansi_highlight(void) {
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering return on_tty() ? ANSI_HIGHLIGHT_ON : "";
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringstatic inline const char *ansi_highlight_red(void) {
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering return on_tty() ? ANSI_HIGHLIGHT_RED_ON : "";
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringstatic inline const char *ansi_highlight_green(void) {
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering return on_tty() ? ANSI_HIGHLIGHT_GREEN_ON : "";
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringstatic inline const char *ansi_highlight_yellow(void) {
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering return on_tty() ? ANSI_HIGHLIGHT_YELLOW_ON : "";
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringstatic inline const char *ansi_highlight_blue(void) {
83f6936a018b08880670838756e0f4e9ea98b4a7Lennart Poettering return on_tty() ? ANSI_HIGHLIGHT_BLUE_ON : "";
83f6936a018b08880670838756e0f4e9ea98b4a7Lennart Poetteringstatic inline const char *ansi_highlight_off(void) {
83f6936a018b08880670838756e0f4e9ea98b4a7Lennart Poettering return on_tty() ? ANSI_HIGHLIGHT_OFF : "";
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringchar *ellipsize(const char *s, size_t length, unsigned percent);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering /* bytes columns */
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringchar *ellipsize_mem(const char *s, size_t old_length, size_t new_length, unsigned percent);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringchar *unquote(const char *s, const char *quotes);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringchar *normalize_env_assignment(const char *s);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringint wait_for_terminate(pid_t pid, siginfo_t *status);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringint wait_for_terminate_and_warn(const char *name, pid_t pid);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringbool null_or_empty(struct stat *st) _pure_;
d4205751d4643c272059a3728045929dd0e5e800Lennart PoetteringDIR *xopendirat(int dirfd, const char *name, int flags);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringchar *fstab_node_to_udev_node(const char *p);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringbool tty_is_console(const char *tty) _pure_;
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringconst char *default_term_for_tty(const char *tty);
83f6936a018b08880670838756e0f4e9ea98b4a7Lennart Poetteringvoid execute_directory(const char *directory, DIR *_d, char *argv[]);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringbool nulstr_contains(const char*nulstr, const char *needle);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringbool hostname_is_valid(const char *s) _pure_;
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringchar* hostname_cleanup(char *s, bool lowercase);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringint copy_file(const char *from, const char *to, int flags);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringint symlink_atomic(const char *from, const char *to);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringbool display_is_local(const char *display) _pure_;
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringint socket_from_display(const char *display, char **path);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringint get_user_creds(const char **username, uid_t *uid, gid_t *gid, const char **home, const char **shell);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringint get_group_creds(const char **groupname, gid_t *gid);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringint glob_extend(char ***strv, const char *path);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringint dirent_ensure_type(DIR *d, struct dirent *de);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringint in_search_path(const char *path, char **search);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringint get_files_in_directory(const char *path, char ***list);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringchar *strjoin(const char *x, ...) _sentinel_;
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringbool in_charset(const char *s, const char* charset) _pure_;
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringint block_get_whole_disk(dev_t d, dev_t *ret);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringint file_is_priv_sticky(const char *p);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringint strdup_or_null(const char *a, char **b);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering for ((i) = (l); (i) && *(i); (i) = strchr((i), 0)+1)
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering for ((i) = (l), (j) = strchr((i), 0)+1; (i) && *(i); (i) = strchr((j), 0)+1, (j) = *(i) ? strchr((i), 0)+1 : (i))
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringint ioprio_class_to_string_alloc(int i, char **s);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringint ioprio_class_from_string(const char *s);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringconst char *sigchld_code_to_string(int i) _const_;
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringint sigchld_code_from_string(const char *s) _pure_;
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringint log_facility_unshifted_to_string_alloc(int i, char **s);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringint log_facility_unshifted_from_string(const char *s);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringint log_level_to_string_alloc(int i, char **s);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringint log_level_from_string(const char *s);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringint sched_policy_to_string_alloc(int i, char **s);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringint sched_policy_from_string(const char *s);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringconst char *rlimit_to_string(int i) _const_;
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringint rlimit_from_string(const char *s) _pure_;
54b7254c1fa629937f92fd6fa34bdf127b696a00Zbigniew Jędrzejewski-Szmekint ip_tos_to_string_alloc(int i, char **s);
54b7254c1fa629937f92fd6fa34bdf127b696a00Zbigniew Jędrzejewski-Szmekint ip_tos_from_string(const char *s);
54b7254c1fa629937f92fd6fa34bdf127b696a00Zbigniew Jędrzejewski-Szmekconst char *signal_to_string(int i) _const_;
54b7254c1fa629937f92fd6fa34bdf127b696a00Zbigniew Jędrzejewski-Szmekint signal_from_string(const char *s) _pure_;
54b7254c1fa629937f92fd6fa34bdf127b696a00Zbigniew Jędrzejewski-Szmekint signal_from_string_try_harder(const char *s);
54b7254c1fa629937f92fd6fa34bdf127b696a00Zbigniew Jędrzejewski-Szmekint prot_from_flags(int flags) _const_;
54b7254c1fa629937f92fd6fa34bdf127b696a00Zbigniew Jędrzejewski-Szmekchar *format_bytes(char *buf, size_t l, off_t t);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringint fd_wait_for_event(int fd, int event, usec_t timeout);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringvoid* memdup(const void *p, size_t l) _alloc_(2);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringint fork_agent(pid_t *pid, const int except[], unsigned n_except, const char *path, ...);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringint setrlimit_closest(int resource, const struct rlimit *rlim);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringint getenv_for_pid(pid_t pid, const char *field, char **_value);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringbool is_valid_documentation_url(const char *url) _pure_;
54b7254c1fa629937f92fd6fa34bdf127b696a00Zbigniew Jędrzejewski-Szmekstatic inline void freep(void *p) {
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering#define DEFINE_TRIVIAL_CLEANUP_FUNC(type, func) \
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering struct __useless_struct_to_allow_trailing_semicolon__
54b7254c1fa629937f92fd6fa34bdf127b696a00Zbigniew Jędrzejewski-Szmekstatic inline void closep(int *fd) {
54b7254c1fa629937f92fd6fa34bdf127b696a00Zbigniew Jędrzejewski-Szmekstatic inline void umaskp(mode_t *u) {
54b7254c1fa629937f92fd6fa34bdf127b696a00Zbigniew Jędrzejewski-Szmekstatic inline void close_pipep(int (*p)[2]) {
54b7254c1fa629937f92fd6fa34bdf127b696a00Zbigniew Jędrzejewski-SzmekDEFINE_TRIVIAL_CLEANUP_FUNC(FILE*, fclose);
54b7254c1fa629937f92fd6fa34bdf127b696a00Zbigniew Jędrzejewski-SzmekDEFINE_TRIVIAL_CLEANUP_FUNC(FILE*, pclose);
54b7254c1fa629937f92fd6fa34bdf127b696a00Zbigniew Jędrzejewski-SzmekDEFINE_TRIVIAL_CLEANUP_FUNC(DIR*, closedir);
54b7254c1fa629937f92fd6fa34bdf127b696a00Zbigniew Jędrzejewski-SzmekDEFINE_TRIVIAL_CLEANUP_FUNC(FILE*, endmntent);
54b7254c1fa629937f92fd6fa34bdf127b696a00Zbigniew Jędrzejewski-Szmek#define _cleanup_free_ _cleanup_(freep)
54b7254c1fa629937f92fd6fa34bdf127b696a00Zbigniew Jędrzejewski-Szmek#define _cleanup_close_ _cleanup_(closep)
54b7254c1fa629937f92fd6fa34bdf127b696a00Zbigniew Jędrzejewski-Szmek#define _cleanup_umask_ _cleanup_(umaskp)
54b7254c1fa629937f92fd6fa34bdf127b696a00Zbigniew Jędrzejewski-Szmek#define _cleanup_globfree_ _cleanup_(globfree)
54b7254c1fa629937f92fd6fa34bdf127b696a00Zbigniew Jędrzejewski-Szmek#define _cleanup_fclose_ _cleanup_(fclosep)
54b7254c1fa629937f92fd6fa34bdf127b696a00Zbigniew Jędrzejewski-Szmek#define _cleanup_pclose_ _cleanup_(pclosep)
54b7254c1fa629937f92fd6fa34bdf127b696a00Zbigniew Jędrzejewski-Szmek#define _cleanup_closedir_ _cleanup_(closedirp)
54b7254c1fa629937f92fd6fa34bdf127b696a00Zbigniew Jędrzejewski-Szmek#define _cleanup_endmntent_ _cleanup_(endmntentp)
54b7254c1fa629937f92fd6fa34bdf127b696a00Zbigniew Jędrzejewski-Szmek#define _cleanup_close_pipe_ _cleanup_(close_pipep)
54b7254c1fa629937f92fd6fa34bdf127b696a00Zbigniew Jędrzejewski-Szmek_malloc_ _alloc_(1, 2) static inline void *malloc_multiply(size_t a, size_t b) {
54b7254c1fa629937f92fd6fa34bdf127b696a00Zbigniew Jędrzejewski-Szmek if (_unlikely_(b == 0 || a > ((size_t) -1) / b))
return NULL;
return memdup(p, a * b);
int (*compar) (const void *, const void *, void *),
void *arg);
bool is_locale_utf8(void);
typedef enum DrawSpecialChar {
int on_ac_power(void);
if (ferror(f)) { \
on_error; \
if (!de) { \
if (errno > 0) { \
on_error; \
memset(s, c, n);
return (uint8_t*)s + n;
char *strrep(const char *s, unsigned n);
struct _umask_struct_ {
bool quit;
return __builtin_ctz(n);
static inline bool logind_running(void) {
#define DECIMAL_STR_WIDTH(x) \
ans++; \
ans; \
#define alloca0(n) \
char *_new_; \
#define strappenda(a, b) \
char *_c_; \
_c_; \
const char *_r_; \
if (_pid_ == 0) { \
_r_; \
struct _locale_struct_ {
bool quit;
for (_cleanup_(_reset_locale_) struct _locale_struct_ _saved_locale_ = { (locale_t) 0, (locale_t) 0, false }; \
int shall_restore_state(void);
int (*compar)(const void *, const void *)) {
if (nmemb) {