X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fload-fragment.c;h=ef5d192f2a0fecbbdd7310a8bdacc5456689b7f9;hb=6ef25fb65ee0a62972ed7cbc01b6a11feb5fcb16;hp=b122ea419cfe907235cb930ac26ffea54caba5d8;hpb=9e37286844f67ca7c59e923dd27ad193dfdda7eb;p=elogind.git diff --git a/src/load-fragment.c b/src/load-fragment.c index b122ea419..ef5d192f2 100644 --- a/src/load-fragment.c +++ b/src/load-fragment.c @@ -84,7 +84,8 @@ int config_parse_unit_deps( char *t, *k; int r; - if (!(t = strndup(w, l))) + t = strndup(w, l); + if (!t) return -ENOMEM; k = unit_name_printf(u, t); @@ -94,12 +95,8 @@ int config_parse_unit_deps( return -ENOMEM; r = unit_add_dependency_by_name(u, d, k, NULL, true); - - if (r < 0) { - log_error("Failed to add dependency on %s, ignoring: %s", k, strerror(-r)); - free(k); - return 0; - } + if (r < 0) + log_error("[%s:%u] Failed to add dependency on %s, ignoring: %s", filename, line, k, strerror(-r)); free(k); } @@ -554,6 +551,7 @@ int config_parse_exec( if (!n[0]) { log_error("[%s:%u] Invalid command line, ignoring: %s", filename, line, rvalue); strv_free(n); + free(path); return 0; } @@ -1264,6 +1262,7 @@ int config_parse_timer_unit( Timer *t = data; int r; DBusError error; + Unit *u; assert(filename); assert(lvalue); @@ -1277,12 +1276,15 @@ int config_parse_timer_unit( return 0; } - if ((r = manager_load_unit(t->meta.manager, rvalue, NULL, NULL, &t->unit)) < 0) { + r = manager_load_unit(t->meta.manager, rvalue, NULL, NULL, &u); + if (r < 0) { log_error("[%s:%u] Failed to load unit %s, ignoring: %s", filename, line, rvalue, bus_error(&error, r)); dbus_error_free(&error); return 0; } + unit_ref_set(&t->unit, u); + return 0; } @@ -1346,6 +1348,7 @@ int config_parse_path_unit( Path *t = data; int r; DBusError error; + Unit *u; assert(filename); assert(lvalue); @@ -1359,12 +1362,14 @@ int config_parse_path_unit( return 0; } - if ((r = manager_load_unit(t->meta.manager, rvalue, NULL, &error, &t->unit)) < 0) { + if ((r = manager_load_unit(t->meta.manager, rvalue, NULL, &error, &u)) < 0) { log_error("[%s:%u] Failed to load unit %s, ignoring: %s", filename, line, rvalue, bus_error(&error, r)); dbus_error_free(&error); return 0; } + unit_ref_set(&t->unit, u); + return 0; } @@ -1381,6 +1386,7 @@ int config_parse_socket_service( Socket *s = data; int r; DBusError error; + Unit *x; assert(filename); assert(lvalue); @@ -1394,12 +1400,15 @@ int config_parse_socket_service( return 0; } - if ((r = manager_load_unit(s->meta.manager, rvalue, NULL, &error, (Unit**) &s->service)) < 0) { + r = manager_load_unit(s->meta.manager, rvalue, NULL, &error, &x); + if (r < 0) { log_error("[%s:%u] Failed to load unit %s, ignoring: %s", filename, line, rvalue, bus_error(&error, r)); dbus_error_free(&error); return 0; } + unit_ref_set(&s->service, x); + return 0; } @@ -1415,7 +1424,6 @@ int config_parse_service_sockets( Service *s = data; int r; - DBusError error; char *state, *w; size_t l; @@ -1424,35 +1432,34 @@ int config_parse_service_sockets( assert(rvalue); assert(data); - dbus_error_init(&error); - FOREACH_WORD_QUOTED(w, l, rvalue, state) { - char *t; - Unit *sock; + char *t, *k; - if (!(t = strndup(w, l))) + t = strndup(w, l); + if (!t) return -ENOMEM; - if (!endswith(t, ".socket")) { - log_error("[%s:%u] Unit must be of type socket, ignoring: %s", filename, line, rvalue); - free(t); - continue; - } - - r = manager_load_unit(s->meta.manager, t, NULL, &error, &sock); + k = unit_name_printf(UNIT(s), t); free(t); - if (r < 0) { - log_error("[%s:%u] Failed to load unit %s, ignoring: %s", filename, line, rvalue, bus_error(&error, r)); - dbus_error_free(&error); + if (!k) + return -ENOMEM; + + if (!endswith(k, ".socket")) { + log_error("[%s:%u] Unit must be of type socket, ignoring: %s", filename, line, rvalue); + free(k); continue; } - if ((r = set_ensure_allocated(&s->configured_sockets, trivial_hash_func, trivial_compare_func)) < 0) - return r; + r = unit_add_two_dependencies_by_name(UNIT(s), UNIT_WANTS, UNIT_AFTER, k, NULL, true); + if (r < 0) + log_error("[%s:%u] Failed to add dependency on %s, ignoring: %s", filename, line, k, strerror(-r)); - if ((r = set_put(s->configured_sockets, sock)) < 0) + r = unit_add_dependency_by_name(UNIT(s), UNIT_TRIGGERED_BY, k, NULL, true); + if (r < 0) return r; + + free(k); } return 0; @@ -1545,10 +1552,12 @@ int config_parse_unit_condition_path( assert(rvalue); assert(data); - if ((trigger = rvalue[0] == '|')) + trigger = rvalue[0] == '|'; + if (trigger) rvalue++; - if ((negate = rvalue[0] == '!')) + negate = rvalue[0] == '!'; + if (negate) rvalue++; if (!path_is_absolute(rvalue)) { @@ -1556,7 +1565,8 @@ int config_parse_unit_condition_path( return 0; } - if (!(c = condition_new(cond, rvalue, trigger, negate))) + c = condition_new(cond, rvalue, trigger, negate); + if (!c) return -ENOMEM; LIST_PREPEND(Condition, conditions, u->meta.conditions, c); @@ -1843,6 +1853,7 @@ int config_parse_unit_device_allow(const char *filename, unsigned line, const ch static int blkio_map(const char *controller, const char *name, const char *value, char **ret) { struct stat st; char **l; + dev_t d; assert(controller); assert(name); @@ -1861,13 +1872,23 @@ static int blkio_map(const char *controller, const char *name, const char *value return -errno; } - if (!S_ISBLK(st.st_mode)) { - log_warning("%s is not a block device.", l[0]); + 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]); strv_free(l); return -ENODEV; } - if (asprintf(ret, "%u:%u %s", major(st.st_rdev), minor(st.st_rdev), l[1]) < 0) { + if (asprintf(ret, "%u:%u %s", major(d), minor(d), l[1]) < 0) { strv_free(l); return -ENOMEM; } @@ -1907,7 +1928,7 @@ int config_parse_unit_blkio_weight(const char *filename, unsigned line, const ch weight = l[1]; } - if (device && !path_startswith(device, "/dev/")) { + if (device && !path_is_absolute(device)) { log_error("[%s:%u] Failed to parse block device node value, ignoring: %s", filename, line, rvalue); strv_free(l); return 0; @@ -1965,7 +1986,7 @@ int config_parse_unit_blkio_bandwidth(const char *filename, unsigned line, const return 0; } - if (!path_startswith(l[0], "/dev/")) { + if (!path_is_absolute(l[0])) { log_error("[%s:%u] Failed to parse block device node value, ignoring: %s", filename, line, rvalue); strv_free(l); return 0;