1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2013 Kay Sievers
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
29 #include <sys/timex.h>
32 #include "boot-loader.h"
36 #include "conf-files.h"
38 static char *loader_fragment_read_title(const char *fragment) {
43 f = fopen(fragment, "re");
47 while (fgets(line, sizeof(line), f) != NULL) {
54 if (line[l-1] == '\n')
64 if (!startswith(s, "title"))
81 int boot_loader_read_entries(struct boot_info *info) {
82 _cleanup_strv_free_ char **files = NULL;
83 static const char *loader_dir[] = { "/boot/loader/entries", NULL};
88 err = conf_files_list_strv(&files, ".conf", NULL, loader_dir);
92 count = strv_length(files);
93 info->loader_entries = new0(struct boot_info_entry, count);
94 if (!info->loader_entries)
97 for (i = 0; i < count; i++) {
98 info->loader_entries[i].title = loader_fragment_read_title(files[i]);
99 info->loader_entries[i].path = strdup(files[i]);
100 if (!info->loader_entries[i].title || !info->loader_entries[i].path) {
101 free(info->loader_entries[i].title);
102 free(info->loader_entries[i].path);
105 info->loader_entries_count++;
111 int boot_loader_find_active_entry(struct boot_info *info, const char *loader_active) {
117 if (info->loader_entries_count == 0)
120 if (asprintf(&fn, "/boot/loader/entries/%s.conf", loader_active) < 0)
123 for (i = 0; i < info->loader_entries_count; i++) {
124 if (streq(fn, info->loader_entries[i].path)) {
125 info->loader_entry_active = i;