chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix order and document user unit dirs
[elogind.git]
/
src
/
shared
/
install.c
diff --git
a/src/shared/install.c
b/src/shared/install.c
index a080d8f328af9ae4acbd3041362f6f5d5b2985c2..fa064c230fdeb98de6e06bc8fb1340ae5a834a42 100644
(file)
--- a/
src/shared/install.c
+++ b/
src/shared/install.c
@@
-45,8
+45,6
@@
typedef struct {
Hashmap *have_installed;
} InstallContext;
Hashmap *have_installed;
} InstallContext;
-#define _cleanup_install_context_done_ _cleanup_(install_context_done)
-
static int in_search_path(const char *path, char **search) {
_cleanup_free_ char *parent = NULL;
int r;
static int in_search_path(const char *path, char **search) {
_cleanup_free_ char *parent = NULL;
int r;
@@
-88,15
+86,10
@@
static int get_config_path(UnitFileScope scope, bool runtime, const char *root_d
case UNIT_FILE_SYSTEM:
case UNIT_FILE_SYSTEM:
- if (root_dir && runtime)
- asprintf(&p, "%s/run/systemd/system", root_dir);
- else if (runtime)
- p = strdup("/run/systemd/system");
- else if (root_dir)
- asprintf(&p, "%s/%s", root_dir, SYSTEM_CONFIG_UNIT_PATH);
+ if (runtime)
+ p = path_join(root_dir, "/run/systemd/system", NULL);
else
else
- p = strdup(SYSTEM_CONFIG_UNIT_PATH);
-
+ p = path_join(root_dir, SYSTEM_CONFIG_UNIT_PATH, NULL);
break;
case UNIT_FILE_GLOBAL:
break;
case UNIT_FILE_GLOBAL:
@@
-112,10
+105,14
@@
static int get_config_path(UnitFileScope scope, bool runtime, const char *root_d
case UNIT_FILE_USER:
case UNIT_FILE_USER:
- if (root_dir
|| runtime
)
+ if (root_dir)
return -EINVAL;
return -EINVAL;
- r = user_config_home(&p);
+ if (runtime)
+ r = user_runtime_dir(&p);
+ else
+ r = user_config_home(&p);
+
if (r <= 0)
return r < 0 ? r : -ENOENT;
if (r <= 0)
return r < 0 ? r : -ENOENT;
@@
-186,7
+183,7
@@
static int mark_symlink_for_removal(
assert(p);
assert(p);
- r = set_ensure_allocated(remove_symlinks_to,
string_hash_func, string_compare_func
);
+ r = set_ensure_allocated(remove_symlinks_to,
&string_hash_ops
);
if (r < 0)
return r;
if (r < 0)
return r;
@@
-534,36
+531,33
@@
static int find_symlinks_in_scope(
UnitFileState *state) {
int r;
UnitFileState *state) {
int r;
- _cleanup_free_ char *path
2
= NULL;
+ _cleanup_free_ char *path = NULL;
bool same_name_link_runtime = false, same_name_link = false;
assert(scope >= 0);
assert(scope < _UNIT_FILE_SCOPE_MAX);
assert(name);
bool same_name_link_runtime = false, same_name_link = false;
assert(scope >= 0);
assert(scope < _UNIT_FILE_SCOPE_MAX);
assert(name);
- if (scope == UNIT_FILE_SYSTEM || scope == UNIT_FILE_GLOBAL) {
- _cleanup_free_ char *path = NULL;
-
/* First look in runtime config path */
-
r = get_config_path(scope, true, root_dir, &path);
-
if (r < 0)
-
return r;
+ /* First look in runtime config path */
+ r = get_config_path(scope, true, root_dir, &path);
+ if (r < 0)
+ return r;
- r = find_symlinks(name, path, &same_name_link_runtime);
- if (r < 0)
- return r;
- else if (r > 0) {
- *state = UNIT_FILE_ENABLED_RUNTIME;
- return r;
- }
+ r = find_symlinks(name, path, &same_name_link_runtime);
+ if (r < 0)
+ return r;
+ else if (r > 0) {
+ *state = UNIT_FILE_ENABLED_RUNTIME;
+ return r;
}
/* Then look in the normal config path */
}
/* Then look in the normal config path */
- r = get_config_path(scope, false, root_dir, &path
2
);
+ r = get_config_path(scope, false, root_dir, &path);
if (r < 0)
return r;
if (r < 0)
return r;
- r = find_symlinks(name, path
2
, &same_name_link);
+ r = find_symlinks(name, path, &same_name_link);
if (r < 0)
return r;
else if (r > 0) {
if (r < 0)
return r;
else if (r > 0) {
@@
-891,7
+885,7
@@
static int install_info_add(
hashmap_get(c->will_install, name))
return 0;
hashmap_get(c->will_install, name))
return 0;
- r = hashmap_ensure_allocated(&c->will_install,
string_hash_func, string_compare_func
);
+ r = hashmap_ensure_allocated(&c->will_install,
&string_hash_ops
);
if (r < 0)
return r;
if (r < 0)
return r;
@@
-951,20
+945,19
@@
static int config_parse_also(
void *data,
void *userdata) {
void *data,
void *userdata) {
- char *w;
size_t l;
size_t l;
- c
har
*state;
+ c
onst char *word,
*state;
InstallContext *c = data;
assert(filename);
assert(lvalue);
assert(rvalue);
InstallContext *c = data;
assert(filename);
assert(lvalue);
assert(rvalue);
- FOREACH_WORD_QUOTED(w, l, rvalue, state) {
+ FOREACH_WORD_QUOTED(w
ord
, l, rvalue, state) {
_cleanup_free_ char *n;
int r;
_cleanup_free_ char *n;
int r;
- n = strndup(w, l);
+ n = strndup(w
ord
, l);
if (!n)
return -ENOMEM;
if (!n)
return -ENOMEM;
@@
-972,6
+965,9
@@
static int config_parse_also(
if (r < 0)
return r;
}
if (r < 0)
return r;
}
+ if (!isempty(state))
+ log_syntax(unit, LOG_ERR, filename, line, EINVAL,
+ "Trailing garbage, ignoring.");
return 0;
}
return 0;
}
@@
-1030,8
+1026,10
@@
static int config_parse_default_instance(
if (r < 0)
return r;
if (r < 0)
return r;
- if (!unit_instance_is_valid(printed))
+ if (!unit_instance_is_valid(printed)) {
+ free(printed);
return -EINVAL;
return -EINVAL;
+ }
free(i->default_instance);
i->default_instance = printed;
free(i->default_instance);
i->default_instance = printed;
@@
-1064,7
+1062,7
@@
static int unit_file_load(
assert(path);
if (!isempty(root_dir))
assert(path);
if (!isempty(root_dir))
- path = strappenda
3
(root_dir, "/", path);
+ path = strappenda(root_dir, "/", path);
fd = open(path, O_RDONLY|O_CLOEXEC|O_NOCTTY|(allow_symlink ? 0 : O_NOFOLLOW));
if (fd < 0)
fd = open(path, O_RDONLY|O_CLOEXEC|O_NOCTTY|(allow_symlink ? 0 : O_NOFOLLOW));
if (fd < 0)
@@
-1076,7
+1074,10
@@
static int unit_file_load(
return -ENOMEM;
}
return -ENOMEM;
}
- r = config_parse(NULL, path, f, NULL, config_item_table_lookup, items, true, true, info);
+ r = config_parse(NULL, path, f,
+ NULL,
+ config_item_table_lookup, items,
+ true, true, false, info);
if (r < 0)
return r;
if (r < 0)
return r;
@@
-1161,7
+1162,7
@@
static int unit_file_can_install(
const char *name,
bool allow_symlink) {
const char *name,
bool allow_symlink) {
- _cleanup_
install_context_done_
InstallContext c = {};
+ _cleanup_
(install_context_done)
InstallContext c = {};
InstallInfo *i;
int r;
InstallInfo *i;
int r;
@@
-1395,7
+1396,7
@@
static int install_context_apply(
while ((i = hashmap_first(c->will_install))) {
while ((i = hashmap_first(c->will_install))) {
- q = hashmap_ensure_allocated(&c->have_installed,
string_hash_func, string_compare_func
);
+ q = hashmap_ensure_allocated(&c->have_installed,
&string_hash_ops
);
if (q < 0)
return q;
if (q < 0)
return q;
@@
-1436,7
+1437,7
@@
static int install_context_mark_for_removal(
while ((i = hashmap_first(c->will_install))) {
while ((i = hashmap_first(c->will_install))) {
- q = hashmap_ensure_allocated(&c->have_installed,
string_hash_func, string_compare_func
);
+ q = hashmap_ensure_allocated(&c->have_installed,
&string_hash_ops
);
if (q < 0)
return q;
if (q < 0)
return q;
@@
-1498,7
+1499,7
@@
int unit_file_enable(
unsigned *n_changes) {
_cleanup_lookup_paths_free_ LookupPaths paths = {};
unsigned *n_changes) {
_cleanup_lookup_paths_free_ LookupPaths paths = {};
- _cleanup_
install_context_done_
InstallContext c = {};
+ _cleanup_
(install_context_done)
InstallContext c = {};
char **i;
_cleanup_free_ char *config_path = NULL;
int r;
char **i;
_cleanup_free_ char *config_path = NULL;
int r;
@@
-1537,7
+1538,7
@@
int unit_file_disable(
unsigned *n_changes) {
_cleanup_lookup_paths_free_ LookupPaths paths = {};
unsigned *n_changes) {
_cleanup_lookup_paths_free_ LookupPaths paths = {};
- _cleanup_
install_context_done_
InstallContext c = {};
+ _cleanup_
(install_context_done)
InstallContext c = {};
char **i;
_cleanup_free_ char *config_path = NULL;
_cleanup_set_free_free_ Set *remove_symlinks_to = NULL;
char **i;
_cleanup_free_ char *config_path = NULL;
_cleanup_set_free_free_ Set *remove_symlinks_to = NULL;
@@
-1597,7
+1598,7
@@
int unit_file_set_default(
unsigned *n_changes) {
_cleanup_lookup_paths_free_ LookupPaths paths = {};
unsigned *n_changes) {
_cleanup_lookup_paths_free_ LookupPaths paths = {};
- _cleanup_
install_context_done_
InstallContext c = {};
+ _cleanup_
(install_context_done)
InstallContext c = {};
_cleanup_free_ char *config_path = NULL;
char *path;
int r;
_cleanup_free_ char *config_path = NULL;
char *path;
int r;
@@
-1658,11
+1659,7
@@
int unit_file_get_default(
_cleanup_free_ char *path = NULL, *tmp = NULL;
char *n;
_cleanup_free_ char *path = NULL, *tmp = NULL;
char *n;
- if (isempty(root_dir))
- path = strappend(*p, "/" SPECIAL_DEFAULT_TARGET);
- else
- path = strjoin(root_dir, "/", *p, "/" SPECIAL_DEFAULT_TARGET, NULL);
-
+ path = path_join(root_dir, *p, SPECIAL_DEFAULT_TARGET);
if (!path)
return -ENOMEM;
if (!path)
return -ENOMEM;
@@
-1719,15
+1716,12
@@
UnitFileState unit_file_get_state(
free(path);
path = NULL;
free(path);
path = NULL;
- if (root_dir)
- asprintf(&path, "%s/%s/%s", root_dir, *i, name);
- else
- asprintf(&path, "%s/%s", *i, name);
+ path = path_join(root_dir, *i, name);
if (!path)
return -ENOMEM;
if (root_dir)
if (!path)
return -ENOMEM;
if (root_dir)
- partial = path + strlen(root_dir)
+ 1
;
+ partial = path + strlen(root_dir);
else
partial = path;
else
partial = path;
@@
-1866,7
+1860,7
@@
int unit_file_preset(
UnitFileChange **changes,
unsigned *n_changes) {
UnitFileChange **changes,
unsigned *n_changes) {
- _cleanup_
install_context_done_
InstallContext plus = {}, minus = {};
+ _cleanup_
(install_context_done)
InstallContext plus = {}, minus = {};
_cleanup_lookup_paths_free_ LookupPaths paths = {};
_cleanup_free_ char *config_path = NULL;
char **i;
_cleanup_lookup_paths_free_ LookupPaths paths = {};
_cleanup_free_ char *config_path = NULL;
char **i;
@@
-1874,7
+1868,7
@@
int unit_file_preset(
assert(scope >= 0);
assert(scope < _UNIT_FILE_SCOPE_MAX);
assert(scope >= 0);
assert(scope < _UNIT_FILE_SCOPE_MAX);
- assert(mode < _UNIT_FILE_PRESET_M
ODE_M
AX);
+ assert(mode < _UNIT_FILE_PRESET_MAX);
r = lookup_paths_init_from_scope(&paths, scope, root_dir);
if (r < 0)
r = lookup_paths_init_from_scope(&paths, scope, root_dir);
if (r < 0)
@@
-1934,7
+1928,7
@@
int unit_file_preset_all(
UnitFileChange **changes,
unsigned *n_changes) {
UnitFileChange **changes,
unsigned *n_changes) {
- _cleanup_
install_context_done_
InstallContext plus = {}, minus = {};
+ _cleanup_
(install_context_done)
InstallContext plus = {}, minus = {};
_cleanup_lookup_paths_free_ LookupPaths paths = {};
_cleanup_free_ char *config_path = NULL;
char **i;
_cleanup_lookup_paths_free_ LookupPaths paths = {};
_cleanup_free_ char *config_path = NULL;
char **i;
@@
-1942,7
+1936,7
@@
int unit_file_preset_all(
assert(scope >= 0);
assert(scope < _UNIT_FILE_SCOPE_MAX);
assert(scope >= 0);
assert(scope < _UNIT_FILE_SCOPE_MAX);
- assert(mode < _UNIT_FILE_PRESET_M
ODE_M
AX);
+ assert(mode < _UNIT_FILE_PRESET_MAX);
r = lookup_paths_init_from_scope(&paths, scope, root_dir);
if (r < 0)
r = lookup_paths_init_from_scope(&paths, scope, root_dir);
if (r < 0)
@@
-1954,17
+1948,11
@@
int unit_file_preset_all(
STRV_FOREACH(i, paths.unit_path) {
_cleanup_closedir_ DIR *d = NULL;
STRV_FOREACH(i, paths.unit_path) {
_cleanup_closedir_ DIR *d = NULL;
- _cleanup_free_ char *buf = NULL;
- const char *units_dir;
-
- if (!isempty(root_dir)) {
- buf = strjoin(root_dir, "/", *i, NULL);
- if (!buf)
- return -ENOMEM;
+ _cleanup_free_ char *units_dir;
-
units_dir = buf
;
- } else
-
units_dir = *i
;
+
units_dir = path_join(root_dir, *i, NULL)
;
+ if (!units_dir)
+
return -ENOMEM
;
d = opendir(units_dir);
if (!d) {
d = opendir(units_dir);
if (!d) {
@@
-2032,14
+2020,15
@@
int unit_file_preset_all(
return r;
}
return r;
}
-static void unit
filelist_free(UnitFileList *
*f) {
- if (!
*
f)
+static void unit
_file_list_free_one(UnitFileList
*f) {
+ if (!f)
return;
return;
- free(
(*f)
->path);
- free(
*
f);
+ free(
f
->path);
+ free(f);
}
}
-#define _cleanup_unitfilelist_free_ _cleanup_(unitfilelist_free)
+
+DEFINE_TRIVIAL_CLEANUP_FUNC(UnitFileList*, unit_file_list_free_one);
int unit_file_get_list(
UnitFileScope scope,
int unit_file_get_list(
UnitFileScope scope,
@@
-2057,23
+2046,23
@@
int unit_file_get_list(
if (root_dir && scope != UNIT_FILE_SYSTEM)
return -EINVAL;
if (root_dir && scope != UNIT_FILE_SYSTEM)
return -EINVAL;
+ if (root_dir) {
+ r = access(root_dir, F_OK);
+ if (r < 0)
+ return -errno;
+ }
+
r = lookup_paths_init_from_scope(&paths, scope, root_dir);
if (r < 0)
return r;
STRV_FOREACH(i, paths.unit_path) {
_cleanup_closedir_ DIR *d = NULL;
r = lookup_paths_init_from_scope(&paths, scope, root_dir);
if (r < 0)
return r;
STRV_FOREACH(i, paths.unit_path) {
_cleanup_closedir_ DIR *d = NULL;
- _cleanup_free_ char *buf = NULL;
- const char *units_dir;
+ _cleanup_free_ char *units_dir;
- if (!isempty(root_dir)) {
- buf = strjoin(root_dir, "/", *i, NULL);
- if (!buf)
- return -ENOMEM;
-
- units_dir = buf;
- } else
- units_dir = *i;
+ units_dir = path_join(root_dir, *i, NULL);
+ if (!units_dir)
+ return -ENOMEM;
d = opendir(units_dir);
if (!d) {
d = opendir(units_dir);
if (!d) {
@@
-2084,8
+2073,9
@@
int unit_file_get_list(
}
for (;;) {
}
for (;;) {
- _cleanup_
unitfilelist_free_
UnitFileList *f = NULL;
+ _cleanup_
(unit_file_list_free_onep)
UnitFileList *f = NULL;
struct dirent *de;
struct dirent *de;
+ _cleanup_free_ char *path = NULL;
errno = 0;
de = readdir(d);
errno = 0;
de = readdir(d);
@@
-2135,7
+2125,11
@@
int unit_file_get_list(
goto found;
}
goto found;
}
- r = unit_file_can_install(&paths, root_dir, f->path, true);
+ path = path_make_absolute(de->d_name, *i);
+ if (!path)
+ return -ENOMEM;
+
+ r = unit_file_can_install(&paths, root_dir, path, true);
if (r == -EINVAL || /* Invalid setting? */
r == -EBADMSG || /* Invalid format? */
r == -ENOENT /* Included file not found? */)
if (r == -EINVAL || /* Invalid setting? */
r == -EBADMSG || /* Invalid format? */
r == -ENOENT /* Included file not found? */)
@@
-2179,7
+2173,7
@@
static const char* const unit_file_change_type_table[_UNIT_FILE_CHANGE_TYPE_MAX]
DEFINE_STRING_TABLE_LOOKUP(unit_file_change_type, UnitFileChangeType);
DEFINE_STRING_TABLE_LOOKUP(unit_file_change_type, UnitFileChangeType);
-static const char* const unit_file_preset_mode_table[_UNIT_FILE_PRESET_M
ODE_M
AX] = {
+static const char* const unit_file_preset_mode_table[_UNIT_FILE_PRESET_MAX] = {
[UNIT_FILE_PRESET_FULL] = "full",
[UNIT_FILE_PRESET_ENABLE_ONLY] = "enable-only",
[UNIT_FILE_PRESET_DISABLE_ONLY] = "disable-only",
[UNIT_FILE_PRESET_FULL] = "full",
[UNIT_FILE_PRESET_ENABLE_ONLY] = "enable-only",
[UNIT_FILE_PRESET_DISABLE_ONLY] = "disable-only",