if (!FLAGS_SET(flags, PORTABLE_REATTACH) && !FLAGS_SET(flags, PORTABLE_FORCE_ATTACH))
HASHMAP_FOREACH(item, unit_files) {
- r = unit_file_exists(scope, &paths, item->name);
+ r = unit_file_exists_full(scope, &paths, SEARCH_IGNORE_TEMPLATE, item->name, /* ret_path= */ NULL);
if (r < 0)
return sd_bus_error_set_errnof(error, r, "Failed to determine whether unit '%s' exists on the host: %m", item->name);
if (r > 0)
#define UNIT_FILE_FOLLOW_SYMLINK_MAX 64
-typedef enum SearchFlags {
- SEARCH_LOAD = 1 << 0,
- SEARCH_FOLLOW_CONFIG_SYMLINKS = 1 << 1,
- SEARCH_DROPIN = 1 << 2,
-} SearchFlags;
-
typedef struct {
RuntimeScope scope;
OrderedHashmap *will_process;
assert(info->name);
- if (unit_name_is_valid(info->name, UNIT_NAME_INSTANCE)) {
+ if (!FLAGS_SET(flags, SEARCH_IGNORE_TEMPLATE) && unit_name_is_valid(info->name, UNIT_NAME_INSTANCE)) {
r = unit_name_template(info->name, &template);
if (r < 0)
return r;
int unit_file_exists_full(
RuntimeScope scope,
const LookupPaths *lp,
- bool follow,
+ SearchFlags flags,
const char *name,
char **ret_path) {
&c,
lp,
name,
- follow ? SEARCH_FOLLOW_CONFIG_SYMLINKS : 0,
+ flags,
ret_path ? &info : NULL,
/* changes= */ NULL,
/* n_changes= */ NULL);
_UNIT_FILE_FLAGS_MASK_PUBLIC = UNIT_FILE_RUNTIME|UNIT_FILE_PORTABLE|UNIT_FILE_FORCE,
} UnitFileFlags;
+typedef enum SearchFlags {
+ SEARCH_LOAD = 1 << 0,
+ SEARCH_FOLLOW_CONFIG_SYMLINKS = 1 << 1,
+ SEARCH_DROPIN = 1 << 2,
+ SEARCH_IGNORE_TEMPLATE = 1 << 3, /* Don't look up the template if the instance does not exist. */
+} SearchFlags;
+
/* type can be either one of the INSTALL_CHANGE_SYMLINK, INSTALL_CHANGE_UNLINK, … listed above, or a negative
* errno value.
*
int unit_file_exists_full(
RuntimeScope scope,
const LookupPaths *lp,
- bool follow,
+ SearchFlags flags,
const char *name,
char **ret_path);
static inline int unit_file_exists(RuntimeScope scope, const LookupPaths *lp, const char *name) {
- return unit_file_exists_full(scope, lp, false, name, NULL);
+ return unit_file_exists_full(scope, lp, 0, name, NULL);
}
int unit_file_get_list(RuntimeScope scope, const char *root_dir, char * const *states, char * const *patterns, Hashmap **ret);
_cleanup_free_ char *found_sshd_template_unit = NULL;
r = unit_file_exists_full(RUNTIME_SCOPE_SYSTEM, &lp,
- /* follow = */ true,
+ SEARCH_FOLLOW_CONFIG_SYMLINKS,
"sshd@.service",
&found_sshd_template_unit);
if (r < 0)