aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarel Zak <kzak@redhat.com>2025-10-15 15:11:25 +0200
committerKarel Zak <kzak@redhat.com>2025-10-15 15:11:25 +0200
commit06805e9ec8db3cffeead4c64a211fd6692cd6cab (patch)
tree58861398b05dd9fcbea0c22584aa4397f6e36c66
parentbd34d1c085cdd0ed56718638d02f86c9d356e05e (diff)
downloadutil-linux-06805e9ec8db3cffeead4c64a211fd6692cd6cab.tar.gz
lib/configs: add head parameter to configs_refer_filename()
Allow configs_refer_filename() to add entries at either the head or tail of the list by adding a 'head' parameter. This simplifies the code for adding the main config file, eliminating the need to add to the tail and then move to the head. When head=1, use list_add() to prepend to the list. When head=0, use list_add_tail() to append to the list. Signed-off-by: Karel Zak <kzak@redhat.com>
-rw-r--r--lib/configs.c18
1 files changed, 7 insertions, 11 deletions
diff --git a/lib/configs.c b/lib/configs.c
index a7faf6ad24..7ecd69df65 100644
--- a/lib/configs.c
+++ b/lib/configs.c
@@ -74,7 +74,7 @@ static char *main_configs(const char *root,
return path;
}
-static int configs_refer_filename(struct list_head *list, char *filename)
+static int configs_refer_filename(struct list_head *list, char *filename, int head)
{
struct file_element *e;
@@ -84,7 +84,10 @@ static int configs_refer_filename(struct list_head *list, char *filename)
INIT_LIST_HEAD(&e->file_list);
e->filename = filename;
- list_add_tail(&e->file_list, list);
+ if (head)
+ list_add(&e->file_list, list);
+ else
+ list_add_tail(&e->file_list, list);
return 0;
}
@@ -147,7 +150,7 @@ static int read_dir(struct list_head *file_list,
break;
}
- ret = configs_refer_filename(file_list, filename);
+ ret = configs_refer_filename(file_list, filename, 0);
if (ret < 0) {
free(filename);
break;
@@ -285,18 +288,11 @@ int ul_configs_file_list(struct list_head *file_list,
/* Add main config file at the beginning (highest priority) */
if (main_file != NULL) {
- struct list_head *e;
-
- ret = configs_refer_filename(file_list, main_file);
+ ret = configs_refer_filename(file_list, main_file, 1);
if (ret < 0) {
free(main_file);
goto finish;
}
-
- /* Move last element (just added) to front */
- e = file_list->prev;
- list_del(e);
- list_add(e, file_list);
}
counter = list_count_entries(file_list);