| /* | |
| * No copyright is claimed. This code is in the public domain; do with | |
| * it what you wish. | |
| * | |
| * Evaluating a list of configuration filenames which have to be handled/parsed. | |
| * | |
| * The order of this file list has been defined by | |
| * https://github.com/uapi-group/specifications/blob/main/specs/configuration_files_specification.md | |
| */ | |
| #ifndef UTIL_LINUX_CONFIGS_H | |
| #define UTIL_LINUX_CONFIGS_H | |
| #include "list.h" | |
| /** | |
| * ul_configs_file_list - Evaluating a list of sorted configuration filenames which have to be handled | |
| * in the correct order. | |
| * | |
| * @file_list: List of filenames which have to be parsed in that order | |
| * @project: name of the project used as subdirectory, can be NULL | |
| * @etc_subdir: absolute directory path for user changed configuration files, can be NULL (default "/etc"). | |
| * @usr_subdir: absolute directory path of vendor defined settings (often "/usr/lib"). | |
| * @config_name: basename of the configuration file. If it is NULL, drop-ins without a main configuration file will be parsed only. | |
| * @config_suffix: suffix of the configuration file. Can also be NULL. | |
| * | |
| * Returns the length of the file_list, or -ENOMEM, or -ENOTEMPTY if config_name is NULL | |
| * | |
| * The list is returned in parsing order, which means in the order of | |
| * increasing priority: | |
| * | |
| * - the main file (<config_name>.<suffix>) is the first one; it is searched | |
| * in @etcdir, @rundir and @usrdir in this order and only the first one | |
| * found is used, so a main file in /etc replaces the one in /usr/lib | |
| * rather than modifying it, | |
| * | |
| * - then the drop-ins, the files with the @config_suffix suffix in the | |
| * <config_name>.<suffix>.d directory, sorted by their basename and | |
| * collected from all the three directories, where a drop-in in /etc | |
| * replaces the drop-in of the same name in /run or /usr/lib. | |
| * | |
| * The caller is expected to parse the files in this order and to let the | |
| * later file overwrite the settings of the previous one. This means that | |
| * drop-ins have higher priority than the main file, and that a drop-in has | |
| * higher priority than the drop-ins which sort before it. | |
| * | |
| * Example: | |
| * int count = 0; | |
| * struct list_head *file_list; | |
| * | |
| * count = ul_configs_file_list(&file_list, | |
| * "foo", | |
| * "/etc", | |
| * "/usr/lib", | |
| * "example", | |
| * "conf"); | |
| * | |
| * The order of this file list has been defined by | |
| * https://github.com/uapi-group/specifications/blob/main/specs/configuration_files_specification.md | |
| * | |
| */ | |
| int ul_configs_file_list(struct list_head *file_list, | |
| const char *project, | |
| const char *etcdir, | |
| const char *rundir, | |
| const char *usrdir, | |
| const char *confname, | |
| const char *suffix); | |
| /** | |
| * ul_configs_free_list - Freeing configuration list. | |
| * | |
| * @file_list: List of filenames which has to be freed. | |
| * | |
| */ | |
| void ul_configs_free_list(struct list_head *file_list); | |
| /** | |
| * ul_configs_next_filename - Going through the file list which has to be handled/parsed. | |
| * | |
| * @file_list: List of filenames which have to be handled. | |
| * @current_entry: Current list entry. Has to be initialized with NULL for the first call. | |
| * @name: Returned file name for each call. | |
| * | |
| * Returns 0 on success, <0 on error and 1 if the end of the list has been reached. | |
| * | |
| * Example: | |
| * int count = 0; | |
| * struct list_head *file_list = NULL; | |
| * struct list_head *current = NULL; | |
| * char *name = NULL; | |
| * | |
| * count = ul_configs_file_list(&file_list, | |
| * "foo", | |
| * "/etc", | |
| * "/usr/lib", | |
| * "example", | |
| * "conf"); | |
| * | |
| * while (ul_configs_next_filename(&file_list, ¤t, &name) == 0) | |
| * printf("filename: %s\n", name); | |
| * | |
| * ul_configs_free_list(&file_list); | |
| * | |
| */ | |
| int ul_configs_next_filename(struct list_head *file_list, | |
| struct list_head **current_entry, | |
| char **name); | |
| #endif /* UTIL_LINUX_CONFIGS_H */ |