#include "missing.h"
#include "unit-name.h"
#include "unit-printf.h"
-#include "bus-errors.h"
+#include "dbus-common.h"
#include "utf8.h"
#include "path-util.h"
#include "syscall-list.h"
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);
}
FOREACH_WORD_QUOTED(w, l, rvalue, state) {
- char _cleanup_free_ *t = NULL;
+ _cleanup_free_ char *t = NULL;
int r;
unsigned cpu;
* interface. */
FOREACH_WORD_QUOTED(w, l, rvalue, state) {
- char _cleanup_free_ *t = NULL;
+ _cleanup_free_ char *t = NULL;
int r;
cap_value_t cap;
}
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);
assert(data);
FOREACH_WORD_SEPARATOR(w, l, rvalue, ", ", state) {
- char _cleanup_free_ *t;
+ _cleanup_free_ char *t;
t = strndup(w, l);
if (!t)
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;
}
Path *p = data;
PathSpec *s;
PathType b;
- char _cleanup_free_ *k = NULL;
+ _cleanup_free_ char *k = NULL;
assert(filename);
assert(lvalue);
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,
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)
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)
if (!id)
return -ENOMEM;
- r = set_put(names, id);
- if (r < 0) {
- free(id);
+ r = set_consume(names, id);
+ if (r < 0)
return r;
- }
}
}
/* Now, parse the file contents */
r = config_parse(u->id, filename, f, UNIT_VTABLE(u)->sections,
config_item_perf_lookup,
- (void*) load_fragment_gperf_lookup, false, u);
+ (void*) load_fragment_gperf_lookup, false, true, u);
if (r < 0)
goto finish;
{ 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" },