From: Lennart Poettering Date: Tue, 17 Nov 2015 13:04:40 +0000 (+0100) Subject: core: move check whether a unit is suitable to become transient into unit.c X-Git-Tag: v228~1^2~6 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0f13f3bd7918b84955eaa0ceeea0f964877a93f7;p=platform%2Fupstream%2Fsystemd.git core: move check whether a unit is suitable to become transient into unit.c Lets introduce unit_is_pristine() that verifies whether a unit is suitable to become a transient unit, by checking that it is no referenced yet and has no data on disk assigned. --- diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c index 51ee581..693d93f 100644 --- a/src/core/dbus-manager.c +++ b/src/core/dbus-manager.c @@ -663,19 +663,7 @@ static int transient_unit_from_message( if (r < 0) return r; - /* Check if the unit already exists or is already referenced, - * in a number of different ways. Note that to cater for unit - * types such as slice, we are generally fine with units that - * are marked UNIT_LOADED even even though nothing was - * actually loaded, as those unit types don't require a file - * on disk to validly load. */ - - if (!IN_SET(u->load_state, UNIT_NOT_FOUND, UNIT_LOADED) || - u->fragment_path || - u->source_path || - !strv_isempty(u->dropin_paths) || - u->refs || - set_size(u->dependencies[UNIT_REFERENCED_BY]) > 0) + if (!unit_is_pristine(u)) return sd_bus_error_setf(error, BUS_ERROR_UNIT_EXISTS, "Unit %s already exists.", name); /* OK, the unit failed to load and is unreferenced, now let's diff --git a/src/core/unit.c b/src/core/unit.c index d199d87..7809bfd 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -3704,3 +3704,23 @@ int unit_fail_if_symlink(Unit *u, const char* where) { return -ELOOP; } + +bool unit_is_pristine(Unit *u) { + assert(u); + + /* Check if the unit already exists or is already referenced, + * in a number of different ways. Note that to cater for unit + * types such as slice, we are generally fine with units that + * are marked UNIT_LOADED even even though nothing was + * actually loaded, as those unit types don't require a file + * on disk to validly load. */ + + return !(!IN_SET(u->load_state, UNIT_NOT_FOUND, UNIT_LOADED) || + u->fragment_path || + u->source_path || + !strv_isempty(u->dropin_paths) || + u->refs || + set_size(u->dependencies[UNIT_REFERENCED_BY]) > 0 || + u->job || + u->merged_into); +} diff --git a/src/core/unit.h b/src/core/unit.h index bcf41d2..a69d624 100644 --- a/src/core/unit.h +++ b/src/core/unit.h @@ -586,6 +586,8 @@ int unit_require_mounts_for(Unit *u, const char *path); bool unit_type_supported(UnitType t); +bool unit_is_pristine(Unit *u); + static inline bool unit_supported(Unit *u) { return unit_type_supported(u->type); }