X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fcore%2Fload-fragment.c;h=3d23372630bd9da0556a4ff1e5e97c7f8ec06953;hb=a6b26d9011de60e1c41f51e8d2aab1d2f7bbf0f5;hp=e71194301d1a619925fe1d0c2b9a8a4c676a4fb8;hpb=449101fce2757575c4813a9512890536365445f6;p=elogind.git diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c index e71194301..3d2337263 100644 --- a/src/core/load-fragment.c +++ b/src/core/load-fragment.c @@ -91,7 +91,7 @@ int config_parse_unit_deps(const char* unit, assert(rvalue); FOREACH_WORD_QUOTED(w, l, rvalue, state) { - char _cleanup_free_ *t = NULL, *k = NULL; + _cleanup_free_ char *t = NULL, *k = NULL; int r; t = strndup(w, l); @@ -785,7 +785,7 @@ int config_parse_exec_cpu_affinity(const char *unit, } FOREACH_WORD_QUOTED(w, l, rvalue, state) { - char _cleanup_free_ *t = NULL; + _cleanup_free_ char *t = NULL; int r; unsigned cpu; @@ -927,7 +927,7 @@ int config_parse_bounding_set(const char *unit, * interface. */ FOREACH_WORD_QUOTED(w, l, rvalue, state) { - char _cleanup_free_ *t = NULL; + _cleanup_free_ char *t = NULL; int r; cap_value_t cap; @@ -1019,7 +1019,7 @@ int config_parse_unit_cgroup(const char *unit, } FOREACH_WORD_QUOTED(w, l, rvalue, state) { - char _cleanup_free_ *t = NULL, *k = NULL, *ku = NULL; + _cleanup_free_ char *t = NULL, *k = NULL, *ku = NULL; int r; t = strndup(w, l); @@ -1161,7 +1161,7 @@ int config_parse_exec_mount_flags(const char *unit, assert(data); FOREACH_WORD_SEPARATOR(w, l, rvalue, ", ", state) { - char _cleanup_free_ *t; + _cleanup_free_ char *t; t = strndup(w, l); if (!t) @@ -1254,50 +1254,57 @@ int config_parse_timer(const char *unit, return 0; } -int config_parse_timer_unit(const char *unit, - const char *filename, - unsigned line, - const char *section, - const char *lvalue, - int ltype, - const char *rvalue, - void *data, - void *userdata) { +int config_parse_trigger_unit( + const char *unit, + const char *filename, + unsigned line, + const char *section, + const char *lvalue, + int ltype, + const char *rvalue, + void *data, + void *userdata) { - Timer *t = data; - int r; - DBusError error; - Unit *u; _cleanup_free_ char *p = NULL; + Unit *u = data; + UnitType type; + int r; assert(filename); assert(lvalue); assert(rvalue); assert(data); - dbus_error_init(&error); + if (!set_isempty(u->dependencies[UNIT_TRIGGERS])) { + log_syntax(unit, LOG_ERR, filename, line, EINVAL, + "Multiple units to trigger specified, ignoring: %s", rvalue); + return 0; + } - p = unit_name_printf(UNIT(t), rvalue); + p = unit_name_printf(u, rvalue); if (!p) return log_oom(); - if (endswith(p, ".timer")) { + type = unit_name_to_type(p); + if (type < 0) { log_syntax(unit, LOG_ERR, filename, line, EINVAL, - "Unit cannot be of type timer, ignoring: %s", rvalue); + "Unit type not valid, ignoring: %s", rvalue); return 0; } - r = manager_load_unit(UNIT(t)->manager, p, NULL, NULL, &u); + if (type == u->type) { + log_syntax(unit, LOG_ERR, filename, line, EINVAL, + "Trigger cannot be of same type, ignoring: %s", rvalue); + return 0; + } + + r = unit_add_two_dependencies_by_name(u, UNIT_BEFORE, UNIT_TRIGGERS, p, NULL, true); if (r < 0) { log_syntax(unit, LOG_ERR, filename, line, -r, - "Failed to load unit %s, ignoring: %s", - rvalue, bus_error(&error, r)); - dbus_error_free(&error); + "Failed to add trigger on %s, ignoring: %s", p, strerror(-r)); return 0; } - unit_ref_set(&t->unit, u); - return 0; } @@ -1314,7 +1321,7 @@ int config_parse_path_spec(const char *unit, Path *p = data; PathSpec *s; PathType b; - char _cleanup_free_ *k = NULL; + _cleanup_free_ char *k = NULL; assert(filename); assert(lvalue); @@ -1365,53 +1372,6 @@ int config_parse_path_spec(const char *unit, return 0; } -int config_parse_path_unit(const char *unit, - const char *filename, - unsigned line, - const char *section, - const char *lvalue, - int ltype, - const char *rvalue, - void *data, - void *userdata) { - - Path *t = data; - int r; - DBusError error; - Unit *u; - _cleanup_free_ char *p = NULL; - - assert(filename); - assert(lvalue); - assert(rvalue); - assert(data); - - dbus_error_init(&error); - - p = unit_name_printf(UNIT(t), rvalue); - if (!p) - return log_oom(); - - if (endswith(p, ".path")) { - log_syntax(unit, LOG_ERR, filename, line, EINVAL, - "Unit cannot be of type path, ignoring: %s", p); - return 0; - } - - r = manager_load_unit(UNIT(t)->manager, p, NULL, &error, &u); - if (r < 0) { - log_syntax(unit, LOG_ERR, filename, line, EINVAL, - "Failed to load unit %s, ignoring: %s", - p, bus_error(&error, r)); - dbus_error_free(&error); - return 0; - } - - unit_ref_set(&t->unit, u); - - return 0; -} - int config_parse_socket_service(const char *unit, const char *filename, unsigned line, @@ -1480,7 +1440,7 @@ int config_parse_service_sockets(const char *unit, assert(data); FOREACH_WORD_QUOTED(w, l, rvalue, state) { - char _cleanup_free_ *t = NULL, *k = NULL; + _cleanup_free_ char *t = NULL, *k = NULL; t = strndup(w, l); if (!t) @@ -2074,7 +2034,7 @@ int config_parse_syscall_filter(const char *unit, FOREACH_WORD_QUOTED(w, l, rvalue, state) { int id; - char _cleanup_free_ *t = NULL; + _cleanup_free_ char *t = NULL; t = strndup(w, l); if (!t) @@ -2135,11 +2095,9 @@ static int open_follow(char **filename, FILE **_f, Set *names, char **_final) { if (!id) return -ENOMEM; - r = set_put(names, id); - if (r < 0) { - free(id); + r = set_consume(names, id); + if (r < 0) return r; - } } } @@ -2480,10 +2438,9 @@ void unit_dump_config_items(FILE *f) { { config_parse_unit_requires_mounts_for, "PATH [...]" }, { config_parse_exec_mount_flags, "MOUNTFLAG [...]" }, { config_parse_unit_string_printf, "STRING" }, + { config_parse_trigger_unit, "UNIT" }, { config_parse_timer, "TIMER" }, - { config_parse_timer_unit, "NAME" }, { config_parse_path_spec, "PATH" }, - { config_parse_path_unit, "UNIT" }, { config_parse_notify_access, "ACCESS" }, { config_parse_ip_tos, "TOS" }, { config_parse_unit_condition_path, "CONDITION" },