mirror of
https://github.com/systemd/systemd
synced 2024-07-21 18:24:38 +00:00
shared/install: modernize install_info_add
This commit is contained in:
parent
df152dbbe5
commit
1ac0056cc2
|
@ -1180,16 +1180,19 @@ static int install_info_add(
|
||||||
bool auxiliary,
|
bool auxiliary,
|
||||||
InstallInfo **ret) {
|
InstallInfo **ret) {
|
||||||
|
|
||||||
|
_cleanup_free_ char *name_alloc = NULL;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
assert(ctx);
|
assert(ctx);
|
||||||
|
|
||||||
if (!name) {
|
if (!name) {
|
||||||
/* 'name' and 'path' must not both be null. Check here 'path' using assert_se() to
|
assert(path);
|
||||||
* workaround a bug in gcc that generates a -Wnonnull warning when calling basename(),
|
|
||||||
* but this cannot be possible in any code path (See #6119). */
|
r = path_extract_filename(path, &name_alloc);
|
||||||
assert_se(path);
|
if (r < 0)
|
||||||
name = basename(path);
|
return r;
|
||||||
|
|
||||||
|
name = name_alloc;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!unit_name_is_valid(name, UNIT_NAME_ANY))
|
if (!unit_name_is_valid(name, UNIT_NAME_ANY))
|
||||||
|
@ -1204,35 +1207,35 @@ static int install_info_add(
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
_cleanup_(install_info_freep) InstallInfo *alloc = new(InstallInfo, 1);
|
_cleanup_(install_info_freep) InstallInfo *new_info = new(InstallInfo, 1);
|
||||||
if (!alloc)
|
if (!new_info)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
*alloc = (InstallInfo) {
|
*new_info = (InstallInfo) {
|
||||||
.install_mode = _INSTALL_MODE_INVALID,
|
.install_mode = _INSTALL_MODE_INVALID,
|
||||||
.auxiliary = auxiliary,
|
.auxiliary = auxiliary,
|
||||||
};
|
};
|
||||||
|
|
||||||
alloc->name = strdup(name);
|
if (name_alloc)
|
||||||
if (!alloc->name)
|
new_info->name = TAKE_PTR(name_alloc);
|
||||||
return -ENOMEM;
|
else {
|
||||||
|
new_info->name = strdup(name);
|
||||||
if (root) {
|
if (!new_info->name)
|
||||||
alloc->root = strdup(root);
|
|
||||||
if (!alloc->root)
|
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (path) {
|
r = strdup_to(&new_info->root, root);
|
||||||
alloc->path = strdup(path);
|
|
||||||
if (!alloc->path)
|
|
||||||
return -ENOMEM;
|
|
||||||
}
|
|
||||||
|
|
||||||
r = ordered_hashmap_ensure_put(&ctx->will_process, &string_hash_ops, alloc->name, alloc);
|
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
i = TAKE_PTR(alloc);
|
|
||||||
|
r = strdup_to(&new_info->path, path);
|
||||||
|
if (r < 0)
|
||||||
|
return r;
|
||||||
|
|
||||||
|
r = ordered_hashmap_ensure_put(&ctx->will_process, &string_hash_ops, new_info->name, new_info);
|
||||||
|
if (r < 0)
|
||||||
|
return r;
|
||||||
|
i = TAKE_PTR(new_info);
|
||||||
|
|
||||||
if (ret)
|
if (ret)
|
||||||
*ret = i;
|
*ret = i;
|
||||||
|
|
Loading…
Reference in a new issue