X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fcore%2Fload-fragment.c;h=65a2a39248ba3e0fa979b569e07fa41522402e00;hb=e62d8c394474;hp=f82ddd530c0e6fe1ba0e5223dd11d74bb6ee91c5;hpb=74051b9b5865586bf4d30b9075649af838fb92bd;p=elogind.git diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c index f82ddd530..65a2a3924 100644 --- a/src/core/load-fragment.c +++ b/src/core/load-fragment.c @@ -48,6 +48,7 @@ #include "utf8.h" #include "path-util.h" #include "syscall-list.h" +#include "env-util.h" #ifndef HAVE_SYSV_COMPAT int config_parse_warn_compat( @@ -126,9 +127,10 @@ int config_parse_unit_string_printf( k = unit_full_printf(u, rvalue); if (!k) - return log_oom(); + log_error("[%s:%u] Failed to resolve unit specifiers on %s. Ignoring.", + filename, line, rvalue); - return config_parse_string(filename, line, section, lvalue, ltype, k, data, userdata); + return config_parse_string(filename, line, section, lvalue, ltype, k ? k : rvalue, data, userdata); } int config_parse_unit_strv_printf( @@ -151,9 +153,10 @@ int config_parse_unit_strv_printf( k = unit_full_printf(u, rvalue); if (!k) - return log_oom(); + log_error("[%s:%u] Failed to resolve unit specifiers on %s. Ignoring.", + filename, line, rvalue); - return config_parse_strv(filename, line, section, lvalue, ltype, k, data, userdata); + return config_parse_strv(filename, line, section, lvalue, ltype, k ? k : rvalue, data, userdata); } int config_parse_unit_path_printf( @@ -176,9 +179,10 @@ int config_parse_unit_path_printf( k = unit_full_printf(u, rvalue); if (!k) - return log_oom(); + log_error("[%s:%u] Failed to resolve unit specifiers on %s. Ignoring.", + filename, line, rvalue); - return config_parse_path(filename, line, section, lvalue, ltype, k, data, userdata); + return config_parse_path(filename, line, section, lvalue, ltype, k ? k : rvalue, data, userdata); } int config_parse_socket_listen( @@ -216,8 +220,13 @@ int config_parse_socket_listen( p->type = ltype; p->path = unit_full_printf(UNIT(s), rvalue); if (!p->path) { - free(p); - return log_oom(); + p->path = strdup(rvalue); + if (!p->path) { + free(p); + return log_oom(); + } else + log_error("[%s:%u] Failed to resolve unit specifiers on %s. Ignoring.", + filename, line, rvalue); } path_kill_slashes(p->path); @@ -228,12 +237,11 @@ int config_parse_socket_listen( p->type = SOCKET_SOCKET; k = unit_full_printf(UNIT(s), rvalue); - if (!k) { - free(p); - return log_oom(); - } + if (!k) + log_error("[%s:%u] Failed to resolve unit specifiers on %s. Ignoring.", + filename, line, rvalue); - r = socket_address_parse_netlink(&p->address, k); + r = socket_address_parse_netlink(&p->address, k ? k : rvalue); if (r < 0) { log_error("[%s:%u] Failed to parse address value, ignoring: %s", filename, line, rvalue); free(p); @@ -246,12 +254,11 @@ int config_parse_socket_listen( p->type = SOCKET_SOCKET; k = unit_full_printf(UNIT(s), rvalue); - if (!k) { - free(p); - return log_oom(); - } + if (!k) + log_error("[%s:%u] Failed to resolve unit specifiers on %s. Ignoring.", + filename, line, rvalue); - r = socket_address_parse(&p->address, k); + r = socket_address_parse(&p->address, k ? k : rvalue); if (r < 0) { log_error("[%s:%u] Failed to parse address value, ignoring: %s", filename, line, rvalue); free(p); @@ -458,7 +465,7 @@ int config_parse_exec( k = 0; FOREACH_WORD_QUOTED(w, l, rvalue, state) { - if (strncmp(w, ";", MAX(l, 1U)) == 0) + if (strneq(w, ";", MAX(l, 1U))) break; k++; @@ -470,9 +477,9 @@ int config_parse_exec( k = 0; FOREACH_WORD_QUOTED(w, l, rvalue, state) { - if (strncmp(w, ";", MAX(l, 1U)) == 0) + if (strneq(w, ";", MAX(l, 1U))) break; - else if (strncmp(w, "\\;", MAX(l, 1U)) == 0) + else if (strneq(w, "\\;", MAX(l, 1U))) w ++; if (honour_argv0 && w == rvalue) { @@ -839,17 +846,17 @@ int config_parse_exec_secure_bits( FOREACH_WORD_QUOTED(w, l, rvalue, state) { if (first_word(w, "keep-caps")) - c->secure_bits |= SECURE_KEEP_CAPS; + c->secure_bits |= 1<secure_bits |= SECURE_KEEP_CAPS_LOCKED; + c->secure_bits |= 1<secure_bits |= SECURE_NO_SETUID_FIXUP; + c->secure_bits |= 1<secure_bits |= SECURE_NO_SETUID_FIXUP_LOCKED; + c->secure_bits |= 1<secure_bits |= SECURE_NOROOT; + c->secure_bits |= 1<secure_bits |= SECURE_NOROOT_LOCKED; + c->secure_bits |= 1<= 1); - - if (streq(l[0], "*")) { - - if (asprintf(ret, "a *:*%s%s", - isempty(l[1]) ? "" : " ", strempty(l[1])) < 0) - return -ENOMEM; - } else { - struct stat st; - - if (stat(l[0], &st) < 0) { - log_warning("Couldn't stat device %s", l[0]); - return -errno; - } - - if (!S_ISCHR(st.st_mode) && !S_ISBLK(st.st_mode)) { - log_warning("%s is not a device.", l[0]); - return -ENODEV; - } - - if (asprintf(ret, "%c %u:%u%s%s", - S_ISCHR(st.st_mode) ? 'c' : 'b', - major(st.st_rdev), minor(st.st_rdev), - isempty(l[1]) ? "" : " ", strempty(l[1])) < 0) - return -ENOMEM; - } - - return 0; -} - -int config_parse_unit_device_allow(const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata) { - Unit *u = data; - _cleanup_strv_free_ char **l = NULL; - int r; - unsigned k; - - assert(filename); - assert(lvalue); - assert(rvalue); - assert(data); - - l = strv_split_quoted(rvalue); - if (!l) - return log_oom(); - - k = strv_length(l); - if (k < 1 || k > 2) { - log_error("[%s:%u] Failed to parse device value, ignoring: %s", filename, line, rvalue); - return 0; - } - - if (!streq(l[0], "*") && !path_startswith(l[0], "/dev")) { - log_error("[%s:%u] Device node path not absolute, ignoring: %s", filename, line, rvalue); - return 0; - } - - if (!isempty(l[1]) && !in_charset(l[1], "rwm")) { - log_error("[%s:%u] Device access string invalid, ignoring: %s", filename, line, rvalue); + log_error("[%s:%u] Failed to parse cgroup attribute value, ignoring: %s", filename, line, rvalue); return 0; } - r = unit_add_cgroup_attribute(u, "devices", - streq(lvalue, "DeviceAllow") ? "devices.allow" : "devices.deny", - rvalue, device_map, NULL); - + r = unit_add_cgroup_attribute(u, s, NULL, n, v ? v : rvalue + a + b, NULL); if (r < 0) { log_error("[%s:%u] Failed to add cgroup attribute value, ignoring: %s", filename, line, rvalue); return 0; @@ -1895,148 +1819,36 @@ int config_parse_unit_device_allow(const char *filename, unsigned line, const ch return 0; } -static int blkio_map(const char *controller, const char *name, const char *value, char **ret) { - struct stat st; - _cleanup_strv_free_ char **l = NULL; - dev_t d; - - assert(controller); - assert(name); - assert(value); - assert(ret); - - l = strv_split_quoted(value); - if (!l) - return log_oom(); - - assert(strv_length(l) == 2); - - if (stat(l[0], &st) < 0) { - log_warning("Couldn't stat device %s", l[0]); - return -errno; - } - - if (S_ISBLK(st.st_mode)) - d = st.st_rdev; - else if (major(st.st_dev) != 0) { - /* If this is not a device node then find the block - * device this file is stored on */ - d = st.st_dev; - - /* If this is a partition, try to get the originating - * block device */ - block_get_whole_disk(d, &d); - } else { - log_warning("%s is not a block device and file system block device cannot be determined or is not local.", l[0]); - return -ENODEV; - } - - if (asprintf(ret, "%u:%u %s", major(d), minor(d), l[1]) < 0) - return -ENOMEM; - - return 0; -} +int config_parse_unit_cgroup_attr_pretty( + const char *filename, + unsigned line, + const char *section, + const char *lvalue, + int ltype, + const char *rvalue, + void *data, + void *userdata) { -int config_parse_unit_blkio_weight(const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata) { Unit *u = data; + _cleanup_free_ char *v = NULL; + const CGroupSemantics *s; int r; - unsigned long ul; - const char *device = NULL, *weight; - unsigned k; - _cleanup_free_ char *t = NULL; - _cleanup_strv_free_ char **l = NULL; assert(filename); assert(lvalue); assert(rvalue); assert(data); - l = strv_split_quoted(rvalue); - if (!l) - return log_oom(); - - k = strv_length(l); - if (k < 1 || k > 2) { - log_error("[%s:%u] Failed to parse weight value, ignoring: %s", filename, line, rvalue); - return 0; - } - - if (k == 1) - weight = l[0]; - else { - device = l[0]; - weight = l[1]; - } - - if (device && !path_is_absolute(device)) { - log_error("[%s:%u] Failed to parse block device node value, ignoring: %s", filename, line, rvalue); - return 0; - } - - if (safe_atolu(weight, &ul) < 0 || ul < 10 || ul > 1000) { - log_error("[%s:%u] Failed to parse block IO weight value, ignoring: %s", filename, line, rvalue); - return 0; - } - - if (device) - r = asprintf(&t, "%s %lu", device, ul); - else - r = asprintf(&t, "%lu", ul); - if (r < 0) - return log_oom(); - - if (device) - r = unit_add_cgroup_attribute(u, "blkio", "blkio.weight_device", t, blkio_map, NULL); - else - r = unit_add_cgroup_attribute(u, "blkio", "blkio.weight", t, NULL, NULL); + r = cgroup_semantics_find(NULL, lvalue, rvalue, &v, &s); if (r < 0) { - log_error("[%s:%u] Failed to add cgroup attribute value, ignoring: %s", filename, line, rvalue); - return 0; - } - - return 0; -} - -int config_parse_unit_blkio_bandwidth(const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata) { - Unit *u = data; - int r; - off_t bytes; - unsigned k; - _cleanup_free_ char *t = NULL; - _cleanup_strv_free_ char **l = NULL; - - assert(filename); - assert(lvalue); - assert(rvalue); - assert(data); - - l = strv_split_quoted(rvalue); - if (!l) - return log_oom(); - - k = strv_length(l); - if (k != 2) { - log_error("[%s:%u] Failed to parse bandwidth value, ignoring: %s", filename, line, rvalue); - return 0; - } - - if (!path_is_absolute(l[0])) { - log_error("[%s:%u] Failed to parse block device node value, ignoring: %s", filename, line, rvalue); + log_error("[%s:%u] Failed to parse cgroup attribute value, ignoring: %s", filename, line, rvalue); return 0; - } - - if (parse_bytes(l[1], &bytes) < 0 || bytes <= 0) { - log_error("[%s:%u] Failed to parse block IO bandwidth value, ignoring: %s", filename, line, rvalue); + } else if (r == 0) { + log_error("[%s:%u] Unknown or unsupported cgroup attribute %s, ignoring: %s", filename, line, lvalue, rvalue); return 0; } - r = asprintf(&t, "%s %llu", l[0], (unsigned long long) bytes); - if (r < 0) - return log_oom(); - - r = unit_add_cgroup_attribute(u, "blkio", - streq(lvalue, "BlockIOReadBandwidth") ? "blkio.read_bps_device" : "blkio.write_bps_device", - t, blkio_map, NULL); + r = unit_add_cgroup_attribute(u, s, NULL, NULL, v, NULL); if (r < 0) { log_error("[%s:%u] Failed to add cgroup attribute value, ignoring: %s", filename, line, rvalue); return 0; @@ -2120,10 +1932,12 @@ int config_parse_documentation( } static void syscall_set(uint32_t *p, int nr) { + nr = SYSCALL_TO_INDEX(nr); p[nr >> 4] |= 1 << (nr & 31); } static void syscall_unset(uint32_t *p, int nr) { + nr = SYSCALL_TO_INDEX(nr); p[nr >> 4] &= ~(1 << (nr & 31)); } @@ -2617,7 +2431,7 @@ void unit_dump_config_items(FILE *f) { prefix_len = dot-i; if (dot) - if (!prev || strncmp(prev, i, prefix_len+1) != 0) { + if (!prev || !strneq(prev, i, prefix_len+1)) { if (prev) fputc('\n', f);