1 /*-*- Mode: C; c-basic-offset: 8 -*-*/
4 This file is part of systemd.
6 Copyright 2010 Lennart Poettering
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
31 #include <sys/resource.h>
32 #include <linux/sched.h>
33 #include <sys/types.h>
37 #include <sys/ioctl.h>
39 #include <linux/tiocl.h>
42 #include <sys/inotify.h>
46 #include <sys/prctl.h>
47 #include <sys/utsname.h>
49 #include <netinet/ip.h>
60 #include <selinux/selinux.h>
61 #include <selinux/label.h>
63 static struct selabel_handle *label_hnd = NULL;
65 static inline int use_selinux(void) {
66 static int use_selinux_ind = -1;
68 if (use_selinux_ind == -1)
69 use_selinux_ind = (is_selinux_enabled() == 1);
71 return use_selinux_ind;
74 static int label_get_file_label_from_path(
78 security_context_t *fcon) {
80 security_context_t dir_con = NULL;
81 security_class_t sclass;
84 r = getfilecon(path, &dir_con);
87 if ((sclass = string_to_security_class(class)) != 0)
88 r = security_compute_create((security_context_t) label, dir_con, sclass, fcon);
99 int label_init(void) {
104 label_hnd = selabel_open(SELABEL_CTX_FILE, NULL, 0);
106 log_full(security_getenforce() == 1 ? LOG_ERR : LOG_DEBUG, "Failed to initialize SELinux context: %m");
107 r = (security_getenforce() == 1) ? -errno : 0;
115 int label_fix(const char *path) {
119 security_context_t fcon;
121 r = lstat(path, &st);
124 r = selabel_lookup_raw(label_hnd, &fcon, path, st.st_mode);
127 r = setfilecon(path, fcon);
132 log_error("Unable to fix label of %s: %m", path);
133 r = (security_getenforce() == 1) ? -errno : 0;
140 void label_finish(void) {
144 selabel_close(label_hnd);
149 int label_get_socket_label_from_exe(
155 security_context_t mycon = NULL, fcon = NULL;
156 security_class_t sclass;
162 r = getfilecon(exe, &fcon);
166 sclass = string_to_security_class("process");
167 r = security_compute_create(mycon, fcon, sclass, (security_context_t *) label);
169 log_debug("SELinux Socket context for %s will be set to %s", exe, *label);
172 if (r< 0 && security_getenforce() == 1)
182 int label_fifofile_set(const char *label, const char *path) {
186 security_context_t filecon = NULL;
187 if (use_selinux() && label) {
188 if (((r = label_get_file_label_from_path(label, path, "fifo_file", &filecon)) == 0)) {
189 if ((r = setfscreatecon(filecon)) < 0) {
190 log_error("Failed to set SELinux file context (%s) on %s: %m", label, path);
197 if (r < 0 && security_getenforce() == 0)
205 int label_socket_set(const char *label) {
208 if (use_selinux() && setsockcreatecon((security_context_t) label) < 0) {
209 log_error("Failed to set SELinux context (%s) on socket: %m", label);
210 if (security_getenforce() == 1)
218 void label_file_clear(void) {
222 setfscreatecon(NULL);
228 void label_free(const char *label) {
232 freecon((security_context_t) label);
238 void label_socket_clear(void) {
242 setsockcreatecon(NULL);
248 static int label_mkdir(
254 security_context_t fcon = NULL;
257 if (path[0] == '/') {
258 r = selabel_lookup_raw(label_hnd, &fcon, path, mode);
262 char *newpath = NULL;
263 cwd = getcwd(NULL,0);
264 if ((! cwd) || (asprintf(&newpath, "%s/%s",cwd,path) < 0)) {
268 r = selabel_lookup_raw(label_hnd, &fcon, newpath, mode);
274 r = setfscreatecon(fcon);
276 if ((r < 0) && (errno != ENOENT)) {
277 log_error("Failed to set security context %s for %s", fcon, path);
279 if (security_getenforce() == 1)
283 r = mkdir(path, mode);
287 setfscreatecon(NULL);
293 return mkdir(path, mode);
297 bool streq_ptr(const char *a, const char *b) {
299 /* Like streq(), but tries to make sense of NULL pointers */
310 usec_t now(clockid_t clock_id) {
313 assert_se(clock_gettime(clock_id, &ts) == 0);
315 return timespec_load(&ts);
318 dual_timestamp* dual_timestamp_get(dual_timestamp *ts) {
321 ts->realtime = now(CLOCK_REALTIME);
322 ts->monotonic = now(CLOCK_MONOTONIC);
327 usec_t timespec_load(const struct timespec *ts) {
331 (usec_t) ts->tv_sec * USEC_PER_SEC +
332 (usec_t) ts->tv_nsec / NSEC_PER_USEC;
335 struct timespec *timespec_store(struct timespec *ts, usec_t u) {
338 ts->tv_sec = (time_t) (u / USEC_PER_SEC);
339 ts->tv_nsec = (long int) ((u % USEC_PER_SEC) * NSEC_PER_USEC);
344 usec_t timeval_load(const struct timeval *tv) {
348 (usec_t) tv->tv_sec * USEC_PER_SEC +
349 (usec_t) tv->tv_usec;
352 struct timeval *timeval_store(struct timeval *tv, usec_t u) {
355 tv->tv_sec = (time_t) (u / USEC_PER_SEC);
356 tv->tv_usec = (suseconds_t) (u % USEC_PER_SEC);
361 bool endswith(const char *s, const char *postfix) {
368 pl = strlen(postfix);
376 return memcmp(s + sl - pl, postfix, pl) == 0;
379 bool startswith(const char *s, const char *prefix) {
394 return memcmp(s, prefix, pl) == 0;
397 bool startswith_no_case(const char *s, const char *prefix) {
413 for(i = 0; i < pl; ++i) {
414 if (tolower(s[i]) != tolower(prefix[i]))
421 bool first_word(const char *s, const char *word) {
436 if (memcmp(s, word, wl) != 0)
440 strchr(WHITESPACE, s[wl]);
443 int close_nointr(int fd) {
449 if ((r = close(fd)) >= 0)
457 void close_nointr_nofail(int fd) {
458 int saved_errno = errno;
460 /* like close_nointr() but cannot fail, and guarantees errno
463 assert_se(close_nointr(fd) == 0);
468 void close_many(const int fds[], unsigned n_fd) {
471 for (i = 0; i < n_fd; i++)
472 close_nointr_nofail(fds[i]);
475 int parse_boolean(const char *v) {
478 if (streq(v, "1") || v[0] == 'y' || v[0] == 'Y' || v[0] == 't' || v[0] == 'T' || !strcasecmp(v, "on"))
480 else if (streq(v, "0") || v[0] == 'n' || v[0] == 'N' || v[0] == 'f' || v[0] == 'F' || !strcasecmp(v, "off"))
486 int parse_pid(const char *s, pid_t* ret_pid) {
494 if ((r = safe_atolu(s, &ul)) < 0)
499 if ((unsigned long) pid != ul)
509 int safe_atou(const char *s, unsigned *ret_u) {
517 l = strtoul(s, &x, 0);
519 if (!x || *x || errno)
520 return errno ? -errno : -EINVAL;
522 if ((unsigned long) (unsigned) l != l)
525 *ret_u = (unsigned) l;
529 int safe_atoi(const char *s, int *ret_i) {
537 l = strtol(s, &x, 0);
539 if (!x || *x || errno)
540 return errno ? -errno : -EINVAL;
542 if ((long) (int) l != l)
549 int safe_atollu(const char *s, long long unsigned *ret_llu) {
551 unsigned long long l;
557 l = strtoull(s, &x, 0);
559 if (!x || *x || errno)
560 return errno ? -errno : -EINVAL;
566 int safe_atolli(const char *s, long long int *ret_lli) {
574 l = strtoll(s, &x, 0);
576 if (!x || *x || errno)
577 return errno ? -errno : -EINVAL;
583 /* Split a string into words. */
584 char *split(const char *c, size_t *l, const char *separator, char **state) {
587 current = *state ? *state : (char*) c;
589 if (!*current || *c == 0)
592 current += strspn(current, separator);
593 *l = strcspn(current, separator);
596 return (char*) current;
599 /* Split a string into words, but consider strings enclosed in '' and
600 * "" as words even if they include spaces. */
601 char *split_quoted(const char *c, size_t *l, char **state) {
603 bool escaped = false;
605 current = *state ? *state : (char*) c;
607 if (!*current || *c == 0)
610 current += strspn(current, WHITESPACE);
612 if (*current == '\'') {
615 for (e = current; *e; e++) {
625 *state = *e == 0 ? e : e+1;
626 } else if (*current == '\"') {
629 for (e = current; *e; e++) {
639 *state = *e == 0 ? e : e+1;
641 for (e = current; *e; e++) {
646 else if (strchr(WHITESPACE, *e))
653 return (char*) current;
656 char **split_path_and_make_absolute(const char *p) {
660 if (!(l = strv_split(p, ":")))
663 if (!strv_path_make_absolute_cwd(l)) {
671 int get_parent_of_pid(pid_t pid, pid_t *_ppid) {
674 char fn[132], line[256], *p;
680 assert_se(snprintf(fn, sizeof(fn)-1, "/proc/%lu/stat", (unsigned long) pid) < (int) (sizeof(fn)-1));
681 fn[sizeof(fn)-1] = 0;
683 if (!(f = fopen(fn, "r")))
686 if (!(fgets(line, sizeof(line), f))) {
694 /* Let's skip the pid and comm fields. The latter is enclosed
695 * in () but does not escape any () in its value, so let's
696 * skip over it manually */
698 if (!(p = strrchr(line, ')')))
709 if ((long unsigned) (pid_t) ppid != ppid)
712 *_ppid = (pid_t) ppid;
717 int write_one_line_file(const char *fn, const char *line) {
724 if (!(f = fopen(fn, "we")))
727 if (fputs(line, f) < 0) {
738 int read_one_line_file(const char *fn, char **line) {
746 if (!(f = fopen(fn, "re")))
749 if (!(fgets(t, sizeof(t), f))) {
754 if (!(c = strdup(t))) {
767 char *truncate_nl(char *s) {
770 s[strcspn(s, NEWLINE)] = 0;
774 int get_process_name(pid_t pid, char **name) {
781 if (asprintf(&p, "/proc/%lu/comm", (unsigned long) pid) < 0)
784 r = read_one_line_file(p, name);
794 int get_process_cmdline(pid_t pid, size_t max_length, char **line) {
802 assert(max_length > 0);
805 if (asprintf(&p, "/proc/%lu/cmdline", (unsigned long) pid) < 0)
814 if (!(r = new(char, max_length))) {
821 while ((c = getc(f)) != EOF) {
843 size_t n = MIN(left-1, 3U);
851 /* Kernel threads have no argv[] */
858 if ((h = get_process_name(pid, &t)) < 0)
861 h = asprintf(&r, "[%s]", t);
872 char *strnappend(const char *s, const char *suffix, size_t b) {
880 return strndup(suffix, b);
890 if (!(r = new(char, a+b+1)))
894 memcpy(r+a, suffix, b);
900 char *strappend(const char *s, const char *suffix) {
901 return strnappend(s, suffix, suffix ? strlen(suffix) : 0);
904 int readlink_malloc(const char *p, char **r) {
914 if (!(c = new(char, l)))
917 if ((n = readlink(p, c, l-1)) < 0) {
923 if ((size_t) n < l-1) {
934 int readlink_and_make_absolute(const char *p, char **r) {
941 if ((j = readlink_malloc(p, &target)) < 0)
944 k = file_in_same_dir(p, target);
954 int parent_of_path(const char *path, char **_r) {
955 const char *e, *a = NULL, *b = NULL, *p;
965 for (e = path; *e; e++) {
967 if (!slash && *e == '/') {
971 } else if (slash && *e != '/')
986 r = strndup(path, p-path);
996 char *file_name_from_path(const char *p) {
1001 if ((r = strrchr(p, '/')))
1007 bool path_is_absolute(const char *p) {
1013 bool is_path(const char *p) {
1015 return !!strchr(p, '/');
1018 char *path_make_absolute(const char *p, const char *prefix) {
1023 /* Makes every item in the list an absolute path by prepending
1024 * the prefix, if specified and necessary */
1026 if (path_is_absolute(p) || !prefix)
1029 if (asprintf(&r, "%s/%s", prefix, p) < 0)
1035 char *path_make_absolute_cwd(const char *p) {
1040 /* Similar to path_make_absolute(), but prefixes with the
1041 * current working directory. */
1043 if (path_is_absolute(p))
1046 if (!(cwd = get_current_dir_name()))
1049 r = path_make_absolute(p, cwd);
1055 char **strv_path_make_absolute_cwd(char **l) {
1058 /* Goes through every item in the string list and makes it
1059 * absolute. This works in place and won't rollback any
1060 * changes on failure. */
1062 STRV_FOREACH(s, l) {
1065 if (!(t = path_make_absolute_cwd(*s)))
1075 char **strv_path_canonicalize(char **l) {
1078 bool enomem = false;
1080 if (strv_isempty(l))
1083 /* Goes through every item in the string list and canonicalize
1084 * the path. This works in place and won't rollback any
1085 * changes on failure. */
1087 STRV_FOREACH(s, l) {
1090 t = path_make_absolute_cwd(*s);
1099 u = canonicalize_file_name(t);
1103 if (errno == ENOMEM || !errno)
1120 int reset_all_signal_handlers(void) {
1123 for (sig = 1; sig < _NSIG; sig++) {
1124 struct sigaction sa;
1126 if (sig == SIGKILL || sig == SIGSTOP)
1130 sa.sa_handler = SIG_DFL;
1131 sa.sa_flags = SA_RESTART;
1133 /* On Linux the first two RT signals are reserved by
1134 * glibc, and sigaction() will return EINVAL for them. */
1135 if ((sigaction(sig, &sa, NULL) < 0))
1136 if (errno != EINVAL)
1143 char *strstrip(char *s) {
1146 /* Drops trailing whitespace. Modifies the string in
1147 * place. Returns pointer to first non-space character */
1149 s += strspn(s, WHITESPACE);
1151 for (e = s; *e; e++)
1152 if (!strchr(WHITESPACE, *e))
1163 char *delete_chars(char *s, const char *bad) {
1166 /* Drops all whitespace, regardless where in the string */
1168 for (f = s, t = s; *f; f++) {
1169 if (strchr(bad, *f))
1180 char *file_in_same_dir(const char *path, const char *filename) {
1187 /* This removes the last component of path and appends
1188 * filename, unless the latter is absolute anyway or the
1191 if (path_is_absolute(filename))
1192 return strdup(filename);
1194 if (!(e = strrchr(path, '/')))
1195 return strdup(filename);
1197 k = strlen(filename);
1198 if (!(r = new(char, e-path+1+k+1)))
1201 memcpy(r, path, e-path+1);
1202 memcpy(r+(e-path)+1, filename, k+1);
1207 int safe_mkdir(const char *path, mode_t mode, uid_t uid, gid_t gid) {
1210 if (label_mkdir(path, mode) >= 0)
1211 if (chmod_and_chown(path, mode, uid, gid) < 0)
1214 if (lstat(path, &st) < 0)
1217 if ((st.st_mode & 0777) != mode ||
1220 !S_ISDIR(st.st_mode)) {
1229 int mkdir_parents(const char *path, mode_t mode) {
1234 /* Creates every parent directory in the path except the last
1237 p = path + strspn(path, "/");
1242 e = p + strcspn(p, "/");
1243 p = e + strspn(e, "/");
1245 /* Is this the last component? If so, then we're
1250 if (!(t = strndup(path, e - path)))
1253 r = label_mkdir(t, mode);
1256 if (r < 0 && errno != EEXIST)
1261 int mkdir_p(const char *path, mode_t mode) {
1266 if ((r = mkdir_parents(path, mode)) < 0)
1269 if (label_mkdir(path, mode) < 0 && errno != EEXIST)
1275 int rmdir_parents(const char *path, const char *stop) {
1284 /* Skip trailing slashes */
1285 while (l > 0 && path[l-1] == '/')
1291 /* Skip last component */
1292 while (l > 0 && path[l-1] != '/')
1295 /* Skip trailing slashes */
1296 while (l > 0 && path[l-1] == '/')
1302 if (!(t = strndup(path, l)))
1305 if (path_startswith(stop, t)) {
1314 if (errno != ENOENT)
1322 char hexchar(int x) {
1323 static const char table[16] = "0123456789abcdef";
1325 return table[x & 15];
1328 int unhexchar(char c) {
1330 if (c >= '0' && c <= '9')
1333 if (c >= 'a' && c <= 'f')
1334 return c - 'a' + 10;
1336 if (c >= 'A' && c <= 'F')
1337 return c - 'A' + 10;
1342 char octchar(int x) {
1343 return '0' + (x & 7);
1346 int unoctchar(char c) {
1348 if (c >= '0' && c <= '7')
1354 char decchar(int x) {
1355 return '0' + (x % 10);
1358 int undecchar(char c) {
1360 if (c >= '0' && c <= '9')
1366 char *cescape(const char *s) {
1372 /* Does C style string escaping. */
1374 if (!(r = new(char, strlen(s)*4 + 1)))
1377 for (f = s, t = r; *f; f++)
1423 /* For special chars we prefer octal over
1424 * hexadecimal encoding, simply because glib's
1425 * g_strescape() does the same */
1426 if ((*f < ' ') || (*f >= 127)) {
1428 *(t++) = octchar((unsigned char) *f >> 6);
1429 *(t++) = octchar((unsigned char) *f >> 3);
1430 *(t++) = octchar((unsigned char) *f);
1441 char *cunescape_length(const char *s, size_t length) {
1447 /* Undoes C style string escaping */
1449 if (!(r = new(char, length+1)))
1452 for (f = s, t = r; f < s + length; f++) {
1495 /* This is an extension of the XDG syntax files */
1500 /* hexadecimal encoding */
1503 if ((a = unhexchar(f[1])) < 0 ||
1504 (b = unhexchar(f[2])) < 0) {
1505 /* Invalid escape code, let's take it literal then */
1509 *(t++) = (char) ((a << 4) | b);
1524 /* octal encoding */
1527 if ((a = unoctchar(f[0])) < 0 ||
1528 (b = unoctchar(f[1])) < 0 ||
1529 (c = unoctchar(f[2])) < 0) {
1530 /* Invalid escape code, let's take it literal then */
1534 *(t++) = (char) ((a << 6) | (b << 3) | c);
1542 /* premature end of string.*/
1547 /* Invalid escape code, let's take it literal then */
1559 char *cunescape(const char *s) {
1560 return cunescape_length(s, strlen(s));
1563 char *xescape(const char *s, const char *bad) {
1567 /* Escapes all chars in bad, in addition to \ and all special
1568 * chars, in \xFF style escaping. May be reversed with
1571 if (!(r = new(char, strlen(s)*4+1)))
1574 for (f = s, t = r; *f; f++) {
1576 if ((*f < ' ') || (*f >= 127) ||
1577 (*f == '\\') || strchr(bad, *f)) {
1580 *(t++) = hexchar(*f >> 4);
1581 *(t++) = hexchar(*f);
1591 char *bus_path_escape(const char *s) {
1597 /* Escapes all chars that D-Bus' object path cannot deal
1598 * with. Can be reverse with bus_path_unescape() */
1600 if (!(r = new(char, strlen(s)*3+1)))
1603 for (f = s, t = r; *f; f++) {
1605 if (!(*f >= 'A' && *f <= 'Z') &&
1606 !(*f >= 'a' && *f <= 'z') &&
1607 !(*f >= '0' && *f <= '9')) {
1609 *(t++) = hexchar(*f >> 4);
1610 *(t++) = hexchar(*f);
1620 char *bus_path_unescape(const char *f) {
1625 if (!(r = strdup(f)))
1628 for (t = r; *f; f++) {
1633 if ((a = unhexchar(f[1])) < 0 ||
1634 (b = unhexchar(f[2])) < 0) {
1635 /* Invalid escape code, let's take it literal then */
1638 *(t++) = (char) ((a << 4) | b);
1650 char *path_kill_slashes(char *path) {
1654 /* Removes redundant inner and trailing slashes. Modifies the
1655 * passed string in-place.
1657 * ///foo///bar/ becomes /foo/bar
1660 for (f = path, t = path; *f; f++) {
1675 /* Special rule, if we are talking of the root directory, a
1676 trailing slash is good */
1678 if (t == path && slash)
1685 bool path_startswith(const char *path, const char *prefix) {
1689 if ((path[0] == '/') != (prefix[0] == '/'))
1695 path += strspn(path, "/");
1696 prefix += strspn(prefix, "/");
1704 a = strcspn(path, "/");
1705 b = strcspn(prefix, "/");
1710 if (memcmp(path, prefix, a) != 0)
1718 bool path_equal(const char *a, const char *b) {
1722 if ((a[0] == '/') != (b[0] == '/'))
1728 a += strspn(a, "/");
1729 b += strspn(b, "/");
1731 if (*a == 0 && *b == 0)
1734 if (*a == 0 || *b == 0)
1737 j = strcspn(a, "/");
1738 k = strcspn(b, "/");
1743 if (memcmp(a, b, j) != 0)
1751 char *ascii_strlower(char *t) {
1756 for (p = t; *p; p++)
1757 if (*p >= 'A' && *p <= 'Z')
1758 *p = *p - 'A' + 'a';
1763 bool ignore_file(const char *filename) {
1767 filename[0] == '.' ||
1768 streq(filename, "lost+found") ||
1769 endswith(filename, "~") ||
1770 endswith(filename, ".rpmnew") ||
1771 endswith(filename, ".rpmsave") ||
1772 endswith(filename, ".rpmorig") ||
1773 endswith(filename, ".dpkg-old") ||
1774 endswith(filename, ".dpkg-new") ||
1775 endswith(filename, ".swp");
1778 int fd_nonblock(int fd, bool nonblock) {
1783 if ((flags = fcntl(fd, F_GETFL, 0)) < 0)
1787 flags |= O_NONBLOCK;
1789 flags &= ~O_NONBLOCK;
1791 if (fcntl(fd, F_SETFL, flags) < 0)
1797 int fd_cloexec(int fd, bool cloexec) {
1802 if ((flags = fcntl(fd, F_GETFD, 0)) < 0)
1806 flags |= FD_CLOEXEC;
1808 flags &= ~FD_CLOEXEC;
1810 if (fcntl(fd, F_SETFD, flags) < 0)
1816 int close_all_fds(const int except[], unsigned n_except) {
1821 if (!(d = opendir("/proc/self/fd")))
1824 while ((de = readdir(d))) {
1827 if (ignore_file(de->d_name))
1830 if ((r = safe_atoi(de->d_name, &fd)) < 0)
1844 for (i = 0; i < n_except; i++)
1845 if (except[i] == fd) {
1854 if ((r = close_nointr(fd)) < 0) {
1855 /* Valgrind has its own FD and doesn't want to have it closed */
1868 bool chars_intersect(const char *a, const char *b) {
1871 /* Returns true if any of the chars in a are in b. */
1872 for (p = a; *p; p++)
1879 char *format_timestamp(char *buf, size_t l, usec_t t) {
1889 sec = (time_t) (t / USEC_PER_SEC);
1891 if (strftime(buf, l, "%a, %d %b %Y %H:%M:%S %z", localtime_r(&sec, &tm)) <= 0)
1897 char *format_timespan(char *buf, size_t l, usec_t t) {
1898 static const struct {
1902 { "w", USEC_PER_WEEK },
1903 { "d", USEC_PER_DAY },
1904 { "h", USEC_PER_HOUR },
1905 { "min", USEC_PER_MINUTE },
1906 { "s", USEC_PER_SEC },
1907 { "ms", USEC_PER_MSEC },
1917 if (t == (usec_t) -1)
1920 /* The result of this function can be parsed with parse_usec */
1922 for (i = 0; i < ELEMENTSOF(table); i++) {
1926 if (t < table[i].usec)
1932 k = snprintf(p, l, "%s%llu%s", p > buf ? " " : "", (unsigned long long) (t / table[i].usec), table[i].suffix);
1933 n = MIN((size_t) k, l);
1946 bool fstype_is_network(const char *fstype) {
1947 static const char * const table[] = {
1959 for (i = 0; i < ELEMENTSOF(table); i++)
1960 if (streq(table[i], fstype))
1969 if ((fd = open("/dev/tty0", O_RDWR|O_NOCTTY|O_CLOEXEC)) < 0)
1974 TIOCL_GETKMSGREDIRECT,
1978 if (ioctl(fd, TIOCLINUX, tiocl) < 0)
1981 vt = tiocl[0] <= 0 ? 1 : tiocl[0];
1984 if (ioctl(fd, VT_ACTIVATE, vt) < 0)
1987 close_nointr_nofail(r);
1991 int read_one_char(FILE *f, char *ret, bool *need_nl) {
1992 struct termios old_termios, new_termios;
1999 if (tcgetattr(fileno(f), &old_termios) >= 0) {
2000 new_termios = old_termios;
2002 new_termios.c_lflag &= ~ICANON;
2003 new_termios.c_cc[VMIN] = 1;
2004 new_termios.c_cc[VTIME] = 0;
2006 if (tcsetattr(fileno(f), TCSADRAIN, &new_termios) >= 0) {
2009 k = fread(&c, 1, 1, f);
2011 tcsetattr(fileno(f), TCSADRAIN, &old_termios);
2017 *need_nl = c != '\n';
2024 if (!(fgets(line, sizeof(line), f)))
2029 if (strlen(line) != 1)
2039 int ask(char *ret, const char *replies, const char *text, ...) {
2048 bool need_nl = true;
2050 fputs("\x1B[1m", stdout);
2056 fputs("\x1B[0m", stdout);
2060 if ((r = read_one_char(stdin, &c, &need_nl)) < 0) {
2062 if (r == -EBADMSG) {
2063 puts("Bad input, please try again.");
2074 if (strchr(replies, c)) {
2079 puts("Read unexpected character, please try again.");
2083 int reset_terminal(int fd) {
2084 struct termios termios;
2088 /* Set terminal to some sane defaults */
2092 /* First, unlock termios */
2094 ioctl(fd, TIOCSLCKTRMIOS, &termios);
2096 /* Disable exclusive mode, just in case */
2097 ioctl(fd, TIOCNXCL);
2099 /* Enable console unicode mode */
2101 ioctl(fd, KDSKBMODE, &arg);
2103 if (tcgetattr(fd, &termios) < 0) {
2108 /* We only reset the stuff that matters to the software. How
2109 * hardware is set up we don't touch assuming that somebody
2110 * else will do that for us */
2112 termios.c_iflag &= ~(IGNBRK | BRKINT | ISTRIP | INLCR | IGNCR | IUCLC);
2113 termios.c_iflag |= ICRNL | IMAXBEL | IUTF8;
2114 termios.c_oflag |= ONLCR;
2115 termios.c_cflag |= CREAD;
2116 termios.c_lflag = ISIG | ICANON | IEXTEN | ECHO | ECHOE | ECHOK | ECHOCTL | ECHOPRT | ECHOKE;
2118 termios.c_cc[VINTR] = 03; /* ^C */
2119 termios.c_cc[VQUIT] = 034; /* ^\ */
2120 termios.c_cc[VERASE] = 0177;
2121 termios.c_cc[VKILL] = 025; /* ^X */
2122 termios.c_cc[VEOF] = 04; /* ^D */
2123 termios.c_cc[VSTART] = 021; /* ^Q */
2124 termios.c_cc[VSTOP] = 023; /* ^S */
2125 termios.c_cc[VSUSP] = 032; /* ^Z */
2126 termios.c_cc[VLNEXT] = 026; /* ^V */
2127 termios.c_cc[VWERASE] = 027; /* ^W */
2128 termios.c_cc[VREPRINT] = 022; /* ^R */
2129 termios.c_cc[VEOL] = 0;
2130 termios.c_cc[VEOL2] = 0;
2132 termios.c_cc[VTIME] = 0;
2133 termios.c_cc[VMIN] = 1;
2135 if (tcsetattr(fd, TCSANOW, &termios) < 0)
2139 /* Just in case, flush all crap out */
2140 tcflush(fd, TCIOFLUSH);
2145 int open_terminal(const char *name, int mode) {
2148 if ((fd = open(name, mode)) < 0)
2151 if ((r = isatty(fd)) < 0) {
2152 close_nointr_nofail(fd);
2157 close_nointr_nofail(fd);
2164 int flush_fd(int fd) {
2165 struct pollfd pollfd;
2169 pollfd.events = POLLIN;
2176 if ((r = poll(&pollfd, 1, 0)) < 0) {
2187 if ((l = read(fd, buf, sizeof(buf))) < 0) {
2192 if (errno == EAGAIN)
2203 int acquire_terminal(const char *name, bool fail, bool force, bool ignore_tiocstty_eperm) {
2204 int fd = -1, notify = -1, r, wd = -1;
2208 /* We use inotify to be notified when the tty is closed. We
2209 * create the watch before checking if we can actually acquire
2210 * it, so that we don't lose any event.
2212 * Note: strictly speaking this actually watches for the
2213 * device being closed, it does *not* really watch whether a
2214 * tty loses its controlling process. However, unless some
2215 * rogue process uses TIOCNOTTY on /dev/tty *after* closing
2216 * its tty otherwise this will not become a problem. As long
2217 * as the administrator makes sure not configure any service
2218 * on the same tty as an untrusted user this should not be a
2219 * problem. (Which he probably should not do anyway.) */
2221 if (!fail && !force) {
2222 if ((notify = inotify_init1(IN_CLOEXEC)) < 0) {
2227 if ((wd = inotify_add_watch(notify, name, IN_CLOSE)) < 0) {
2235 if ((r = flush_fd(notify)) < 0)
2238 /* We pass here O_NOCTTY only so that we can check the return
2239 * value TIOCSCTTY and have a reliable way to figure out if we
2240 * successfully became the controlling process of the tty */
2241 if ((fd = open_terminal(name, O_RDWR|O_NOCTTY)) < 0)
2244 /* First, try to get the tty */
2245 r = ioctl(fd, TIOCSCTTY, force);
2247 /* Sometimes it makes sense to ignore TIOCSCTTY
2248 * returning EPERM, i.e. when very likely we already
2249 * are have this controlling terminal. */
2250 if (r < 0 && errno == EPERM && ignore_tiocstty_eperm)
2253 if (r < 0 && (force || fail || errno != EPERM)) {
2263 assert(notify >= 0);
2266 struct inotify_event e;
2269 if ((l = read(notify, &e, sizeof(e))) != sizeof(e)) {
2283 if (e.wd != wd || !(e.mask & IN_CLOSE)) {
2291 /* We close the tty fd here since if the old session
2292 * ended our handle will be dead. It's important that
2293 * we do this after sleeping, so that we don't enter
2294 * an endless loop. */
2295 close_nointr_nofail(fd);
2299 close_nointr_nofail(notify);
2301 if ((r = reset_terminal(fd)) < 0)
2302 log_warning("Failed to reset terminal: %s", strerror(-r));
2308 close_nointr_nofail(fd);
2311 close_nointr_nofail(notify);
2316 int release_terminal(void) {
2318 struct sigaction sa_old, sa_new;
2320 if ((fd = open("/dev/tty", O_RDWR|O_NOCTTY|O_NDELAY)) < 0)
2323 /* Temporarily ignore SIGHUP, so that we don't get SIGHUP'ed
2324 * by our own TIOCNOTTY */
2327 sa_new.sa_handler = SIG_IGN;
2328 sa_new.sa_flags = SA_RESTART;
2329 assert_se(sigaction(SIGHUP, &sa_new, &sa_old) == 0);
2331 if (ioctl(fd, TIOCNOTTY) < 0)
2334 assert_se(sigaction(SIGHUP, &sa_old, NULL) == 0);
2336 close_nointr_nofail(fd);
2340 int sigaction_many(const struct sigaction *sa, ...) {
2345 while ((sig = va_arg(ap, int)) > 0)
2346 if (sigaction(sig, sa, NULL) < 0)
2353 int ignore_signals(int sig, ...) {
2354 struct sigaction sa;
2359 sa.sa_handler = SIG_IGN;
2360 sa.sa_flags = SA_RESTART;
2362 if (sigaction(sig, &sa, NULL) < 0)
2366 while ((sig = va_arg(ap, int)) > 0)
2367 if (sigaction(sig, &sa, NULL) < 0)
2374 int default_signals(int sig, ...) {
2375 struct sigaction sa;
2380 sa.sa_handler = SIG_DFL;
2381 sa.sa_flags = SA_RESTART;
2383 if (sigaction(sig, &sa, NULL) < 0)
2387 while ((sig = va_arg(ap, int)) > 0)
2388 if (sigaction(sig, &sa, NULL) < 0)
2395 int close_pipe(int p[]) {
2401 a = close_nointr(p[0]);
2406 b = close_nointr(p[1]);
2410 return a < 0 ? a : b;
2413 ssize_t loop_read(int fd, void *buf, size_t nbytes, bool do_poll) {
2422 while (nbytes > 0) {
2425 if ((k = read(fd, p, nbytes)) <= 0) {
2427 if (k < 0 && errno == EINTR)
2430 if (k < 0 && errno == EAGAIN && do_poll) {
2431 struct pollfd pollfd;
2435 pollfd.events = POLLIN;
2437 if (poll(&pollfd, 1, -1) < 0) {
2441 return n > 0 ? n : -errno;
2444 if (pollfd.revents != POLLIN)
2445 return n > 0 ? n : -EIO;
2450 return n > 0 ? n : (k < 0 ? -errno : 0);
2461 ssize_t loop_write(int fd, const void *buf, size_t nbytes, bool do_poll) {
2470 while (nbytes > 0) {
2473 if ((k = write(fd, p, nbytes)) <= 0) {
2475 if (k < 0 && errno == EINTR)
2478 if (k < 0 && errno == EAGAIN && do_poll) {
2479 struct pollfd pollfd;
2483 pollfd.events = POLLOUT;
2485 if (poll(&pollfd, 1, -1) < 0) {
2489 return n > 0 ? n : -errno;
2492 if (pollfd.revents != POLLOUT)
2493 return n > 0 ? n : -EIO;
2498 return n > 0 ? n : (k < 0 ? -errno : 0);
2509 int path_is_mount_point(const char *t) {
2514 if (lstat(t, &a) < 0) {
2515 if (errno == ENOENT)
2521 if ((r = parent_of_path(t, &parent)) < 0)
2524 r = lstat(parent, &b);
2530 return a.st_dev != b.st_dev;
2533 int parse_usec(const char *t, usec_t *usec) {
2534 static const struct {
2538 { "sec", USEC_PER_SEC },
2539 { "s", USEC_PER_SEC },
2540 { "min", USEC_PER_MINUTE },
2541 { "hr", USEC_PER_HOUR },
2542 { "h", USEC_PER_HOUR },
2543 { "d", USEC_PER_DAY },
2544 { "w", USEC_PER_WEEK },
2545 { "msec", USEC_PER_MSEC },
2546 { "ms", USEC_PER_MSEC },
2547 { "m", USEC_PER_MINUTE },
2550 { "", USEC_PER_SEC },
2566 l = strtoll(p, &e, 10);
2577 e += strspn(e, WHITESPACE);
2579 for (i = 0; i < ELEMENTSOF(table); i++)
2580 if (startswith(e, table[i].suffix)) {
2581 r += (usec_t) l * table[i].usec;
2582 p = e + strlen(table[i].suffix);
2586 if (i >= ELEMENTSOF(table))
2596 int make_stdio(int fd) {
2601 r = dup2(fd, STDIN_FILENO);
2602 s = dup2(fd, STDOUT_FILENO);
2603 t = dup2(fd, STDERR_FILENO);
2606 close_nointr_nofail(fd);
2608 if (r < 0 || s < 0 || t < 0)
2614 bool is_clean_exit(int code, int status) {
2616 if (code == CLD_EXITED)
2619 /* If a daemon does not implement handlers for some of the
2620 * signals that's not considered an unclean shutdown */
2621 if (code == CLD_KILLED)
2625 status == SIGTERM ||
2631 bool is_device_path(const char *path) {
2633 /* Returns true on paths that refer to a device, either in
2634 * sysfs or in /dev */
2637 path_startswith(path, "/dev/") ||
2638 path_startswith(path, "/sys/");
2641 int dir_is_empty(const char *path) {
2644 struct dirent buf, *de;
2646 if (!(d = opendir(path)))
2650 if ((r = readdir_r(d, &buf, &de)) > 0) {
2660 if (!ignore_file(de->d_name)) {
2670 unsigned long long random_ull(void) {
2675 if ((fd = open("/dev/urandom", O_RDONLY|O_CLOEXEC|O_NOCTTY)) < 0)
2678 r = loop_read(fd, &ull, sizeof(ull), true);
2679 close_nointr_nofail(fd);
2681 if (r != sizeof(ull))
2687 return random() * RAND_MAX + random();
2690 void rename_process(const char name[8]) {
2693 prctl(PR_SET_NAME, name);
2695 /* This is a like a poor man's setproctitle(). The string
2696 * passed should fit in 7 chars (i.e. the length of
2699 if (program_invocation_name)
2700 strncpy(program_invocation_name, name, strlen(program_invocation_name));
2703 void sigset_add_many(sigset_t *ss, ...) {
2710 while ((sig = va_arg(ap, int)) > 0)
2711 assert_se(sigaddset(ss, sig) == 0);
2715 char* gethostname_malloc(void) {
2718 assert_se(uname(&u) >= 0);
2721 return strdup(u.nodename);
2723 return strdup(u.sysname);
2726 int getmachineid_malloc(char **b) {
2731 if ((r = read_one_line_file("/var/lib/dbus/machine-id", b)) < 0)
2738 char* getlogname_malloc(void) {
2742 struct passwd pwbuf, *pw = NULL;
2745 if (isatty(STDIN_FILENO) && fstat(STDIN_FILENO, &st) >= 0)
2750 /* Shortcut things to avoid NSS lookups */
2752 return strdup("root");
2754 if ((bufsize = sysconf(_SC_GETPW_R_SIZE_MAX)) <= 0)
2757 if (!(buf = malloc(bufsize)))
2760 if (getpwuid_r(uid, &pwbuf, buf, bufsize, &pw) == 0 && pw) {
2761 name = strdup(pw->pw_name);
2768 if (asprintf(&name, "%lu", (unsigned long) uid) < 0)
2774 int getttyname_malloc(char **r) {
2775 char path[PATH_MAX], *p, *c;
2779 if (ttyname_r(STDIN_FILENO, path, sizeof(path)) < 0)
2785 if (startswith(path, "/dev/"))
2788 if (!(c = strdup(p)))
2795 static int rm_rf_children(int fd, bool only_dirs) {
2801 /* This returns the first error we run into, but nevertheless
2804 if (!(d = fdopendir(fd))) {
2805 close_nointr_nofail(fd);
2807 return errno == ENOENT ? 0 : -errno;
2811 struct dirent buf, *de;
2815 if ((r = readdir_r(d, &buf, &de)) != 0) {
2824 if (streq(de->d_name, ".") || streq(de->d_name, ".."))
2827 if (de->d_type == DT_UNKNOWN) {
2830 if (fstatat(fd, de->d_name, &st, AT_SYMLINK_NOFOLLOW) < 0) {
2831 if (ret == 0 && errno != ENOENT)
2836 is_dir = S_ISDIR(st.st_mode);
2838 is_dir = de->d_type == DT_DIR;
2843 if ((subdir_fd = openat(fd, de->d_name, O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC)) < 0) {
2844 if (ret == 0 && errno != ENOENT)
2849 if ((r = rm_rf_children(subdir_fd, only_dirs)) < 0) {
2854 if (unlinkat(fd, de->d_name, AT_REMOVEDIR) < 0) {
2855 if (ret == 0 && errno != ENOENT)
2858 } else if (!only_dirs) {
2860 if (unlinkat(fd, de->d_name, 0) < 0) {
2861 if (ret == 0 && errno != ENOENT)
2872 int rm_rf(const char *path, bool only_dirs, bool delete_root) {
2878 if ((fd = open(path, O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC)) < 0) {
2880 if (errno != ENOTDIR)
2883 if (delete_root && !only_dirs)
2884 if (unlink(path) < 0)
2890 r = rm_rf_children(fd, only_dirs);
2893 if (rmdir(path) < 0) {
2901 int chmod_and_chown(const char *path, mode_t mode, uid_t uid, gid_t gid) {
2904 /* Under the assumption that we are running privileged we
2905 * first change the access mode and only then hand out
2906 * ownership to avoid a window where access is too open. */
2908 if (chmod(path, mode) < 0)
2911 if (chown(path, uid, gid) < 0)
2917 cpu_set_t* cpu_set_malloc(unsigned *ncpus) {
2921 /* Allocates the cpuset in the right size */
2924 if (!(r = CPU_ALLOC(n)))
2927 if (sched_getaffinity(0, CPU_ALLOC_SIZE(n), r) >= 0) {
2928 CPU_ZERO_S(CPU_ALLOC_SIZE(n), r);
2938 if (errno != EINVAL)
2945 void status_vprintf(const char *format, va_list ap) {
2951 /* This independent of logging, as status messages are
2952 * optional and go exclusively to the console. */
2954 if (vasprintf(&s, format, ap) < 0)
2957 if ((fd = open_terminal("/dev/console", O_WRONLY|O_NOCTTY|O_CLOEXEC)) < 0)
2960 write(fd, s, strlen(s));
2966 close_nointr_nofail(fd);
2969 void status_printf(const char *format, ...) {
2974 va_start(ap, format);
2975 status_vprintf(format, ap);
2979 void status_welcome(void) {
2981 #if defined(TARGET_FEDORA)
2984 if (read_one_line_file("/etc/system-release", &r) < 0)
2989 /* This tries to mimic the color magic the old Red Hat sysinit
2992 if (startswith(r, "Red Hat"))
2993 status_printf("Welcome to \x1B[0;31m%s\x1B[0m!\n", r); /* Red for RHEL */
2994 else if (startswith(r, "Fedora"))
2995 status_printf("Welcome to \x1B[0;34m%s\x1B[0m!\n", r); /* Blue for Fedora */
2997 status_printf("Welcome to %s!\n", r);
3001 #elif defined(TARGET_SUSE)
3004 if (read_one_line_file("/etc/SuSE-release", &r) < 0)
3009 status_printf("Welcome to \x1B[0;32m%s\x1B[0m!\n", r); /* Green for SUSE */
3012 #warning "You probably should add a welcome text logic here."
3016 char *replace_env(const char *format, char **env) {
3023 const char *e, *word = format;
3028 for (e = format; *e; e ++) {
3039 if (!(k = strnappend(r, word, e-word-1)))
3048 } else if (*e == '$') {
3049 if (!(k = strnappend(r, word, e-word)))
3065 if ((t = strv_env_get_with_length(env, word+2, e-word-2))) {
3066 if (!(k = strappend(r, t)))
3081 if (!(k = strnappend(r, word, e-word)))
3092 char **replace_env_argv(char **argv, char **env) {
3094 unsigned k = 0, l = 0;
3096 l = strv_length(argv);
3098 if (!(r = new(char*, l+1)))
3101 STRV_FOREACH(i, argv) {
3103 /* If $FOO appears as single word, replace it by the split up variable */
3104 if ((*i)[0] == '$') {
3105 char *e = strv_env_get(env, *i+1);
3111 if (!(m = strv_split_quoted(e))) {
3120 if (!(w = realloc(r, sizeof(char*) * (l+1)))) {
3128 memcpy(r + k, m, q * sizeof(char*));
3136 /* If ${FOO} appears as part of a word, replace it by the variable as-is */
3137 if (!(r[k++] = replace_env(*i, env))) {
3148 static __thread int parsed_columns = 0;
3151 if (parsed_columns > 0)
3152 return parsed_columns;
3154 if ((e = getenv("COLUMNS")))
3155 parsed_columns = atoi(e);
3157 if (parsed_columns <= 0) {
3161 if (ioctl(STDIN_FILENO, TIOCGWINSZ, &ws) >= 0)
3162 parsed_columns = ws.ws_col;
3165 if (parsed_columns <= 0)
3166 parsed_columns = 80;
3168 return parsed_columns;
3171 int running_in_chroot(void) {
3177 /* Only works as root */
3179 if (stat("/proc/1/root", &a) < 0)
3182 if (stat("/", &b) < 0)
3186 a.st_dev != b.st_dev ||
3187 a.st_ino != b.st_ino;
3190 char *ellipsize(const char *s, unsigned length, unsigned percent) {
3195 assert(percent <= 100);
3196 assert(length >= 3);
3200 if (l <= 3 || l <= length)
3203 if (!(r = new0(char, length+1)))
3206 x = (length * percent) / 100;
3216 s + l - (length - x - 3),
3222 static const char *const ioprio_class_table[] = {
3223 [IOPRIO_CLASS_NONE] = "none",
3224 [IOPRIO_CLASS_RT] = "realtime",
3225 [IOPRIO_CLASS_BE] = "best-effort",
3226 [IOPRIO_CLASS_IDLE] = "idle"
3229 DEFINE_STRING_TABLE_LOOKUP(ioprio_class, int);
3231 static const char *const sigchld_code_table[] = {
3232 [CLD_EXITED] = "exited",
3233 [CLD_KILLED] = "killed",
3234 [CLD_DUMPED] = "dumped",
3235 [CLD_TRAPPED] = "trapped",
3236 [CLD_STOPPED] = "stopped",
3237 [CLD_CONTINUED] = "continued",
3240 DEFINE_STRING_TABLE_LOOKUP(sigchld_code, int);
3242 static const char *const log_facility_table[LOG_NFACILITIES] = {
3243 [LOG_FAC(LOG_KERN)] = "kern",
3244 [LOG_FAC(LOG_USER)] = "user",
3245 [LOG_FAC(LOG_MAIL)] = "mail",
3246 [LOG_FAC(LOG_DAEMON)] = "daemon",
3247 [LOG_FAC(LOG_AUTH)] = "auth",
3248 [LOG_FAC(LOG_SYSLOG)] = "syslog",
3249 [LOG_FAC(LOG_LPR)] = "lpr",
3250 [LOG_FAC(LOG_NEWS)] = "news",
3251 [LOG_FAC(LOG_UUCP)] = "uucp",
3252 [LOG_FAC(LOG_CRON)] = "cron",
3253 [LOG_FAC(LOG_AUTHPRIV)] = "authpriv",
3254 [LOG_FAC(LOG_FTP)] = "ftp",
3255 [LOG_FAC(LOG_LOCAL0)] = "local0",
3256 [LOG_FAC(LOG_LOCAL1)] = "local1",
3257 [LOG_FAC(LOG_LOCAL2)] = "local2",
3258 [LOG_FAC(LOG_LOCAL3)] = "local3",
3259 [LOG_FAC(LOG_LOCAL4)] = "local4",
3260 [LOG_FAC(LOG_LOCAL5)] = "local5",
3261 [LOG_FAC(LOG_LOCAL6)] = "local6",
3262 [LOG_FAC(LOG_LOCAL7)] = "local7"
3265 DEFINE_STRING_TABLE_LOOKUP(log_facility, int);
3267 static const char *const log_level_table[] = {
3268 [LOG_EMERG] = "emerg",
3269 [LOG_ALERT] = "alert",
3270 [LOG_CRIT] = "crit",
3272 [LOG_WARNING] = "warning",
3273 [LOG_NOTICE] = "notice",
3274 [LOG_INFO] = "info",
3275 [LOG_DEBUG] = "debug"
3278 DEFINE_STRING_TABLE_LOOKUP(log_level, int);
3280 static const char* const sched_policy_table[] = {
3281 [SCHED_OTHER] = "other",
3282 [SCHED_BATCH] = "batch",
3283 [SCHED_IDLE] = "idle",
3284 [SCHED_FIFO] = "fifo",
3288 DEFINE_STRING_TABLE_LOOKUP(sched_policy, int);
3290 static const char* const rlimit_table[] = {
3291 [RLIMIT_CPU] = "LimitCPU",
3292 [RLIMIT_FSIZE] = "LimitFSIZE",
3293 [RLIMIT_DATA] = "LimitDATA",
3294 [RLIMIT_STACK] = "LimitSTACK",
3295 [RLIMIT_CORE] = "LimitCORE",
3296 [RLIMIT_RSS] = "LimitRSS",
3297 [RLIMIT_NOFILE] = "LimitNOFILE",
3298 [RLIMIT_AS] = "LimitAS",
3299 [RLIMIT_NPROC] = "LimitNPROC",
3300 [RLIMIT_MEMLOCK] = "LimitMEMLOCK",
3301 [RLIMIT_LOCKS] = "LimitLOCKS",
3302 [RLIMIT_SIGPENDING] = "LimitSIGPENDING",
3303 [RLIMIT_MSGQUEUE] = "LimitMSGQUEUE",
3304 [RLIMIT_NICE] = "LimitNICE",
3305 [RLIMIT_RTPRIO] = "LimitRTPRIO",
3306 [RLIMIT_RTTIME] = "LimitRTTIME"
3309 DEFINE_STRING_TABLE_LOOKUP(rlimit, int);
3311 static const char* const ip_tos_table[] = {
3312 [IPTOS_LOWDELAY] = "low-delay",
3313 [IPTOS_THROUGHPUT] = "throughput",
3314 [IPTOS_RELIABILITY] = "reliability",
3315 [IPTOS_LOWCOST] = "low-cost",
3318 DEFINE_STRING_TABLE_LOOKUP(ip_tos, int);
3320 static const char *const signal_table[] = {
3336 [SIGSTKFLT] = "STKFLT",
3346 [SIGVTALRM] = "VTALRM",
3348 [SIGWINCH] = "WINCH",
3354 DEFINE_STRING_TABLE_LOOKUP(signal, int);