X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fcore%2Fload-fragment.c;h=42c181de4da6efbef91ad6f3463af6752a0f43e6;hb=4e6db59202ad2dbbef56a69985643390ffdd57bd;hp=6e333aaf1599cd3a91f1d202d39b412da25716be;hpb=641906e9366891e0ad3e6e38b7396a427678c4cf;p=elogind.git diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c index 6e333aaf1..42c181de4 100644 --- a/src/core/load-fragment.c +++ b/src/core/load-fragment.c @@ -127,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( @@ -152,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( @@ -177,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( @@ -217,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); @@ -229,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); @@ -247,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); @@ -840,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; @@ -1946,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); + log_error("[%s:%u] Failed to parse cgroup attribute 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); + } else if (r == 0) { + log_error("[%s:%u] Unknown or unsupported cgroup attribute %s, ignoring: %s", filename, line, lvalue, 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); - 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; @@ -2634,7 +2395,7 @@ void unit_dump_config_items(FILE *f) { { config_parse_socket_listen, "SOCKET [...]" }, { config_parse_socket_bind, "SOCKETBIND" }, { config_parse_socket_bindtodevice, "NETWORKINTERFACE" }, - { config_parse_usec, "SECONDS" }, + { config_parse_sec, "SECONDS" }, { config_parse_nsec, "NANOSECONDS" }, { config_parse_path_strv, "PATH [...]" }, { config_parse_unit_requires_mounts_for, "PATH [...]" },