summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/dropin.c38
-rw-r--r--src/shared/dropin.h16
-rw-r--r--src/shared/install.c21
-rw-r--r--src/shared/install.h30
-rw-r--r--src/shared/meson.build2
-rw-r--r--src/shared/path-lookup.h2
-rw-r--r--src/shared/unit-file.c23
-rw-r--r--src/shared/unit-file.h37
8 files changed, 81 insertions, 88 deletions
diff --git a/src/shared/dropin.c b/src/shared/dropin.c
index 409eef21ff..4a29bd09c5 100644
--- a/src/shared/dropin.c
+++ b/src/shared/dropin.c
@@ -24,16 +24,15 @@
#include "unit-name.h"
int drop_in_file(const char *dir, const char *unit, unsigned level,
- const char *name, char **_p, char **_q) {
+ const char *name, char **ret_p, char **ret_q) {
char prefix[DECIMAL_STR_MAX(unsigned)];
- _cleanup_free_ char *b = NULL;
- char *p, *q;
+ _cleanup_free_ char *b = NULL, *p = NULL, *q = NULL;
assert(unit);
assert(name);
- assert(_p);
- assert(_q);
+ assert(ret_p);
+ assert(ret_q);
sprintf(prefix, "%u", level);
@@ -45,17 +44,12 @@ int drop_in_file(const char *dir, const char *unit, unsigned level,
return -EINVAL;
p = strjoin(dir, "/", unit, ".d");
- if (!p)
- return -ENOMEM;
-
q = strjoin(p, "/", prefix, "-", b, ".conf");
- if (!q) {
- free(p);
+ if (!p || !q)
return -ENOMEM;
- }
- *_p = p;
- *_q = q;
+ *ret_p = TAKE_PTR(p);
+ *ret_q = TAKE_PTR(q);
return 0;
}
@@ -99,7 +93,7 @@ int write_drop_in_format(const char *dir, const char *unit, unsigned level,
return write_drop_in(dir, unit, level, name, p);
}
-static int unit_file_find_dir(
+static int unit_file_add_dir(
const char *original_root,
const char *path,
char ***dirs) {
@@ -109,6 +103,8 @@ static int unit_file_find_dir(
assert(path);
+ /* This adds [original_root]/path to dirs, if it exists. */
+
r = chase_symlinks(path, original_root, 0, &chased);
if (r == -ENOENT) /* Ignore -ENOENT, after all most units won't have a drop-in dir. */
return 0;
@@ -121,11 +117,9 @@ static int unit_file_find_dir(
if (r < 0)
return log_warning_errno(r, "Failed to canonicalize path '%s': %m", path);
- r = strv_push(dirs, chased);
- if (r < 0)
+ if (strv_consume(dirs, TAKE_PTR(chased)) < 0)
return log_oom();
- chased = NULL;
return 0;
}
@@ -151,7 +145,7 @@ static int unit_file_find_dirs(
path = strjoina(unit_path, "/", name, suffix);
if (!unit_path_cache || set_get(unit_path_cache, path)) {
- r = unit_file_find_dir(original_root, path, dirs);
+ r = unit_file_add_dir(original_root, path, dirs);
if (r < 0)
return r;
}
@@ -228,19 +222,19 @@ int unit_file_find_dropin_paths(
Set *unit_path_cache,
const char *dir_suffix,
const char *file_suffix,
- Set *names,
+ const Set *names,
char ***ret) {
_cleanup_strv_free_ char **dirs = NULL;
- char *t, **p;
+ char *name, **p;
Iterator i;
int r;
assert(ret);
- SET_FOREACH(t, names, i)
+ SET_FOREACH(name, names, i)
STRV_FOREACH(p, lookup_path)
- (void) unit_file_find_dirs(original_root, unit_path_cache, *p, t, dir_suffix, &dirs);
+ (void) unit_file_find_dirs(original_root, unit_path_cache, *p, name, dir_suffix, &dirs);
if (strv_isempty(dirs)) {
*ret = NULL;
diff --git a/src/shared/dropin.h b/src/shared/dropin.h
index ae7379beee..89a2ab1098 100644
--- a/src/shared/dropin.h
+++ b/src/shared/dropin.h
@@ -21,19 +21,5 @@ int unit_file_find_dropin_paths(
Set *unit_path_cache,
const char *dir_suffix,
const char *file_suffix,
- Set *names,
+ const Set *names,
char ***paths);
-
-static inline int unit_file_find_dropin_conf_paths(
- const char *original_root,
- char **lookup_path,
- Set *unit_path_cache,
- Set *names,
- char ***paths) {
-
- return unit_file_find_dropin_paths(original_root,
- lookup_path,
- unit_path_cache,
- ".d", ".conf",
- names, paths);
-}
diff --git a/src/shared/install.c b/src/shared/install.c
index 68ffd12f03..dfb6036191 100644
--- a/src/shared/install.c
+++ b/src/shared/install.c
@@ -37,7 +37,7 @@
#include "string-table.h"
#include "string-util.h"
#include "strv.h"
-#include "unit-name.h"
+#include "unit-file.h"
#define UNIT_FILE_FOLLOW_SYMLINK_MAX 64
@@ -98,25 +98,6 @@ static void presets_freep(Presets *p) {
p->n_rules = 0;
}
-bool unit_type_may_alias(UnitType type) {
- return IN_SET(type,
- UNIT_SERVICE,
- UNIT_SOCKET,
- UNIT_TARGET,
- UNIT_DEVICE,
- UNIT_TIMER,
- UNIT_PATH);
-}
-
-bool unit_type_may_template(UnitType type) {
- return IN_SET(type,
- UNIT_SERVICE,
- UNIT_SOCKET,
- UNIT_TARGET,
- UNIT_TIMER,
- UNIT_PATH);
-}
-
static const char *const unit_file_type_table[_UNIT_FILE_TYPE_MAX] = {
[UNIT_FILE_TYPE_REGULAR] = "regular",
[UNIT_FILE_TYPE_SYMLINK] = "symlink",
diff --git a/src/shared/install.h b/src/shared/install.h
index e452940991..b2ad9c4a71 100644
--- a/src/shared/install.h
+++ b/src/shared/install.h
@@ -1,8 +1,6 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
#pragma once
-typedef enum UnitFileScope UnitFileScope;
-typedef enum UnitFileState UnitFileState;
typedef enum UnitFilePresetMode UnitFilePresetMode;
typedef enum UnitFileChangeType UnitFileChangeType;
typedef enum UnitFileFlags UnitFileFlags;
@@ -19,31 +17,6 @@ typedef struct UnitFileInstallInfo UnitFileInstallInfo;
#include "strv.h"
#include "unit-name.h"
-enum UnitFileScope {
- UNIT_FILE_SYSTEM,
- UNIT_FILE_GLOBAL,
- UNIT_FILE_USER,
- _UNIT_FILE_SCOPE_MAX,
- _UNIT_FILE_SCOPE_INVALID = -1
-};
-
-enum UnitFileState {
- UNIT_FILE_ENABLED,
- UNIT_FILE_ENABLED_RUNTIME,
- UNIT_FILE_LINKED,
- UNIT_FILE_LINKED_RUNTIME,
- UNIT_FILE_MASKED,
- UNIT_FILE_MASKED_RUNTIME,
- UNIT_FILE_STATIC,
- UNIT_FILE_DISABLED,
- UNIT_FILE_INDIRECT,
- UNIT_FILE_GENERATED,
- UNIT_FILE_TRANSIENT,
- UNIT_FILE_BAD,
- _UNIT_FILE_STATE_MAX,
- _UNIT_FILE_STATE_INVALID = -1
-};
-
enum UnitFilePresetMode {
UNIT_FILE_PRESET_FULL,
UNIT_FILE_PRESET_ENABLE_ONLY,
@@ -114,9 +87,6 @@ struct UnitFileInstallInfo {
bool auxiliary;
};
-bool unit_type_may_alias(UnitType type) _const_;
-bool unit_type_may_template(UnitType type) _const_;
-
int unit_file_enable(
UnitFileScope scope,
UnitFileFlags flags,
diff --git a/src/shared/meson.build b/src/shared/meson.build
index bdd823bbd1..ca24d15eab 100644
--- a/src/shared/meson.build
+++ b/src/shared/meson.build
@@ -170,6 +170,8 @@ shared_sources = files('''
udev-util.h
uid-range.c
uid-range.h
+ unit-file.h
+ unit-file.c
utmp-wtmp.h
varlink.c
varlink.h
diff --git a/src/shared/path-lookup.h b/src/shared/path-lookup.h
index cb7d4d537f..7070b94249 100644
--- a/src/shared/path-lookup.h
+++ b/src/shared/path-lookup.h
@@ -5,7 +5,7 @@
typedef struct LookupPaths LookupPaths;
-#include "install.h"
+#include "unit-file.h"
#include "macro.h"
typedef enum LookupPathsFlags {
diff --git a/src/shared/unit-file.c b/src/shared/unit-file.c
new file mode 100644
index 0000000000..deed7dcf09
--- /dev/null
+++ b/src/shared/unit-file.c
@@ -0,0 +1,23 @@
+/* SPDX-License-Identifier: LGPL-2.1+ */
+
+#include "macro.h"
+#include "unit-file.h"
+
+bool unit_type_may_alias(UnitType type) {
+ return IN_SET(type,
+ UNIT_SERVICE,
+ UNIT_SOCKET,
+ UNIT_TARGET,
+ UNIT_DEVICE,
+ UNIT_TIMER,
+ UNIT_PATH);
+}
+
+bool unit_type_may_template(UnitType type) {
+ return IN_SET(type,
+ UNIT_SERVICE,
+ UNIT_SOCKET,
+ UNIT_TARGET,
+ UNIT_TIMER,
+ UNIT_PATH);
+}
diff --git a/src/shared/unit-file.h b/src/shared/unit-file.h
new file mode 100644
index 0000000000..2b9df655ee
--- /dev/null
+++ b/src/shared/unit-file.h
@@ -0,0 +1,37 @@
+/* SPDX-License-Identifier: LGPL-2.1+ */
+#pragma once
+
+#include <stdbool.h>
+
+#include "unit-name.h"
+
+typedef enum UnitFileState UnitFileState;
+typedef enum UnitFileScope UnitFileScope;
+
+enum UnitFileState {
+ UNIT_FILE_ENABLED,
+ UNIT_FILE_ENABLED_RUNTIME,
+ UNIT_FILE_LINKED,
+ UNIT_FILE_LINKED_RUNTIME,
+ UNIT_FILE_MASKED,
+ UNIT_FILE_MASKED_RUNTIME,
+ UNIT_FILE_STATIC,
+ UNIT_FILE_DISABLED,
+ UNIT_FILE_INDIRECT,
+ UNIT_FILE_GENERATED,
+ UNIT_FILE_TRANSIENT,
+ UNIT_FILE_BAD,
+ _UNIT_FILE_STATE_MAX,
+ _UNIT_FILE_STATE_INVALID = -1
+};
+
+enum UnitFileScope {
+ UNIT_FILE_SYSTEM,
+ UNIT_FILE_GLOBAL,
+ UNIT_FILE_USER,
+ _UNIT_FILE_SCOPE_MAX,
+ _UNIT_FILE_SCOPE_INVALID = -1
+};
+
+bool unit_type_may_alias(UnitType type) _const_;
+bool unit_type_may_template(UnitType type) _const_;