[systemd-devel] [PATCH] conf-files: really work under different root
Lukáš Nykrýn
lnykryn at redhat.com
Thu Jun 12 07:01:13 PDT 2014
Lukas Nykryn píše v Čt 12. 06. 2014 v 15:53 +0200:
> search_and_fopen_* and conf_files_list function accept
> root parameter, but they are not using it.
>
> This leads to an issue with systemd-tmpfiles --root.
> The files and dirs are created in the correct location, but
> on the base of configuration from the normal root.
> ---
> src/shared/conf-files.c | 14 +++++++++++---
> src/shared/util.c | 29 +++++++++++++++++++++++++++--
> 2 files changed, 38 insertions(+), 5 deletions(-)
>
> diff --git a/src/shared/conf-files.c b/src/shared/conf-files.c
> index 5201782..892b170 100644
> --- a/src/shared/conf-files.c
> +++ b/src/shared/conf-files.c
> @@ -37,10 +37,18 @@
> #include "hashmap.h"
> #include "conf-files.h"
>
> -static int files_add(Hashmap *h, const char *dirpath, const char *suffix) {
> +static int files_add(Hashmap *h, const char *dirpath, const char *suffix, const char *root) {
> _cleanup_closedir_ DIR *dir = NULL;
>
> - dir = opendir(dirpath);
> + if (root) {
> + _cleanup_free_ char *p = NULL;
> + p = strjoin(root, "/", dirpath, NULL);
> + if (!p)
> + return -ENOMEM;
> + dir = opendir(p);
> + } else
> + dir = opendir(dirpath);
> +
> if (!dir) {
> if (errno == ENOENT)
> return 0;
> @@ -108,7 +116,7 @@ static int conf_files_list_strv_internal(char ***strv, const char *suffix, const
> return -ENOMEM;
>
> STRV_FOREACH(p, dirs) {
> - r = files_add(fh, *p, suffix);
> + r = files_add(fh, *p, suffix, root);
> if (r == -ENOMEM) {
> hashmap_free_free(fh);
> return r;
> diff --git a/src/shared/util.c b/src/shared/util.c
> index 91cbf20..daf09ab 100644
> --- a/src/shared/util.c
> +++ b/src/shared/util.c
> @@ -5702,6 +5702,15 @@ static int search_and_fopen_internal(const char *path, const char *mode, const c
> if (!p)
> return -ENOMEM;
>
> + if (root) {
> + char *q = NULL;
> + q = strjoin(root, "/", p, NULL);
> + if (!q)
> + return -ENOMEM;
> + free(p);
> + p = q;
> + }
> +
> f = fopen(p, mode);
> if (f) {
> *_f = f;
> @@ -5724,8 +5733,16 @@ int search_and_fopen(const char *path, const char *mode, const char *root, const
>
> if (path_is_absolute(path)) {
> FILE *f;
> + if (root) {
> + _cleanup_free_ char *p = NULL;
> + p = strjoin(root, "/", path, NULL);
> + if (!p)
> + return -ENOMEM;
> +
> + f = fopen(p, mode);
> + } else
> + f = fopen(path, mode);
>
> - f = fopen(path, mode);
> if (f) {
> *_f = f;
> return 0;
> @@ -5747,7 +5764,15 @@ int search_and_fopen_nulstr(const char *path, const char *mode, const char *root
> if (path_is_absolute(path)) {
> FILE *f;
>
> - f = fopen(path, mode);
> + if (root) {
> + _cleanup_free_ char *p = NULL;
> + p = strjoin(root, "/", path, NULL);
> + if (!p)
> + return -ENOMEM;
> +
> + f = fopen(p, mode);
> + } else
> + f = fopen(path, mode);
> if (f) {
> *_f = f;
> return 0;
Damn it. This addresses the same issue as the patch "shared: fix
searching for configs in alternate roots" from Michael Marineau.
So probably just ignore this one.
Lukas
More information about the systemd-devel
mailing list