util.h revision 20f56fddcd58c84fa73597486e905c652667214f
fb0951b02ebf51a93acf12721d8857d31ce57ba3Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
47be870bd83fb3719dffc3ee9348a409ab762a14Lennart Poettering This file is part of systemd.
5430f7f2bc7330f3088b894166bf3524a067e3d8Lennart Poettering Copyright 2010 Lennart Poettering
47be870bd83fb3719dffc3ee9348a409ab762a14Lennart Poettering systemd is free software; you can redistribute it and/or modify it
47be870bd83fb3719dffc3ee9348a409ab762a14Lennart Poettering under the terms of the GNU Lesser General Public License as published by
47be870bd83fb3719dffc3ee9348a409ab762a14Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
47be870bd83fb3719dffc3ee9348a409ab762a14Lennart Poettering (at your option) any later version.
5430f7f2bc7330f3088b894166bf3524a067e3d8Lennart Poettering systemd is distributed in the hope that it will be useful, but
47be870bd83fb3719dffc3ee9348a409ab762a14Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
5430f7f2bc7330f3088b894166bf3524a067e3d8Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
47be870bd83fb3719dffc3ee9348a409ab762a14Lennart Poettering Lesser General Public License for more details.
4e949c11a1df4547d5f102e4131e07b026369cd7Javier Jardón You should have received a copy of the GNU Lesser General Public License
4e949c11a1df4547d5f102e4131e07b026369cd7Javier Jardón along with systemd; If not, see <http://www.gnu.org/licenses/>.
0eaeca1f2373a323b98c86b47561d98e59c67b25Kay Sievers/* What is interpreted as whitespace? */
b62cfcea00862ccbf0e5e297f8a339f70987edefMichael Biebl/* What characters are special in the shell? */
b62cfcea00862ccbf0e5e297f8a339f70987edefMichael Biebl/* must be escaped outside and inside double-quotes */
9a60da2834074d970ca063c210fe9d2f05c70532Thierry Reding/* can be escaped or double-quoted */
732bfe09aeffc3cd78b80ee9e20c9c3babd944d6Zbigniew Jędrzejewski-Szmek#define SHELL_NEED_QUOTES SHELL_NEED_ESCAPE GLOB_CHARS "'()<>|&;"
732bfe09aeffc3cd78b80ee9e20c9c3babd944d6Zbigniew Jędrzejewski-Szmek#define ANSI_HIGHLIGHT_ON "\x1B[1;39m"
732bfe09aeffc3cd78b80ee9e20c9c3babd944d6Zbigniew Jędrzejewski-Szmek#define ANSI_HIGHLIGHT_RED_ON "\x1B[1;31m"
732bfe09aeffc3cd78b80ee9e20c9c3babd944d6Zbigniew Jędrzejewski-Szmek#define ANSI_HIGHLIGHT_GREEN_ON "\x1B[1;32m"
732bfe09aeffc3cd78b80ee9e20c9c3babd944d6Zbigniew Jędrzejewski-Szmek#define ANSI_HIGHLIGHT_YELLOW_ON "\x1B[1;33m"
732bfe09aeffc3cd78b80ee9e20c9c3babd944d6Zbigniew Jędrzejewski-Szmek#define ANSI_HIGHLIGHT_BLUE_ON "\x1B[1;34m"
732bfe09aeffc3cd78b80ee9e20c9c3babd944d6Zbigniew Jędrzejewski-Szmek#define ANSI_HIGHLIGHT_OFF "\x1B[0m"
732bfe09aeffc3cd78b80ee9e20c9c3babd944d6Zbigniew Jędrzejewski-Szmek#define ANSI_ERASE_TO_END_OF_LINE "\x1B[K"
be1a67d9d63bfdd4a5f8ba9cfc804030f10f5833Lennart Poettering#define PAGE_ALIGN(l) ALIGN_TO((l), page_size())
27765dfc7a32d790badb29e6498b34edb0b60c33Lennart Poettering#define strneq(a, b, n) (strncmp((a), (b), (n)) == 0)
d1ab0ca07372649dad70a0348d75e394f254e1b6Lennart Poettering#define strcaseeq(a,b) (strcasecmp((a),(b)) == 0)
780040dc2a4b08a2c1fe5bd8db3a70e966c2acb3Kay Sievers#define strncaseeq(a, b, n) (strncasecmp((a), (b), (n)) == 0)
d1ab0ca07372649dad70a0348d75e394f254e1b6Lennart Poetteringbool streq_ptr(const char *a, const char *b) _pure_;
d1ab0ca07372649dad70a0348d75e394f254e1b6Lennart Poettering#define new(t, n) ((t*) malloc_multiply(sizeof(t), (n)))
d1ab0ca07372649dad70a0348d75e394f254e1b6Lennart Poettering#define new0(t, n) ((t*) calloc((n), sizeof(t)))
d1ab0ca07372649dad70a0348d75e394f254e1b6Lennart Poettering#define newa(t, n) ((t*) alloca(sizeof(t)*(n)))
d1ab0ca07372649dad70a0348d75e394f254e1b6Lennart Poettering#define newa0(t, n) ((t*) alloca0(sizeof(t)*(n)))
d1ab0ca07372649dad70a0348d75e394f254e1b6Lennart Poettering#define newdup(t, p, n) ((t*) memdup_multiply(p, sizeof(t), (n)))
d1ab0ca07372649dad70a0348d75e394f254e1b6Lennart Poetteringstatic inline const char* yes_no(bool b) {
be1a67d9d63bfdd4a5f8ba9cfc804030f10f5833Lennart Poetteringstatic inline const char* true_false(bool b) {
d200735e13c52dcfe36c0e066f9f6c2fbfb85a9cMichal Schmidtstatic inline const char* one_zero(bool b) {
d1ab0ca07372649dad70a0348d75e394f254e1b6Lennart Poetteringstatic inline const char* strempty(const char *s) {
d1ab0ca07372649dad70a0348d75e394f254e1b6Lennart Poettering return s ? s : "";
9b85fc6a89386582bfe792dba881800b0a093839Gustavo Sverzut Barbieristatic inline const char* strnull(const char *s) {
9b85fc6a89386582bfe792dba881800b0a093839Gustavo Sverzut Barbieri return s ? s : "(null)";
c1663b9daf5a43425e54bbe3daf6b10e64578f80Lennart Poetteringstatic inline const char *strna(const char *s) {
b850b06e1efcc7e27cfd785759a3a913ac9ed196Kay Sievers return s ? s : "n/a";
b850b06e1efcc7e27cfd785759a3a913ac9ed196Kay Sieversstatic inline bool isempty(const char *p) {
732bfe09aeffc3cd78b80ee9e20c9c3babd944d6Zbigniew Jędrzejewski-Szmek return !p || !p[0];
a6c0b31d509f76023d8efbcd5e912863c8fb254cZbigniew Jędrzejewski-Szmekstatic inline char *startswith(const char *s, const char *prefix) {
9e7adc3ae1133fa08a468768a490812299fad030Lucas De Marchi return (char*) s + l;
39c4ead2323b45bbe9866e0f97fd8dcfb8a0bedeZbigniew Jędrzejewski-Szmekstatic inline char *startswith_no_case(const char *s, const char *prefix) {
ccd06097c79218f7d5ea4c21721bbcbc7c467dcaZbigniew Jędrzejewski-Szmek if (strncasecmp(s, prefix, l) == 0)
ccd06097c79218f7d5ea4c21721bbcbc7c467dcaZbigniew Jędrzejewski-Szmek return (char*) s + l;
c937e0d5c579863677e0fcb5508517f7714c332dZbigniew Jędrzejewski-Szmekchar *endswith(const char *s, const char *postfix) _pure_;
c937e0d5c579863677e0fcb5508517f7714c332dZbigniew Jędrzejewski-Szmekchar *first_word(const char *s, const char *word) _pure_;
32dcef3ab1eb91ee469c3246ef859578dccd8a45Zbigniew Jędrzejewski-Szmekvoid close_many(const int fds[], unsigned n_fd);
c937e0d5c579863677e0fcb5508517f7714c332dZbigniew Jędrzejewski-Szmekint parse_size(const char *t, off_t base, off_t *size);
c937e0d5c579863677e0fcb5508517f7714c332dZbigniew Jędrzejewski-Szmekint parse_boolean(const char *v) _pure_;
c937e0d5c579863677e0fcb5508517f7714c332dZbigniew Jędrzejewski-Szmekint parse_uid(const char *s, uid_t* ret_uid);
c937e0d5c579863677e0fcb5508517f7714c332dZbigniew Jędrzejewski-Szmek#define parse_gid(s, ret_uid) parse_uid(s, ret_uid)
1864b0e39505cd44a98eee61c97916b86491c0b4Zbigniew Jędrzejewski-Szmekint safe_atou(const char *s, unsigned *ret_u);
1864b0e39505cd44a98eee61c97916b86491c0b4Zbigniew Jędrzejewski-Szmekint safe_atoi(const char *s, int *ret_i);
a6c0b31d509f76023d8efbcd5e912863c8fb254cZbigniew Jędrzejewski-Szmekint safe_atollu(const char *s, unsigned long long *ret_u);
a6c0b31d509f76023d8efbcd5e912863c8fb254cZbigniew Jędrzejewski-Szmekint safe_atolli(const char *s, long long int *ret_i);
a6c0b31d509f76023d8efbcd5e912863c8fb254cZbigniew Jędrzejewski-Szmekint safe_atod(const char *s, double *ret_d);
a6c0b31d509f76023d8efbcd5e912863c8fb254cZbigniew Jędrzejewski-Szmekint safe_atou8(const char *s, uint8_t *ret);
a6c0b31d509f76023d8efbcd5e912863c8fb254cZbigniew Jędrzejewski-Szmekstatic inline int safe_atolu(const char *s, unsigned long *ret_u) {
a6c0b31d509f76023d8efbcd5e912863c8fb254cZbigniew Jędrzejewski-Szmek assert_cc(sizeof(unsigned long) == sizeof(unsigned));
f2ec0646aba7c6703a6c79603957e805b74c3befZbigniew Jędrzejewski-Szmek return safe_atou(s, (unsigned*) ret_u);
c937e0d5c579863677e0fcb5508517f7714c332dZbigniew Jędrzejewski-Szmekstatic inline int safe_atoli(const char *s, long int *ret_u) {
c937e0d5c579863677e0fcb5508517f7714c332dZbigniew Jędrzejewski-Szmek assert_cc(sizeof(long int) == sizeof(int));
c937e0d5c579863677e0fcb5508517f7714c332dZbigniew Jędrzejewski-Szmek return safe_atoi(s, (int*) ret_u);
7959ff9914a6f3a59dbff95c199bcc540b70ac94Kay Sieversstatic inline int safe_atolu(const char *s, unsigned long *ret_u) {
4b357e15876b730343db08719c877fdb45b6ad42Michael Marineau assert_cc(sizeof(unsigned long) == sizeof(unsigned long long));
7959ff9914a6f3a59dbff95c199bcc540b70ac94Kay Sievers return safe_atollu(s, (unsigned long long*) ret_u);
7959ff9914a6f3a59dbff95c199bcc540b70ac94Kay Sieversstatic inline int safe_atoli(const char *s, long int *ret_u) {
85f19d825e7504676f3a80c78c1d9a7ec35a3b3fMichael Biebl assert_cc(sizeof(long int) == sizeof(long long int));
85f19d825e7504676f3a80c78c1d9a7ec35a3b3fMichael Biebl return safe_atolli(s, (long long int*) ret_u);
7959ff9914a6f3a59dbff95c199bcc540b70ac94Kay Sieversstatic inline int safe_atou32(const char *s, uint32_t *ret_u) {
7959ff9914a6f3a59dbff95c199bcc540b70ac94Kay Sievers assert_cc(sizeof(uint32_t) == sizeof(unsigned));
fba1ea06bb5b653e9eb0cc1b6004af8da273a4abShawn Landdenstatic inline int safe_atoi32(const char *s, int32_t *ret_i) {
3b794314149e40afaf3c456285e1e529747b6560Holger Schurigstatic inline int safe_atou64(const char *s, uint64_t *ret_u) {
a8348796c0d39435b1c3d85ce6e95dad1ac85fecLennart Poettering assert_cc(sizeof(uint64_t) == sizeof(unsigned long long));
9388e99e208a6487b26dcbda86005ee9eba8d93dMichael Olbrich return safe_atollu(s, (unsigned long long*) ret_u);
a8348796c0d39435b1c3d85ce6e95dad1ac85fecLennart Poetteringstatic inline int safe_atoi64(const char *s, int64_t *ret_i) {
b237ef2cfac7ab0b33170809e8cb64628606207dTollef Fog Heen assert_cc(sizeof(int64_t) == sizeof(long long int));
a9b5b03212f9c854938483b8901e433c2ba6619bMichael Tremer return safe_atolli(s, (long long int*) ret_i);
ac6b760ceedd4b21921b6a682cf1479af3d3024fZbigniew Jędrzejewski-Szmekint safe_atou16(const char *s, uint16_t *ret);
ac6b760ceedd4b21921b6a682cf1479af3d3024fZbigniew Jędrzejewski-Szmekint safe_atoi16(const char *s, int16_t *ret);
ac6b760ceedd4b21921b6a682cf1479af3d3024fZbigniew Jędrzejewski-Szmekconst char* split(const char **state, size_t *l, const char *separator, bool quoted);
ac6b760ceedd4b21921b6a682cf1479af3d3024fZbigniew Jędrzejewski-Szmek#define FOREACH_WORD(word, length, s, state) \
ac6b760ceedd4b21921b6a682cf1479af3d3024fZbigniew Jędrzejewski-Szmek _FOREACH_WORD(word, length, s, WHITESPACE, false, state)
2270309471213a3c960543e523130627e9cb10e2Kay Sievers#define FOREACH_WORD_SEPARATOR(word, length, s, separator, state) \
4b357e15876b730343db08719c877fdb45b6ad42Michael Marineau _FOREACH_WORD(word, length, s, separator, false, state)
53e856e16ac37fe30b8bb59153ff69aad0fa9c27Zbigniew Jędrzejewski-Szmek#define FOREACH_WORD_QUOTED(word, length, s, state) \
53e856e16ac37fe30b8bb59153ff69aad0fa9c27Zbigniew Jędrzejewski-Szmek _FOREACH_WORD(word, length, s, WHITESPACE, true, state)
53e856e16ac37fe30b8bb59153ff69aad0fa9c27Zbigniew Jędrzejewski-Szmek#define _FOREACH_WORD(word, length, s, separator, quoted, state) \
53e856e16ac37fe30b8bb59153ff69aad0fa9c27Zbigniew Jędrzejewski-Szmek for ((state) = (s), (word) = split(&(state), &(length), (separator), (quoted)); (word); (word) = split(&(state), &(length), (separator), (quoted)))
53e856e16ac37fe30b8bb59153ff69aad0fa9c27Zbigniew Jędrzejewski-Szmekpid_t get_parent_of_pid(pid_t pid, pid_t *ppid);
53e856e16ac37fe30b8bb59153ff69aad0fa9c27Zbigniew Jędrzejewski-Szmekchar *strappend(const char *s, const char *suffix);
53e856e16ac37fe30b8bb59153ff69aad0fa9c27Zbigniew Jędrzejewski-Szmekchar *strnappend(const char *s, const char *suffix, size_t length);
6aea6d10f460853111ca8744201ec8dade97de3cThomas H.P. Andersenchar *replace_env(const char *format, char **env);
6aea6d10f460853111ca8744201ec8dade97de3cThomas H.P. Andersenchar **replace_env_argv(char **argv, char **env);
6aea6d10f460853111ca8744201ec8dade97de3cThomas H.P. Andersenint readlinkat_malloc(int fd, const char *p, char **ret);
6aea6d10f460853111ca8744201ec8dade97de3cThomas H.P. Andersenint readlink_malloc(const char *p, char **r);
6aea6d10f460853111ca8744201ec8dade97de3cThomas H.P. Andersenint readlink_value(const char *p, char **ret);
6aea6d10f460853111ca8744201ec8dade97de3cThomas H.P. Andersenint readlink_and_make_absolute(const char *p, char **r);
6aea6d10f460853111ca8744201ec8dade97de3cThomas H.P. Andersenint readlink_and_canonicalize(const char *p, char **r);
6aea6d10f460853111ca8744201ec8dade97de3cThomas H.P. Andersenchar *delete_chars(char *s, const char *bad);
6aea6d10f460853111ca8744201ec8dade97de3cThomas H.P. Andersenchar *file_in_same_dir(const char *path, const char *filename);
6aea6d10f460853111ca8744201ec8dade97de3cThomas H.P. Andersenint rmdir_parents(const char *path, const char *stop);
6aea6d10f460853111ca8744201ec8dade97de3cThomas H.P. Andersenint get_process_comm(pid_t pid, char **name);
e30431623a7d871da123cc37055ac49abf2c20eaTom Gundersenint get_process_cmdline(pid_t pid, size_t max_length, bool comm_fallback, char **line);
e2ca86cf78f911a8be51f0224796e24883019139Dave Reisnerint get_process_capeff(pid_t pid, char **capeff);
e2ca86cf78f911a8be51f0224796e24883019139Dave Reisnerint get_process_environ(pid_t pid, char **environ);
f553b3b1074151200187df916427a1468186435eAnders Olofssonchar *cescape(const char *s);
f553b3b1074151200187df916427a1468186435eAnders Olofssonchar *cunescape(const char *s);
f553b3b1074151200187df916427a1468186435eAnders Olofssonchar *cunescape_length(const char *s, size_t length);
f553b3b1074151200187df916427a1468186435eAnders Olofssonchar *cunescape_length_with_prefix(const char *s, size_t length, const char *prefix);
f553b3b1074151200187df916427a1468186435eAnders Olofssonchar *xescape(const char *s, const char *bad);
f553b3b1074151200187df916427a1468186435eAnders Olofssonbool dirent_is_file(const struct dirent *de) _pure_;
f553b3b1074151200187df916427a1468186435eAnders Olofssonbool dirent_is_file_with_suffix(const struct dirent *de, const char *suffix) _pure_;
c0467cf387548dc98c0254f63553d862b35a84e5Ronny Chevalierbool hidden_file(const char *filename) _pure_;
c0467cf387548dc98c0254f63553d862b35a84e5Ronny Chevalierbool chars_intersect(const char *a, const char *b) _pure_;
c0467cf387548dc98c0254f63553d862b35a84e5Ronny Chevalier random_bytes(&u, sizeof(u));
816115863962548a9a0d9fbfe429c7f8e685beacRoberto Sassu random_bytes(&u, sizeof(u));
816115863962548a9a0d9fbfe429c7f8e685beacRoberto Sassu/* For basic lookup tables with strictly enumerated entries */
816115863962548a9a0d9fbfe429c7f8e685beacRoberto Sassu#define _DEFINE_STRING_TABLE_LOOKUP_TO_STRING(name,type,scope) \
816115863962548a9a0d9fbfe429c7f8e685beacRoberto Sassu scope const char *name##_to_string(type i) { \
816115863962548a9a0d9fbfe429c7f8e685beacRoberto Sassu if (i < 0 || i >= (type) ELEMENTSOF(name##_table)) \
77e68fa2f0bd018bab2621a31919bfaa6a6b0a35Lennart Poetteringssize_t string_table_lookup(const char * const *table, size_t len, const char *key);
77e68fa2f0bd018bab2621a31919bfaa6a6b0a35Lennart Poettering#define _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING(name,type,scope) \
77e68fa2f0bd018bab2621a31919bfaa6a6b0a35Lennart Poettering scope inline type name##_from_string(const char *s) { \
77e68fa2f0bd018bab2621a31919bfaa6a6b0a35Lennart Poettering return (type)string_table_lookup(name##_table, ELEMENTSOF(name##_table), s); \
77e68fa2f0bd018bab2621a31919bfaa6a6b0a35Lennart Poettering#define _DEFINE_STRING_TABLE_LOOKUP(name,type,scope) \
77e68fa2f0bd018bab2621a31919bfaa6a6b0a35Lennart Poettering _DEFINE_STRING_TABLE_LOOKUP_TO_STRING(name,type,scope) \
77e68fa2f0bd018bab2621a31919bfaa6a6b0a35Lennart Poettering _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING(name,type,scope) \
77e68fa2f0bd018bab2621a31919bfaa6a6b0a35Lennart Poettering struct __useless_struct_to_allow_trailing_semicolon__
77e68fa2f0bd018bab2621a31919bfaa6a6b0a35Lennart Poettering#define DEFINE_STRING_TABLE_LOOKUP(name,type) _DEFINE_STRING_TABLE_LOOKUP(name,type,)
77e68fa2f0bd018bab2621a31919bfaa6a6b0a35Lennart Poettering#define DEFINE_PRIVATE_STRING_TABLE_LOOKUP(name,type) _DEFINE_STRING_TABLE_LOOKUP(name,type,static)
77e68fa2f0bd018bab2621a31919bfaa6a6b0a35Lennart Poettering#define DEFINE_PRIVATE_STRING_TABLE_LOOKUP_TO_STRING(name,type) _DEFINE_STRING_TABLE_LOOKUP_TO_STRING(name,type,static)
77e68fa2f0bd018bab2621a31919bfaa6a6b0a35Lennart Poettering#define DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING(name,type) _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING(name,type,static)
591622d7efbc828f00f190d91b6608148b967ff5Lennart Poettering/* For string conversions where numbers are also acceptable */
591622d7efbc828f00f190d91b6608148b967ff5Lennart Poettering#define DEFINE_STRING_TABLE_LOOKUP_WITH_FALLBACK(name,type,max) \
591622d7efbc828f00f190d91b6608148b967ff5Lennart Poettering int name##_to_string_alloc(type i, char **str) { \
6a6751fe24bf456cf5c1efad785a4d11e78b42d0Lennart Poettering if (i < 0 || i > max) \
6a6751fe24bf456cf5c1efad785a4d11e78b42d0Lennart Poettering if (i < (type) ELEMENTSOF(name##_table)) { \
eef65bf3ee6f73afa4a5de23ae3a794a279f30c0Michael Scherer unsigned u = 0; \
eef65bf3ee6f73afa4a5de23ae3a794a279f30c0Michael Scherer for (i = 0; i < (type)ELEMENTSOF(name##_table); i++) \
eef65bf3ee6f73afa4a5de23ae3a794a279f30c0Michael Scherer return (type) u; \
45df1f2c9a7fee67b37f64ddd00adad5982844faCristian Rodríguez struct __useless_struct_to_allow_trailing_semicolon__
56cf987fe74270bde4e16c7ec9e0414a9030723bDaniel J Walshint close_all_fds(const int except[], unsigned n_except);
45df1f2c9a7fee67b37f64ddd00adad5982844faCristian Rodríguezbool fstype_is_network(const char *fstype);
45df1f2c9a7fee67b37f64ddd00adad5982844faCristian Rodríguezint read_one_char(FILE *f, char *ret, usec_t timeout, bool *need_nl);
45df1f2c9a7fee67b37f64ddd00adad5982844faCristian Rodríguezint ask_char(char *ret, const char *replies, const char *text, ...) _printf_(3, 4);
45df1f2c9a7fee67b37f64ddd00adad5982844faCristian Rodríguezint ask_string(char **ret, const char *text, ...) _printf_(2, 3);
807e17f05e217b474af39503efb9503d81b12596Lennart Poetteringint reset_terminal_fd(int fd, bool switch_to_text);
807e17f05e217b474af39503efb9503d81b12596Lennart Poetteringint open_terminal(const char *name, int mode);
807e17f05e217b474af39503efb9503d81b12596Lennart Poetteringint acquire_terminal(const char *name, bool fail, bool force, bool ignore_tiocstty_eperm, usec_t timeout);
3e2147858f21943d5f4a781c60f33ac22c6096edKay Sieversint sigaction_many(const struct sigaction *sa, ...);
0213c3f8102bdc934c629d11a44ca0b408762287Lennart Poetteringint fopen_temporary(const char *path, FILE **_f, char **_temp_path);
5b6319dceedd81f3f1ce7eb70ea5defaef43bcecLennart Poetteringssize_t loop_read(int fd, void *buf, size_t nbytes, bool do_poll);
5b6319dceedd81f3f1ce7eb70ea5defaef43bcecLennart Poetteringint loop_write(int fd, const void *buf, size_t nbytes, bool do_poll);
5b6319dceedd81f3f1ce7eb70ea5defaef43bcecLennart Poetteringint get_ctty(pid_t, dev_t *_devnr, char **r);
5b6319dceedd81f3f1ce7eb70ea5defaef43bcecLennart Poetteringint chmod_and_chown(const char *path, mode_t mode, uid_t uid, gid_t gid);
5b6319dceedd81f3f1ce7eb70ea5defaef43bcecLennart Poetteringint fchmod_and_fchown(int fd, mode_t mode, uid_t uid, gid_t gid);
5b6319dceedd81f3f1ce7eb70ea5defaef43bcecLennart Poetteringint rm_rf_children(int fd, bool only_dirs, bool honour_sticky, struct stat *root_dev);
5b6319dceedd81f3f1ce7eb70ea5defaef43bcecLennart Poetteringint rm_rf_children_dangerous(int fd, bool only_dirs, bool honour_sticky, struct stat *root_dev);
5b6319dceedd81f3f1ce7eb70ea5defaef43bcecLennart Poetteringint rm_rf(const char *path, bool only_dirs, bool delete_root, bool honour_sticky);
5b6319dceedd81f3f1ce7eb70ea5defaef43bcecLennart Poetteringint rm_rf_dangerous(const char *path, bool only_dirs, bool delete_root, bool honour_sticky);
5b6319dceedd81f3f1ce7eb70ea5defaef43bcecLennart Poetteringcpu_set_t* cpu_set_malloc(unsigned *ncpus);
5b6319dceedd81f3f1ce7eb70ea5defaef43bcecLennart Poetteringint status_vprintf(const char *status, bool ellipse, bool ephemeral, const char *format, va_list ap) _printf_(4,0);
5b6319dceedd81f3f1ce7eb70ea5defaef43bcecLennart Poetteringint status_printf(const char *status, bool ellipse, bool ephemeral, const char *format, ...) _printf_(4,5);
5b6319dceedd81f3f1ce7eb70ea5defaef43bcecLennart Poettering#define xsprintf(buf, fmt, ...) assert_se((size_t) snprintf(buf, ELEMENTSOF(buf), fmt, __VA_ARGS__) < ELEMENTSOF(buf))
5b6319dceedd81f3f1ce7eb70ea5defaef43bcecLennart Poetteringunsigned lines(void);
5b6319dceedd81f3f1ce7eb70ea5defaef43bcecLennart Poetteringvoid columns_lines_cache_reset(int _unused_ signum);
812cce323db081634f37e4ec6d29f2b9328a3f52Lennart Poetteringstatic inline const char *ansi_highlight(void) {
5b6319dceedd81f3f1ce7eb70ea5defaef43bcecLennart Poettering return on_tty() ? ANSI_HIGHLIGHT_ON : "";
5b6319dceedd81f3f1ce7eb70ea5defaef43bcecLennart Poetteringstatic inline const char *ansi_highlight_red(void) {
5b6319dceedd81f3f1ce7eb70ea5defaef43bcecLennart Poettering return on_tty() ? ANSI_HIGHLIGHT_RED_ON : "";
3e2147858f21943d5f4a781c60f33ac22c6096edKay Sieversstatic inline const char *ansi_highlight_green(void) {
5eda94dda25bccda928c4b33c790dbe748573a22Lennart Poettering return on_tty() ? ANSI_HIGHLIGHT_GREEN_ON : "";
5eda94dda25bccda928c4b33c790dbe748573a22Lennart Poetteringstatic inline const char *ansi_highlight_yellow(void) {
5eda94dda25bccda928c4b33c790dbe748573a22Lennart Poettering return on_tty() ? ANSI_HIGHLIGHT_YELLOW_ON : "";
5eda94dda25bccda928c4b33c790dbe748573a22Lennart Poetteringstatic inline const char *ansi_highlight_blue(void) {
5eda94dda25bccda928c4b33c790dbe748573a22Lennart Poettering return on_tty() ? ANSI_HIGHLIGHT_BLUE_ON : "";
5eda94dda25bccda928c4b33c790dbe748573a22Lennart Poetteringstatic inline const char *ansi_highlight_off(void) {
5eda94dda25bccda928c4b33c790dbe748573a22Lennart Poettering return on_tty() ? ANSI_HIGHLIGHT_OFF : "";
5eda94dda25bccda928c4b33c790dbe748573a22Lennart Poetteringint files_same(const char *filea, const char *fileb);
5eda94dda25bccda928c4b33c790dbe748573a22Lennart Poetteringchar *ellipsize(const char *s, size_t length, unsigned percent);
5eda94dda25bccda928c4b33c790dbe748573a22Lennart Poettering /* bytes columns */
5eda94dda25bccda928c4b33c790dbe748573a22Lennart Poetteringchar *ellipsize_mem(const char *s, size_t old_length, size_t new_length, unsigned percent);
5eda94dda25bccda928c4b33c790dbe748573a22Lennart Poetteringint touch_file(const char *path, bool parents, usec_t stamp, uid_t uid, gid_t gid, mode_t mode);
5eda94dda25bccda928c4b33c790dbe748573a22Lennart Poetteringchar *unquote(const char *s, const char *quotes);
5eda94dda25bccda928c4b33c790dbe748573a22Lennart Poetteringchar *normalize_env_assignment(const char *s);
5eda94dda25bccda928c4b33c790dbe748573a22Lennart Poetteringint wait_for_terminate(pid_t pid, siginfo_t *status);
5eda94dda25bccda928c4b33c790dbe748573a22Lennart Poetteringint wait_for_terminate_and_warn(const char *name, pid_t pid, bool check_exit_code);
5eda94dda25bccda928c4b33c790dbe748573a22Lennart Poetteringbool null_or_empty(struct stat *st) _pure_;
fb0951b02ebf51a93acf12721d8857d31ce57ba3Lennart PoetteringDIR *xopendirat(int dirfd, const char *name, int flags);
fb0951b02ebf51a93acf12721d8857d31ce57ba3Lennart Poetteringchar *fstab_node_to_udev_node(const char *p);
fb0951b02ebf51a93acf12721d8857d31ce57ba3Lennart Poetteringbool tty_is_console(const char *tty) _pure_;
fb0951b02ebf51a93acf12721d8857d31ce57ba3Lennart Poetteringconst char *default_term_for_tty(const char *tty);
fb0951b02ebf51a93acf12721d8857d31ce57ba3Lennart Poetteringvoid execute_directories(const char* const* directories, usec_t timeout, char *argv[]);
fb0951b02ebf51a93acf12721d8857d31ce57ba3Lennart Poetteringbool nulstr_contains(const char*nulstr, const char *needle);
fb0951b02ebf51a93acf12721d8857d31ce57ba3Lennart Poetteringbool hostname_is_valid(const char *s) _pure_;
fb0951b02ebf51a93acf12721d8857d31ce57ba3Lennart Poetteringchar* hostname_cleanup(char *s, bool lowercase);
fb0951b02ebf51a93acf12721d8857d31ce57ba3Lennart Poetteringbool machine_name_is_valid(const char *s) _pure_;
fb0951b02ebf51a93acf12721d8857d31ce57ba3Lennart Poetteringint symlink_atomic(const char *from, const char *to);
fb0951b02ebf51a93acf12721d8857d31ce57ba3Lennart Poetteringint mknod_atomic(const char *path, mode_t mode, dev_t dev);
fb0951b02ebf51a93acf12721d8857d31ce57ba3Lennart Poetteringint mkfifo_atomic(const char *path, mode_t mode);
2b3e18de74ca89b374dd4f7a2c30e5731d347841Karol Lewandowskibool display_is_local(const char *display) _pure_;
2b3e18de74ca89b374dd4f7a2c30e5731d347841Karol Lewandowskiint socket_from_display(const char *display, char **path);
2b3e18de74ca89b374dd4f7a2c30e5731d347841Karol Lewandowskiint get_user_creds(const char **username, uid_t *uid, gid_t *gid, const char **home, const char **shell);
2b3e18de74ca89b374dd4f7a2c30e5731d347841Karol Lewandowskiint get_group_creds(const char **groupname, gid_t *gid);
2b3e18de74ca89b374dd4f7a2c30e5731d347841Karol Lewandowskiint glob_extend(char ***strv, const char *path);
2b3e18de74ca89b374dd4f7a2c30e5731d347841Karol Lewandowskiint dirent_ensure_type(DIR *d, struct dirent *de);
6a6751fe24bf456cf5c1efad785a4d11e78b42d0Lennart Poetteringint get_files_in_directory(const char *path, char ***list);
2b3e18de74ca89b374dd4f7a2c30e5731d347841Karol Lewandowskichar *strjoin(const char *x, ...) _sentinel_;
8b197c3a8a57c3f7c231b39e5660856fd9580c80Auke Kokstatic inline bool _pure_ in_charset(const char *s, const char* charset) {
2b3e18de74ca89b374dd4f7a2c30e5731d347841Karol Lewandowskiint block_get_whole_disk(dev_t d, dev_t *ret);
7560fffcd2531786b9c1ca657667a43e90331326Lennart Poettering for ((i) = (l); (i) && *(i); (i) = strchr((i), 0)+1)
7560fffcd2531786b9c1ca657667a43e90331326Lennart Poettering for ((i) = (l), (j) = strchr((i), 0)+1; (i) && *(i); (i) = strchr((j), 0)+1, (j) = *(i) ? strchr((i), 0)+1 : (i))
7560fffcd2531786b9c1ca657667a43e90331326Lennart Poetteringint ioprio_class_to_string_alloc(int i, char **s);
7560fffcd2531786b9c1ca657667a43e90331326Lennart Poetteringint ioprio_class_from_string(const char *s);
7560fffcd2531786b9c1ca657667a43e90331326Lennart Poetteringconst char *sigchld_code_to_string(int i) _const_;
7560fffcd2531786b9c1ca657667a43e90331326Lennart Poetteringint sigchld_code_from_string(const char *s) _pure_;
7560fffcd2531786b9c1ca657667a43e90331326Lennart Poetteringint log_facility_unshifted_to_string_alloc(int i, char **s);
7560fffcd2531786b9c1ca657667a43e90331326Lennart Poetteringint log_facility_unshifted_from_string(const char *s);
7560fffcd2531786b9c1ca657667a43e90331326Lennart Poetteringint log_level_to_string_alloc(int i, char **s);
7560fffcd2531786b9c1ca657667a43e90331326Lennart Poetteringint log_level_from_string(const char *s);
7560fffcd2531786b9c1ca657667a43e90331326Lennart Poetteringint sched_policy_to_string_alloc(int i, char **s);
7560fffcd2531786b9c1ca657667a43e90331326Lennart Poetteringint sched_policy_from_string(const char *s);
7560fffcd2531786b9c1ca657667a43e90331326Lennart Poetteringconst char *rlimit_to_string(int i) _const_;
7560fffcd2531786b9c1ca657667a43e90331326Lennart Poetteringint rlimit_from_string(const char *s) _pure_;
7560fffcd2531786b9c1ca657667a43e90331326Lennart Poetteringint ip_tos_to_string_alloc(int i, char **s);
7560fffcd2531786b9c1ca657667a43e90331326Lennart Poetteringint ip_tos_from_string(const char *s);
7560fffcd2531786b9c1ca657667a43e90331326Lennart Poetteringconst char *signal_to_string(int i) _const_;
7560fffcd2531786b9c1ca657667a43e90331326Lennart Poetteringint signal_from_string(const char *s) _pure_;
7560fffcd2531786b9c1ca657667a43e90331326Lennart Poetteringint signal_from_string_try_harder(const char *s);
4927fcae48de061393b3ce9c12d49f80d73fbf1dLennart Poetteringchar *format_bytes(char *buf, size_t l, off_t t);
4927fcae48de061393b3ce9c12d49f80d73fbf1dLennart Poetteringint fd_wait_for_event(int fd, int event, usec_t timeout);
4927fcae48de061393b3ce9c12d49f80d73fbf1dLennart Poetteringvoid* memdup(const void *p, size_t l) _alloc_(2);
4927fcae48de061393b3ce9c12d49f80d73fbf1dLennart Poetteringint fork_agent(pid_t *pid, const int except[], unsigned n_except, const char *path, ...);
4927fcae48de061393b3ce9c12d49f80d73fbf1dLennart Poetteringint setrlimit_closest(int resource, const struct rlimit *rlim);
4927fcae48de061393b3ce9c12d49f80d73fbf1dLennart Poetteringint getenv_for_pid(pid_t pid, const char *field, char **_value);
4927fcae48de061393b3ce9c12d49f80d73fbf1dLennart Poetteringbool http_url_is_valid(const char *url) _pure_;
4927fcae48de061393b3ce9c12d49f80d73fbf1dLennart Poetteringbool documentation_url_is_valid(const char *url) _pure_;
4927fcae48de061393b3ce9c12d49f80d73fbf1dLennart Poetteringbool http_etag_is_valid(const char *etag);
4927fcae48de061393b3ce9c12d49f80d73fbf1dLennart Poetteringstatic inline void freep(void *p) {
7f4e08056de0184b205a20632e62db73d299937eLennart Poetteringstatic inline void close_pairp(int (*p)[2]) {
f6a971bc0bf1252e9614919ccca0d53db5fc53d9Lennart PoetteringDEFINE_TRIVIAL_CLEANUP_FUNC(FILE*, fclose);
f6a971bc0bf1252e9614919ccca0d53db5fc53d9Lennart PoetteringDEFINE_TRIVIAL_CLEANUP_FUNC(FILE*, pclose);
f6a971bc0bf1252e9614919ccca0d53db5fc53d9Lennart PoetteringDEFINE_TRIVIAL_CLEANUP_FUNC(DIR*, closedir);
f6a971bc0bf1252e9614919ccca0d53db5fc53d9Lennart PoetteringDEFINE_TRIVIAL_CLEANUP_FUNC(FILE*, endmntent);
f6a971bc0bf1252e9614919ccca0d53db5fc53d9Lennart Poettering#define _cleanup_globfree_ _cleanup_(globfree)
f6a971bc0bf1252e9614919ccca0d53db5fc53d9Lennart Poettering#define _cleanup_fclose_ _cleanup_(fclosep)
f6a971bc0bf1252e9614919ccca0d53db5fc53d9Lennart Poettering#define _cleanup_pclose_ _cleanup_(pclosep)
7b17a7d72f5ba5ad838b19803534c56a46f3bce9Lennart Poettering#define _cleanup_closedir_ _cleanup_(closedirp)
7b17a7d72f5ba5ad838b19803534c56a46f3bce9Lennart Poettering#define _cleanup_endmntent_ _cleanup_(endmntentp)
7b17a7d72f5ba5ad838b19803534c56a46f3bce9Lennart Poettering#define _cleanup_close_pair_ _cleanup_(close_pairp)
59bb9d9a14889bee001706a32a518fe0a5009048Zbigniew Jędrzejewski-Szmek_malloc_ _alloc_(1, 2) static inline void *malloc_multiply(size_t a, size_t b) {
7b17a7d72f5ba5ad838b19803534c56a46f3bce9Lennart Poettering if (_unlikely_(b != 0 && a > ((size_t) -1) / b))
7b17a7d72f5ba5ad838b19803534c56a46f3bce9Lennart Poettering return malloc(a * b);
7b17a7d72f5ba5ad838b19803534c56a46f3bce9Lennart Poettering_alloc_(2, 3) static inline void *realloc_multiply(void *p, size_t a, size_t b) {
3e2147858f21943d5f4a781c60f33ac22c6096edKay Sievers if (_unlikely_(b != 0 && a > ((size_t) -1) / b))
27669061f40766457db93d5cc3dfe00dce240806Miklos Vajna return realloc(p, a * b);
27669061f40766457db93d5cc3dfe00dce240806Miklos Vajna_alloc_(2, 3) static inline void *memdup_multiply(const void *p, size_t a, size_t b) {
27669061f40766457db93d5cc3dfe00dce240806Miklos Vajna if (_unlikely_(b != 0 && a > ((size_t) -1) / b))
e5e83e8362e946890ac991fc86a2c5869f9befdfLennart Poettering return memdup(p, a * b);
e5e83e8362e946890ac991fc86a2c5869f9befdfLennart Poetteringbool filename_is_valid(const char *p) _pure_;
e5e83e8362e946890ac991fc86a2c5869f9befdfLennart Poetteringbool string_is_safe(const char *p) _pure_;
3e2147858f21943d5f4a781c60f33ac22c6096edKay Sieversbool string_has_cc(const char *p, const char *ok) _pure_;
e5e83e8362e946890ac991fc86a2c5869f9befdfLennart Poettering * Check if a string contains any glob patterns.
e5e83e8362e946890ac991fc86a2c5869f9befdfLennart Poettering_pure_ static inline bool string_is_glob(const char *p) {
83fdc450aa8f79941bec84488ffd5bf8eadab18eAuke Kokvoid *xbsearch_r(const void *key, const void *base, size_t nmemb, size_t size,
83fdc450aa8f79941bec84488ffd5bf8eadab18eAuke Kok int (*compar) (const void *, const void *, void *),
6351163bf3e519cc07adb2732d12450741f5a0d3Umut Tezduyarconst char *draw_special_char(DrawSpecialChar ch);
6351163bf3e519cc07adb2732d12450741f5a0d3Umut Tezduyarchar *strreplace(const char *text, const char *old_string, const char *new_string);
4de856120f252e7aa19c923c10fbf23310d623aaLennart Poetteringchar *strip_tab_ansi(char **p, size_t *l);
4de856120f252e7aa19c923c10fbf23310d623aaLennart Poetteringint search_and_fopen(const char *path, const char *mode, const char *root, const char **search, FILE **_f);
4de856120f252e7aa19c923c10fbf23310d623aaLennart Poetteringint search_and_fopen_nulstr(const char *path, const char *mode, const char *root, const char *search, FILE **_f);
3990f247652c3bd41e4ea074e6302277eb9c7aa3Lennart Poettering for (errno = 0, de = readdir(d);; errno = 0, de = readdir(d)) \
2a018e83ded29c9719b2478a65ee6245c829c0f5Kay Sievers for (errno = 0, de = readdir(d);; errno = 0, de = readdir(d)) \
4c80c73c2b804576b1de27e644c1da4dab2f9026Kay Sievers if (errno > 0) { \
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poetteringstatic inline void *mempset(void *s, int c, size_t n) {
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering return (uint8_t*)s + n;
be31376e6c9add0786f31a38eec2ecfdb73eb115Kay Sieverschar *strrep(const char *s, unsigned n);
b2e9fb99ab288e8817302851743ed1a3cddd384bMiklos Vajnavoid* greedy_realloc(void **p, size_t *allocated, size_t need, size_t size);
b2e9fb99ab288e8817302851743ed1a3cddd384bMiklos Vajnavoid* greedy_realloc0(void **p, size_t *allocated, size_t need, size_t size);
f47cd184c0ff80e025428e9e385e61bda1ef3d69Miklos Vajna greedy_realloc((void**) &(array), &(allocated), (need), sizeof((array)[0]))
f47cd184c0ff80e025428e9e385e61bda1ef3d69Miklos Vajna#define GREEDY_REALLOC0(array, allocated, need) \
be31376e6c9add0786f31a38eec2ecfdb73eb115Kay Sievers greedy_realloc0((void**) &(array), &(allocated), (need), sizeof((array)[0]))
f47cd184c0ff80e025428e9e385e61bda1ef3d69Miklos Vajnastatic inline void _reset_errno_(int *saved_errno) {
4cd1eaa54507a65286413363216ad407fa7c6e50Miklos Vajna#define PROTECT_ERRNO _cleanup_(_reset_errno_) __attribute__((unused)) int _saved_errno_ = errno
be31376e6c9add0786f31a38eec2ecfdb73eb115Kay Sieversstatic inline int negative_errno(void) {
4cd1eaa54507a65286413363216ad407fa7c6e50Miklos Vajna /* This helper should be used to shut up gcc if you know 'errno' is
4cd1eaa54507a65286413363216ad407fa7c6e50Miklos Vajna * negative. Instead of "return -errno;", use "return negative_errno();"
4cd1eaa54507a65286413363216ad407fa7c6e50Miklos Vajna * It will suppress bogus gcc warnings in case it assumes 'errno' might
3e2147858f21943d5f4a781c60f33ac22c6096edKay Sievers * be 0 and thus the caller's error-handling might not be triggered. */
46ba8aae2b82bc5c87ba347e6bf914ecd5e9d51eLennart Poetteringstatic inline void _reset_umask_(struct _umask_struct_ *s) {
46ba8aae2b82bc5c87ba347e6bf914ecd5e9d51eLennart Poettering for (_cleanup_(_reset_umask_) struct _umask_struct_ _saved_umask_ = { umask(mask), false }; \
3c9317d2d93248f3f0b0feaaa113485aee415d8aColin Walters return (n > 1) ? (unsigned) __builtin_clzll(n) ^ 63U : 0;
b872e9a05939bc3e0ac95a042592506a7488dd6fLennart Poetteringstatic inline unsigned u32ctz(uint32_t n) {
bd441fa27a22b7c6e11d9330560e0622fb69f297Zbigniew Jędrzejewski-Szmekstatic inline unsigned log2i(int x) {
bd441fa27a22b7c6e11d9330560e0622fb69f297Zbigniew Jędrzejewski-Szmek return __SIZEOF_INT__ * 8 - __builtin_clz(x) - 1;
bd441fa27a22b7c6e11d9330560e0622fb69f297Zbigniew Jędrzejewski-Szmekstatic inline unsigned log2u(unsigned x) {
c97a6dbcf10990bcc2455e842a41bf14b01f358dLukasz Skalski return sizeof(unsigned) * 8 - __builtin_clz(x) - 1;
626851be97b4332fc0401d754c81ae7bbc0f5dc4Lennart Poetteringstatic inline unsigned log2u_round_up(unsigned x) {
b1c4ca25bf58e1925012d1dcdd83d61cecbf87fbLennart Poetteringstatic inline bool logind_running(void) {
b1c4ca25bf58e1925012d1dcdd83d61cecbf87fbLennart Poettering return access("/run/systemd/seats/", F_OK) >= 0;
a382332eed10d3348231803c47a4c599d24c5e3aLennart Poettering/* It's not clear what alignment glibc/gcc alloca() guarantee, hence provide a guaranteed safe version */
a382332eed10d3348231803c47a4c599d24c5e3aLennart Poettering (void*)(((uintptr_t)_ptr_ + _mask_) & ~_mask_); \
4ad61fd1806dde23d2c99043b4bed91a196d2c82Cristian Rodríguez#define strjoina(a, ...) \
4ad61fd1806dde23d2c99043b4bed91a196d2c82Cristian Rodríguez const char *_appendees_[] = { a, __VA_ARGS__ }; \
d562955eac58d3a5089e0f344ea586412a134451Tom Gundersen for (_i_ = 0; _i_ < ELEMENTSOF(_appendees_) && _appendees_[_i_]; _i_++) \
d562955eac58d3a5089e0f344ea586412a134451Tom Gundersen for (_i_ = 0; _i_ < ELEMENTSOF(_appendees_) && _appendees_[_i_]; _i_++) \
d562955eac58d3a5089e0f344ea586412a134451Tom Gundersen const char *_r_; \
d562955eac58d3a5089e0f344ea586412a134451Tom Gundersen if (_pid_ == 0) { \
d562955eac58d3a5089e0f344ea586412a134451Tom Gundersen _r_ = alloca(strlen("/proc/") + DECIMAL_STR_MAX(pid_t) + 1 + sizeof(field)); \
d562955eac58d3a5089e0f344ea586412a134451Tom Gundersen sprintf((char*) _r_, "/proc/"PID_FMT"/" field, _pid_); \
3e2147858f21943d5f4a781c60f33ac22c6096edKay Sieversint split_pair(const char *s, const char *sep, char **l, char **r);
3e2147858f21943d5f4a781c60f33ac22c6096edKay Sievers * Normal qsort requires base to be nonnull. Here were require
3e2147858f21943d5f4a781c60f33ac22c6096edKay Sievers * that only if nmemb > 0.
3e2147858f21943d5f4a781c60f33ac22c6096edKay Sieversstatic inline void qsort_safe(void *base, size_t nmemb, size_t size,
3e2147858f21943d5f4a781c60f33ac22c6096edKay Sievers int (*compar)(const void *, const void *)) {
3e2147858f21943d5f4a781c60f33ac22c6096edKay Sieversint parse_proc_cmdline(int (*parse_word)(const char *key, const char *value));
de1c301ed165eb4d04a0c9d4babe97912b5233bbLennart Poetteringint get_proc_cmdline_key(const char *parameter, char **value);
de1c301ed165eb4d04a0c9d4babe97912b5233bbLennart Poetteringint container_get_leader(const char *machine, pid_t *pid);
3e2147858f21943d5f4a781c60f33ac22c6096edKay Sieversint namespace_open(pid_t pid, int *pidns_fd, int *mntns_fd, int *netns_fd, int *root_fd);
75db9a77605b33a1b9355eae957f26380441fce6Lennart Poetteringint namespace_enter(int pidns_fd, int mntns_fd, int netns_fd, int root_fd);
34eff652cedec3cac34b92629ead5f140334b689Lennart Poetteringint writev_safe(int fd, const struct iovec *w, int j);
12e84679cc81cdf5f042540e54131a0ce37147adLennart Poetteringint mkostemp_safe(char *pattern, int flags);
136337ff74f05be3d42a769d9f0cb99716c5c40fTollef Fog Heenint open_tmpfile(const char *path, int flags);
bc2708414babc5c99bb8000e63c84e87606cc15dLennart Poetteringint fd_warn_permissions(const char *path, int fd);
be31376e6c9add0786f31a38eec2ecfdb73eb115Kay Sieversunsigned long personality_from_string(const char *p);
136337ff74f05be3d42a769d9f0cb99716c5c40fTollef Fog Heenconst char *personality_to_string(unsigned long);
136337ff74f05be3d42a769d9f0cb99716c5c40fTollef Fog Heenvoid hexdump(FILE *f, const void *p, size_t s);
07459bb6b92268beb2599f65cf195708d88c51ccFabiano Fidêncio char padding[sizeof(struct file_handle) + MAX_HANDLE_SZ];
f975e971accc4d50c73ae53167db3df7a7099cf2Lennart Poettering#define FILE_HANDLE_INIT { .handle.handle_bytes = MAX_HANDLE_SZ }
dee4c244254bb49d1ffa8bd7171ae9cce596d2d0Lennart Poetteringint update_reboot_param_file(const char *param);
07459bb6b92268beb2599f65cf195708d88c51ccFabiano Fidêncioint umount_recursive(const char *target, int flags);
07459bb6b92268beb2599f65cf195708d88c51ccFabiano Fidêncioint bind_remount_recursive(const char *prefix, bool ro);
bc2708414babc5c99bb8000e63c84e87606cc15dLennart Poetteringint tempfn_xxxxxx(const char *p, char **ret);
bc2708414babc5c99bb8000e63c84e87606cc15dLennart Poetteringint tempfn_random(const char *p, char **ret);
bc2708414babc5c99bb8000e63c84e87606cc15dLennart Poetteringint tempfn_random_child(const char *p, char **ret);
d2d12cd1bfd90f3a13273d82331a7cbd36a93231Lennart Poetteringint is_dir(const char *path, bool follow);
d2d12cd1bfd90f3a13273d82331a7cbd36a93231Lennart Poetteringint unquote_first_word(const char **p, char **ret, bool relax);
25ee45f9953c121fc26a54a85ad7bb3a3180152bMichael Bieblint unquote_many_words(const char **p, ...) _sentinel_;
d2d12cd1bfd90f3a13273d82331a7cbd36a93231Lennart Poetteringint free_and_strdup(char **p, const char *s);
d2d12cd1bfd90f3a13273d82331a7cbd36a93231Lennart Poetteringint sethostname_idempotent(const char *s);
d122948d6fbaac4505cf14a08f1237daa89efdd0Lennart Poettering#define INOTIFY_EVENT_MAX (sizeof(struct inotify_event) + NAME_MAX + 1)
d2d12cd1bfd90f3a13273d82331a7cbd36a93231Lennart Poettering#define FOREACH_INOTIFY_EVENT(e, buffer, sz) \
03c149144d374cffd40a17ffb067837e3e220933Michael Biebl (uint8_t*) (e) < (uint8_t*) (buffer.raw) + (sz); \
d122948d6fbaac4505cf14a08f1237daa89efdd0Lennart Poettering (e) = (struct inotify_event*) ((uint8_t*) (e) + sizeof(struct inotify_event) + (e)->len))
db059f1b031a92ed45b62d1036877abd9c128d1bMichael Biebl#define laccess(path, mode) faccessat(AT_FDCWD, (path), (mode), AT_SYMLINK_NOFOLLOW)
db059f1b031a92ed45b62d1036877abd9c128d1bMichael Bieblssize_t fgetxattrat_fake(int dirfd, const char *filename, const char *attribute, void *value, size_t size, int flags);
4f87c47b35cf9c1f58872559ae67a2656712fdd6William Giokasint path_getcrtime(const char *p, usec_t *usec);
4f87c47b35cf9c1f58872559ae67a2656712fdd6William Giokasint fd_getcrtime_at(int dirfd, const char *name, usec_t *usec, int flags);
b8079ae19b41c9b61850c796dddc601b826850e0Kay Sieversint same_fd(int a, int b);
d2d12cd1bfd90f3a13273d82331a7cbd36a93231Lennart Poetteringint chattr_fd(int fd, bool b, unsigned mask);
ae446765eb0605d2451bb4dd7c336672bcc7ab0cKay Sieversint chattr_path(const char *p, bool b, unsigned mask);
ae446765eb0605d2451bb4dd7c336672bcc7ab0cKay Sieversint read_attr_path(const char *p, unsigned *ret);
9d3203b4765e64300ab8e8d6d3d1b9ed0c514d5eKay Sieverstypedef struct LockFile {
5c390a4ae0d383b2003074ed011d47876c7e630cZbigniew Jędrzejewski-Szmekint make_lock_file(const char *p, int operation, LockFile *ret);
5c390a4ae0d383b2003074ed011d47876c7e630cZbigniew Jędrzejewski-Szmekint make_lock_file_for(const char *p, int operation, LockFile *ret);
5c390a4ae0d383b2003074ed011d47876c7e630cZbigniew Jędrzejewski-Szmekvoid release_lock_file(LockFile *f);
bc9bdbbab45ea2c10fdd8ad7c517b5e4a358bdfbMichał Górny#define _cleanup_release_lock_file_ _cleanup_(release_lock_file)
bc9bdbbab45ea2c10fdd8ad7c517b5e4a358bdfbMichał Górny#define LOCK_FILE_INIT { .fd = -1, .path = NULL }
bc9bdbbab45ea2c10fdd8ad7c517b5e4a358bdfbMichał Górny#define RLIMIT_MAKE_CONST(lim) ((struct rlimit) { lim, lim })
bc9bdbbab45ea2c10fdd8ad7c517b5e4a358bdfbMichał Górnyssize_t sparse_write(int fd, const void *p, size_t sz, size_t run_length);
bc9bdbbab45ea2c10fdd8ad7c517b5e4a358bdfbMichał Górny#define _cleanup_sigkill_wait_ _cleanup_(sigkill_wait)
bc9bdbbab45ea2c10fdd8ad7c517b5e4a358bdfbMichał Górnyint syslog_parse_priority(const char **p, int *priority, bool with_facility);