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>
52 bool streq_ptr(const char *a, const char *b) {
54 /* Like streq(), but tries to make sense of NULL pointers */
65 usec_t now(clockid_t clock_id) {
68 assert_se(clock_gettime(clock_id, &ts) == 0);
70 return timespec_load(&ts);
73 usec_t timespec_load(const struct timespec *ts) {
77 (usec_t) ts->tv_sec * USEC_PER_SEC +
78 (usec_t) ts->tv_nsec / NSEC_PER_USEC;
81 struct timespec *timespec_store(struct timespec *ts, usec_t u) {
84 ts->tv_sec = (time_t) (u / USEC_PER_SEC);
85 ts->tv_nsec = (long int) ((u % USEC_PER_SEC) * NSEC_PER_USEC);
90 usec_t timeval_load(const struct timeval *tv) {
94 (usec_t) tv->tv_sec * USEC_PER_SEC +
98 struct timeval *timeval_store(struct timeval *tv, usec_t u) {
101 tv->tv_sec = (time_t) (u / USEC_PER_SEC);
102 tv->tv_usec = (suseconds_t) (u % USEC_PER_SEC);
107 bool endswith(const char *s, const char *postfix) {
114 pl = strlen(postfix);
119 return memcmp(s + sl - pl, postfix, pl) == 0;
122 bool startswith(const char *s, const char *prefix) {
134 return memcmp(s, prefix, pl) == 0;
137 bool first_word(const char *s, const char *word) {
149 if (memcmp(s, word, wl) != 0)
152 return (s[wl] == 0 ||
153 strchr(WHITESPACE, s[wl]));
156 int close_nointr(int fd) {
162 if ((r = close(fd)) >= 0)
170 void close_nointr_nofail(int fd) {
171 int saved_errno = errno;
173 /* like close_nointr() but cannot fail, and guarantees errno
176 assert_se(close_nointr(fd) == 0);
181 int parse_boolean(const char *v) {
184 if (streq(v, "1") || v[0] == 'y' || v[0] == 'Y' || v[0] == 't' || v[0] == 'T' || !strcasecmp(v, "on"))
186 else if (streq(v, "0") || v[0] == 'n' || v[0] == 'N' || v[0] == 'f' || v[0] == 'F' || !strcasecmp(v, "off"))
192 int safe_atou(const char *s, unsigned *ret_u) {
200 l = strtoul(s, &x, 0);
202 if (!x || *x || errno)
203 return errno ? -errno : -EINVAL;
205 if ((unsigned long) (unsigned) l != l)
208 *ret_u = (unsigned) l;
212 int safe_atoi(const char *s, int *ret_i) {
220 l = strtol(s, &x, 0);
222 if (!x || *x || errno)
223 return errno ? -errno : -EINVAL;
225 if ((long) (int) l != l)
232 int safe_atolu(const char *s, long unsigned *ret_lu) {
240 l = strtoul(s, &x, 0);
242 if (!x || *x || errno)
243 return errno ? -errno : -EINVAL;
249 int safe_atoli(const char *s, long int *ret_li) {
257 l = strtol(s, &x, 0);
259 if (!x || *x || errno)
260 return errno ? -errno : -EINVAL;
266 int safe_atollu(const char *s, long long unsigned *ret_llu) {
268 unsigned long long l;
274 l = strtoull(s, &x, 0);
276 if (!x || *x || errno)
277 return errno ? -errno : -EINVAL;
283 int safe_atolli(const char *s, long long int *ret_lli) {
291 l = strtoll(s, &x, 0);
293 if (!x || *x || errno)
294 return errno ? -errno : -EINVAL;
300 /* Split a string into words. */
301 char *split(const char *c, size_t *l, const char *separator, char **state) {
304 current = *state ? *state : (char*) c;
306 if (!*current || *c == 0)
309 current += strspn(current, separator);
310 *l = strcspn(current, separator);
313 return (char*) current;
316 /* Split a string into words, but consider strings enclosed in '' and
317 * "" as words even if they include spaces. */
318 char *split_quoted(const char *c, size_t *l, char **state) {
321 current = *state ? *state : (char*) c;
323 if (!*current || *c == 0)
326 current += strspn(current, WHITESPACE);
328 if (*current == '\'') {
330 *l = strcspn(current, "'");
335 } else if (*current == '\"') {
337 *l = strcspn(current, "\"");
343 *l = strcspn(current, WHITESPACE);
347 /* FIXME: Cannot deal with strings that have spaces AND ticks
350 return (char*) current;
353 char **split_path_and_make_absolute(const char *p) {
357 if (!(l = strv_split(p, ":")))
360 if (!strv_path_make_absolute_cwd(l)) {
368 int get_parent_of_pid(pid_t pid, pid_t *_ppid) {
371 char fn[132], line[256], *p;
372 long long unsigned ppid;
377 assert_se(snprintf(fn, sizeof(fn)-1, "/proc/%llu/stat", (unsigned long long) pid) < (int) (sizeof(fn)-1));
378 fn[sizeof(fn)-1] = 0;
380 if (!(f = fopen(fn, "r")))
383 if (!(fgets(line, sizeof(line), f))) {
391 /* Let's skip the pid and comm fields. The latter is enclosed
392 * in () but does not escape any () in its value, so let's
393 * skip over it manually */
395 if (!(p = strrchr(line, ')')))
406 if ((long long unsigned) (pid_t) ppid != ppid)
409 *_ppid = (pid_t) ppid;
414 int write_one_line_file(const char *fn, const char *line) {
421 if (!(f = fopen(fn, "we")))
424 if (fputs(line, f) < 0) {
435 int read_one_line_file(const char *fn, char **line) {
443 if (!(f = fopen(fn, "re")))
446 if (!(fgets(t, sizeof(t), f))) {
451 if (!(c = strdup(t))) {
464 char *truncate_nl(char *s) {
467 s[strcspn(s, NEWLINE)] = 0;
471 int get_process_name(pid_t pid, char **name) {
478 if (asprintf(&p, "/proc/%llu/comm", (unsigned long long) pid) < 0)
481 r = read_one_line_file(p, name);
491 char *strappend(const char *s, const char *suffix) {
501 if (!(r = new(char, a+b+1)))
505 memcpy(r+a, suffix, b);
511 int readlink_malloc(const char *p, char **r) {
521 if (!(c = new(char, l)))
524 if ((n = readlink(p, c, l-1)) < 0) {
530 if ((size_t) n < l-1) {
541 char *file_name_from_path(const char *p) {
546 if ((r = strrchr(p, '/')))
552 bool path_is_absolute(const char *p) {
558 bool is_path(const char *p) {
560 return !!strchr(p, '/');
563 char *path_make_absolute(const char *p, const char *prefix) {
568 /* Makes every item in the list an absolute path by prepending
569 * the prefix, if specified and necessary */
571 if (path_is_absolute(p) || !prefix)
574 if (asprintf(&r, "%s/%s", prefix, p) < 0)
580 char *path_make_absolute_cwd(const char *p) {
585 /* Similar to path_make_absolute(), but prefixes with the
586 * current working directory. */
588 if (path_is_absolute(p))
591 if (!(cwd = get_current_dir_name()))
594 r = path_make_absolute(p, cwd);
600 char **strv_path_make_absolute_cwd(char **l) {
603 /* Goes through every item in the string list and makes it
604 * absolute. This works in place and won't rollback any
605 * changes on failure. */
610 if (!(t = path_make_absolute_cwd(*s)))
620 int reset_all_signal_handlers(void) {
623 for (sig = 1; sig < _NSIG; sig++) {
626 if (sig == SIGKILL || sig == SIGSTOP)
630 sa.sa_handler = SIG_DFL;
631 sa.sa_flags = SA_RESTART;
633 /* On Linux the first two RT signals are reserved by
634 * glibc, and sigaction() will return EINVAL for them. */
635 if ((sigaction(sig, &sa, NULL) < 0))
643 char *strstrip(char *s) {
646 /* Drops trailing whitespace. Modifies the string in
647 * place. Returns pointer to first non-space character */
649 s += strspn(s, WHITESPACE);
652 if (!strchr(WHITESPACE, *e))
663 char *delete_chars(char *s, const char *bad) {
666 /* Drops all whitespace, regardless where in the string */
668 for (f = s, t = s; *f; f++) {
680 char *file_in_same_dir(const char *path, const char *filename) {
687 /* This removes the last component of path and appends
688 * filename, unless the latter is absolute anyway or the
691 if (path_is_absolute(filename))
692 return strdup(filename);
694 if (!(e = strrchr(path, '/')))
695 return strdup(filename);
697 k = strlen(filename);
698 if (!(r = new(char, e-path+1+k+1)))
701 memcpy(r, path, e-path+1);
702 memcpy(r+(e-path)+1, filename, k+1);
707 int mkdir_parents(const char *path, mode_t mode) {
712 /* Creates every parent directory in the path except the last
715 p = path + strspn(path, "/");
720 e = p + strcspn(p, "/");
721 p = e + strspn(e, "/");
723 /* Is this the last component? If so, then we're
728 if (!(t = strndup(path, e - path)))
735 if (r < 0 && errno != EEXIST)
740 int mkdir_p(const char *path, mode_t mode) {
745 if ((r = mkdir_parents(path, mode)) < 0)
748 if (mkdir(path, mode) < 0)
754 char hexchar(int x) {
755 static const char table[16] = "0123456789abcdef";
757 return table[x & 15];
760 int unhexchar(char c) {
762 if (c >= '0' && c <= '9')
765 if (c >= 'a' && c <= 'f')
768 if (c >= 'A' && c <= 'F')
774 char octchar(int x) {
775 return '0' + (x & 7);
778 int unoctchar(char c) {
780 if (c >= '0' && c <= '7')
786 char decchar(int x) {
787 return '0' + (x % 10);
790 int undecchar(char c) {
792 if (c >= '0' && c <= '9')
798 char *cescape(const char *s) {
804 /* Does C style string escaping. */
806 if (!(r = new(char, strlen(s)*4 + 1)))
809 for (f = s, t = r; *f; f++)
855 /* For special chars we prefer octal over
856 * hexadecimal encoding, simply because glib's
857 * g_strescape() does the same */
858 if ((*f < ' ') || (*f >= 127)) {
860 *(t++) = octchar((unsigned char) *f >> 6);
861 *(t++) = octchar((unsigned char) *f >> 3);
862 *(t++) = octchar((unsigned char) *f);
873 char *cunescape(const char *s) {
879 /* Undoes C style string escaping */
881 if (!(r = new(char, strlen(s)+1)))
884 for (f = s, t = r; *f; f++) {
927 /* hexadecimal encoding */
930 if ((a = unhexchar(f[1])) < 0 ||
931 (b = unhexchar(f[2])) < 0) {
932 /* Invalid escape code, let's take it literal then */
936 *(t++) = (char) ((a << 4) | b);
954 if ((a = unoctchar(f[0])) < 0 ||
955 (b = unoctchar(f[1])) < 0 ||
956 (c = unoctchar(f[2])) < 0) {
957 /* Invalid escape code, let's take it literal then */
961 *(t++) = (char) ((a << 6) | (b << 3) | c);
969 /* premature end of string.*/
974 /* Invalid escape code, let's take it literal then */
987 char *xescape(const char *s, const char *bad) {
991 /* Escapes all chars in bad, in addition to \ and all special
992 * chars, in \xFF style escaping. May be reversed with
995 if (!(r = new(char, strlen(s)*4+1)))
998 for (f = s, t = r; *f; f++) {
1000 if ((*f < ' ') || (*f >= 127) ||
1001 (*f == '\\') || strchr(bad, *f)) {
1004 *(t++) = hexchar(*f >> 4);
1005 *(t++) = hexchar(*f);
1015 char *bus_path_escape(const char *s) {
1021 /* Escapes all chars that D-Bus' object path cannot deal
1022 * with. Can be reverse with bus_path_unescape() */
1024 if (!(r = new(char, strlen(s)*3+1)))
1027 for (f = s, t = r; *f; f++) {
1029 if (!(*f >= 'A' && *f <= 'Z') &&
1030 !(*f >= 'a' && *f <= 'z') &&
1031 !(*f >= '0' && *f <= '9')) {
1033 *(t++) = hexchar(*f >> 4);
1034 *(t++) = hexchar(*f);
1044 char *bus_path_unescape(const char *s) {
1050 if (!(r = new(char, strlen(s)+1)))
1053 for (f = s, t = r; *f; f++) {
1058 if ((a = unhexchar(f[1])) < 0 ||
1059 (b = unhexchar(f[2])) < 0) {
1060 /* Invalid escape code, let's take it literal then */
1063 *(t++) = (char) ((a << 4) | b);
1075 char *path_kill_slashes(char *path) {
1079 /* Removes redundant inner and trailing slashes. Modifies the
1080 * passed string in-place.
1082 * ///foo///bar/ becomes /foo/bar
1085 for (f = path, t = path; *f; f++) {
1100 /* Special rule, if we are talking of the root directory, a
1101 trailing slash is good */
1103 if (t == path && slash)
1110 bool path_startswith(const char *path, const char *prefix) {
1114 if ((path[0] == '/') != (prefix[0] == '/'))
1120 path += strspn(path, "/");
1121 prefix += strspn(prefix, "/");
1129 a = strcspn(path, "/");
1130 b = strcspn(prefix, "/");
1135 if (memcmp(path, prefix, a) != 0)
1143 char *ascii_strlower(char *t) {
1148 for (p = t; *p; p++)
1149 if (*p >= 'A' && *p <= 'Z')
1150 *p = *p - 'A' + 'a';
1155 bool ignore_file(const char *filename) {
1159 filename[0] == '.' ||
1160 endswith(filename, "~") ||
1161 endswith(filename, ".rpmnew") ||
1162 endswith(filename, ".rpmsave") ||
1163 endswith(filename, ".rpmorig") ||
1164 endswith(filename, ".dpkg-old") ||
1165 endswith(filename, ".dpkg-new") ||
1166 endswith(filename, ".swp");
1169 int fd_nonblock(int fd, bool nonblock) {
1174 if ((flags = fcntl(fd, F_GETFL, 0)) < 0)
1178 flags |= O_NONBLOCK;
1180 flags &= ~O_NONBLOCK;
1182 if (fcntl(fd, F_SETFL, flags) < 0)
1188 int fd_cloexec(int fd, bool cloexec) {
1193 if ((flags = fcntl(fd, F_GETFD, 0)) < 0)
1197 flags |= FD_CLOEXEC;
1199 flags &= ~FD_CLOEXEC;
1201 if (fcntl(fd, F_SETFD, flags) < 0)
1207 int close_all_fds(const int except[], unsigned n_except) {
1212 if (!(d = opendir("/proc/self/fd")))
1215 while ((de = readdir(d))) {
1218 if (de->d_name[0] == '.')
1221 if ((r = safe_atoi(de->d_name, &fd)) < 0)
1235 for (i = 0; i < n_except; i++)
1236 if (except[i] == fd) {
1245 if ((r = close_nointr(fd)) < 0) {
1246 /* Valgrind has its own FD and doesn't want to have it closed */
1259 bool chars_intersect(const char *a, const char *b) {
1262 /* Returns true if any of the chars in a are in b. */
1263 for (p = a; *p; p++)
1270 char *format_timestamp(char *buf, size_t l, usec_t t) {
1280 sec = (time_t) t / USEC_PER_SEC;
1282 if (strftime(buf, l, "%a, %d %b %Y %H:%M:%S %z", localtime_r(&sec, &tm)) <= 0)
1288 bool fstype_is_network(const char *fstype) {
1289 static const char * const table[] = {
1299 for (i = 0; i < ELEMENTSOF(table); i++)
1300 if (streq(table[i], fstype))
1309 if ((fd = open("/dev/tty0", O_RDWR|O_NOCTTY|O_CLOEXEC)) < 0)
1314 TIOCL_GETKMSGREDIRECT,
1318 if (ioctl(fd, TIOCLINUX, tiocl) < 0)
1321 vt = tiocl[0] <= 0 ? 1 : tiocl[0];
1324 if (ioctl(fd, VT_ACTIVATE, vt) < 0)
1331 int read_one_char(FILE *f, char *ret, bool *need_nl) {
1332 struct termios old_termios, new_termios;
1339 if (tcgetattr(fileno(f), &old_termios) >= 0) {
1340 new_termios = old_termios;
1342 new_termios.c_lflag &= ~ICANON;
1343 new_termios.c_cc[VMIN] = 1;
1344 new_termios.c_cc[VTIME] = 0;
1346 if (tcsetattr(fileno(f), TCSADRAIN, &new_termios) >= 0) {
1349 k = fread(&c, 1, 1, f);
1351 tcsetattr(fileno(f), TCSADRAIN, &old_termios);
1357 *need_nl = c != '\n';
1364 if (!(fgets(line, sizeof(line), f)))
1369 if (strlen(line) != 1)
1379 int ask(char *ret, const char *replies, const char *text, ...) {
1388 bool need_nl = true;
1396 if ((r = read_one_char(stdin, &c, &need_nl)) < 0) {
1398 if (r == -EBADMSG) {
1399 puts("Bad input, please try again.");
1410 if (strchr(replies, c)) {
1415 puts("Read unexpected character, please try again.");
1419 int reset_terminal(int fd) {
1420 struct termios termios;
1425 /* Set terminal up for job control */
1427 if (tcgetattr(fd, &termios) < 0) {
1432 termios.c_iflag &= ~(IGNBRK | BRKINT);
1433 termios.c_iflag |= ICRNL | IMAXBEL | IUTF8;
1434 termios.c_oflag |= ONLCR;
1435 termios.c_cflag |= CREAD;
1436 termios.c_lflag = ISIG | ICANON | IEXTEN | ECHO | ECHOE | ECHOK | ECHOCTL | ECHOPRT | ECHOKE;
1438 termios.c_cc[VINTR] = 03; /* ^C */
1439 termios.c_cc[VQUIT] = 034; /* ^\ */
1440 termios.c_cc[VERASE] = 0177;
1441 termios.c_cc[VKILL] = 025; /* ^X */
1442 termios.c_cc[VEOF] = 04; /* ^D */
1443 termios.c_cc[VSTART] = 021; /* ^Q */
1444 termios.c_cc[VSTOP] = 023; /* ^S */
1445 termios.c_cc[VSUSP] = 032; /* ^Z */
1446 termios.c_cc[VLNEXT] = 026; /* ^V */
1447 termios.c_cc[VWERASE] = 027; /* ^W */
1448 termios.c_cc[VREPRINT] = 022; /* ^R */
1450 termios.c_cc[VTIME] = 0;
1451 termios.c_cc[VMIN] = 1;
1453 if (tcsetattr(fd, TCSANOW, &termios) < 0)
1457 /* Just in case, flush all crap out */
1458 tcflush(fd, TCIOFLUSH);
1463 int open_terminal(const char *name, int mode) {
1466 if ((fd = open(name, mode)) < 0)
1469 if ((r = isatty(fd)) < 0) {
1470 close_nointr_nofail(fd);
1475 close_nointr_nofail(fd);
1482 int flush_fd(int fd) {
1483 struct pollfd pollfd;
1487 pollfd.events = POLLIN;
1494 if ((r = poll(&pollfd, 1, 0)) < 0) {
1505 if ((l = read(fd, buf, sizeof(buf))) < 0) {
1510 if (errno == EAGAIN)
1521 int acquire_terminal(const char *name, bool fail, bool force) {
1522 int fd = -1, notify = -1, r, wd;
1526 /* We use inotify to be notified when the tty is closed. We
1527 * create the watch before checking if we can actually acquire
1528 * it, so that we don't lose any event.
1530 * Note: strictly speaking this actually watches for the
1531 * device being closed, it does *not* really watch whether a
1532 * tty loses its controlling process. However, unless some
1533 * rogue process uses TIOCNOTTY on /dev/tty *after* closing
1534 * its tty otherwise this will not become a problem. As long
1535 * as the administrator makes sure not configure any service
1536 * on the same tty as an untrusted user this should not be a
1537 * problem. (Which he probably should not do anyway.) */
1539 if (!fail && !force) {
1540 if ((notify = inotify_init1(IN_CLOEXEC)) < 0) {
1545 if ((wd = inotify_add_watch(notify, name, IN_CLOSE)) < 0) {
1552 if ((r = flush_fd(notify)) < 0)
1555 /* We pass here O_NOCTTY only so that we can check the return
1556 * value TIOCSCTTY and have a reliable way to figure out if we
1557 * successfully became the controlling process of the tty */
1558 if ((fd = open_terminal(name, O_RDWR|O_NOCTTY)) < 0)
1561 /* First, try to get the tty */
1562 if ((r = ioctl(fd, TIOCSCTTY, force)) < 0 &&
1563 (force || fail || errno != EPERM)) {
1573 assert(notify >= 0);
1576 struct inotify_event e;
1579 if ((l = read(notify, &e, sizeof(e))) != sizeof(e)) {
1593 if (e.wd != wd || !(e.mask & IN_CLOSE)) {
1601 /* We close the tty fd here since if the old session
1602 * ended our handle will be dead. It's important that
1603 * we do this after sleeping, so that we don't enter
1604 * an endless loop. */
1605 close_nointr_nofail(fd);
1609 close_nointr(notify);
1611 if ((r = reset_terminal(fd)) < 0)
1612 log_warning("Failed to reset terminal: %s", strerror(-r));
1621 close_nointr(notify);
1626 int release_terminal(void) {
1629 if ((fd = open("/dev/tty", O_RDWR)) < 0)
1632 if (ioctl(fd, TIOCNOTTY) < 0)
1635 close_nointr_nofail(fd);
1639 int ignore_signal(int sig) {
1640 struct sigaction sa;
1643 sa.sa_handler = SIG_IGN;
1644 sa.sa_flags = SA_RESTART;
1646 return sigaction(sig, &sa, NULL);
1649 static const char *const ioprio_class_table[] = {
1650 [IOPRIO_CLASS_NONE] = "none",
1651 [IOPRIO_CLASS_RT] = "realtime",
1652 [IOPRIO_CLASS_BE] = "best-effort",
1653 [IOPRIO_CLASS_IDLE] = "idle"
1656 DEFINE_STRING_TABLE_LOOKUP(ioprio_class, int);
1658 static const char *const sigchld_code_table[] = {
1659 [CLD_EXITED] = "exited",
1660 [CLD_KILLED] = "killed",
1661 [CLD_DUMPED] = "dumped",
1662 [CLD_TRAPPED] = "trapped",
1663 [CLD_STOPPED] = "stopped",
1664 [CLD_CONTINUED] = "continued",
1667 DEFINE_STRING_TABLE_LOOKUP(sigchld_code, int);
1669 static const char *const log_facility_table[LOG_NFACILITIES] = {
1670 [LOG_FAC(LOG_KERN)] = "kern",
1671 [LOG_FAC(LOG_USER)] = "user",
1672 [LOG_FAC(LOG_MAIL)] = "mail",
1673 [LOG_FAC(LOG_DAEMON)] = "daemon",
1674 [LOG_FAC(LOG_AUTH)] = "auth",
1675 [LOG_FAC(LOG_SYSLOG)] = "syslog",
1676 [LOG_FAC(LOG_LPR)] = "lpr",
1677 [LOG_FAC(LOG_NEWS)] = "news",
1678 [LOG_FAC(LOG_UUCP)] = "uucp",
1679 [LOG_FAC(LOG_CRON)] = "cron",
1680 [LOG_FAC(LOG_AUTHPRIV)] = "authpriv",
1681 [LOG_FAC(LOG_FTP)] = "ftp",
1682 [LOG_FAC(LOG_LOCAL0)] = "local0",
1683 [LOG_FAC(LOG_LOCAL1)] = "local1",
1684 [LOG_FAC(LOG_LOCAL2)] = "local2",
1685 [LOG_FAC(LOG_LOCAL3)] = "local3",
1686 [LOG_FAC(LOG_LOCAL4)] = "local4",
1687 [LOG_FAC(LOG_LOCAL5)] = "local5",
1688 [LOG_FAC(LOG_LOCAL6)] = "local6",
1689 [LOG_FAC(LOG_LOCAL7)] = "local7"
1692 DEFINE_STRING_TABLE_LOOKUP(log_facility, int);
1694 static const char *const log_level_table[] = {
1695 [LOG_EMERG] = "emerg",
1696 [LOG_ALERT] = "alert",
1697 [LOG_CRIT] = "crit",
1699 [LOG_WARNING] = "warning",
1700 [LOG_NOTICE] = "notice",
1701 [LOG_INFO] = "info",
1702 [LOG_DEBUG] = "debug"
1705 DEFINE_STRING_TABLE_LOOKUP(log_level, int);
1707 static const char* const sched_policy_table[] = {
1708 [SCHED_OTHER] = "other",
1709 [SCHED_BATCH] = "batch",
1710 [SCHED_IDLE] = "idle",
1711 [SCHED_FIFO] = "fifo",
1715 DEFINE_STRING_TABLE_LOOKUP(sched_policy, int);
1717 static const char* const rlimit_table[] = {
1718 [RLIMIT_CPU] = "LimitCPU",
1719 [RLIMIT_FSIZE] = "LimitFSIZE",
1720 [RLIMIT_DATA] = "LimitDATA",
1721 [RLIMIT_STACK] = "LimitSTACK",
1722 [RLIMIT_CORE] = "LimitCORE",
1723 [RLIMIT_RSS] = "LimitRSS",
1724 [RLIMIT_NOFILE] = "LimitNOFILE",
1725 [RLIMIT_AS] = "LimitAS",
1726 [RLIMIT_NPROC] = "LimitNPROC",
1727 [RLIMIT_MEMLOCK] = "LimitMEMLOCK",
1728 [RLIMIT_LOCKS] = "LimitLOCKS",
1729 [RLIMIT_SIGPENDING] = "LimitSIGPENDING",
1730 [RLIMIT_MSGQUEUE] = "LimitMSGQUEUE",
1731 [RLIMIT_NICE] = "LimitNICE",
1732 [RLIMIT_RTPRIO] = "LimitRTPRIO",
1733 [RLIMIT_RTTIME] = "LimitRTTIME"
1736 DEFINE_STRING_TABLE_LOOKUP(rlimit, int);