9240 lines
254 KiB
Diff
9240 lines
254 KiB
Diff
|
From 446e0e6f0179373ccb2073df62d5552c44a0f36a Mon Sep 17 00:00:00 2001
|
||
|
From: Peter Jones <pjones@redhat.com>
|
||
|
Date: Tue, 18 Aug 2015 10:43:39 -0400
|
||
|
Subject: [PATCH 14/55] Lindent, dammit.
|
||
|
|
||
|
Signed-off-by: Peter Jones <pjones@redhat.com>
|
||
|
---
|
||
|
grubby.c | 8666 ++++++++++++++++++++++++++++--------------------------
|
||
|
1 file changed, 4560 insertions(+), 4106 deletions(-)
|
||
|
|
||
|
diff --git a/grubby.c b/grubby.c
|
||
|
index 70477ba14ee..fe6595b8386 100644
|
||
|
--- a/grubby.c
|
||
|
+++ b/grubby.c
|
||
|
@@ -48,7 +48,7 @@
|
||
|
#define dbgPrintf(format, args...)
|
||
|
#endif
|
||
|
|
||
|
-int debug = 0; /* Currently just for template debugging */
|
||
|
+int debug = 0; /* Currently just for template debugging */
|
||
|
|
||
|
#define _(A) (A)
|
||
|
|
||
|
@@ -70,51 +70,51 @@ char *saved_command_line = NULL;
|
||
|
|
||
|
/* comments get lumped in with indention */
|
||
|
struct lineElement {
|
||
|
- char * item;
|
||
|
- char * indent;
|
||
|
+ char *item;
|
||
|
+ char *indent;
|
||
|
};
|
||
|
|
||
|
-enum lineType_e {
|
||
|
- LT_WHITESPACE = 1 << 0,
|
||
|
- LT_TITLE = 1 << 1,
|
||
|
- LT_KERNEL = 1 << 2,
|
||
|
- LT_INITRD = 1 << 3,
|
||
|
- LT_HYPER = 1 << 4,
|
||
|
- LT_DEFAULT = 1 << 5,
|
||
|
- LT_MBMODULE = 1 << 6,
|
||
|
- LT_ROOT = 1 << 7,
|
||
|
- LT_FALLBACK = 1 << 8,
|
||
|
- LT_KERNELARGS = 1 << 9,
|
||
|
- LT_BOOT = 1 << 10,
|
||
|
- LT_BOOTROOT = 1 << 11,
|
||
|
- LT_LBA = 1 << 12,
|
||
|
- LT_OTHER = 1 << 13,
|
||
|
- LT_GENERIC = 1 << 14,
|
||
|
- LT_ECHO = 1 << 16,
|
||
|
- LT_MENUENTRY = 1 << 17,
|
||
|
- LT_ENTRY_END = 1 << 18,
|
||
|
- LT_SET_VARIABLE = 1 << 19,
|
||
|
- LT_KERNEL_EFI = 1 << 20,
|
||
|
- LT_INITRD_EFI = 1 << 21,
|
||
|
- LT_KERNEL_16 = 1 << 22,
|
||
|
- LT_INITRD_16 = 1 << 23,
|
||
|
- LT_DEVTREE = 1 << 24,
|
||
|
- LT_UNKNOWN = 1 << 25,
|
||
|
+enum lineType_e {
|
||
|
+ LT_WHITESPACE = 1 << 0,
|
||
|
+ LT_TITLE = 1 << 1,
|
||
|
+ LT_KERNEL = 1 << 2,
|
||
|
+ LT_INITRD = 1 << 3,
|
||
|
+ LT_HYPER = 1 << 4,
|
||
|
+ LT_DEFAULT = 1 << 5,
|
||
|
+ LT_MBMODULE = 1 << 6,
|
||
|
+ LT_ROOT = 1 << 7,
|
||
|
+ LT_FALLBACK = 1 << 8,
|
||
|
+ LT_KERNELARGS = 1 << 9,
|
||
|
+ LT_BOOT = 1 << 10,
|
||
|
+ LT_BOOTROOT = 1 << 11,
|
||
|
+ LT_LBA = 1 << 12,
|
||
|
+ LT_OTHER = 1 << 13,
|
||
|
+ LT_GENERIC = 1 << 14,
|
||
|
+ LT_ECHO = 1 << 16,
|
||
|
+ LT_MENUENTRY = 1 << 17,
|
||
|
+ LT_ENTRY_END = 1 << 18,
|
||
|
+ LT_SET_VARIABLE = 1 << 19,
|
||
|
+ LT_KERNEL_EFI = 1 << 20,
|
||
|
+ LT_INITRD_EFI = 1 << 21,
|
||
|
+ LT_KERNEL_16 = 1 << 22,
|
||
|
+ LT_INITRD_16 = 1 << 23,
|
||
|
+ LT_DEVTREE = 1 << 24,
|
||
|
+ LT_UNKNOWN = 1 << 25,
|
||
|
};
|
||
|
|
||
|
struct singleLine {
|
||
|
- char * indent;
|
||
|
- int numElements;
|
||
|
- struct lineElement * elements;
|
||
|
- struct singleLine * next;
|
||
|
- enum lineType_e type;
|
||
|
+ char *indent;
|
||
|
+ int numElements;
|
||
|
+ struct lineElement *elements;
|
||
|
+ struct singleLine *next;
|
||
|
+ enum lineType_e type;
|
||
|
};
|
||
|
|
||
|
struct singleEntry {
|
||
|
- struct singleLine * lines;
|
||
|
- int skip;
|
||
|
- int multiboot;
|
||
|
- struct singleEntry * next;
|
||
|
+ struct singleLine *lines;
|
||
|
+ int skip;
|
||
|
+ int multiboot;
|
||
|
+ struct singleEntry *next;
|
||
|
};
|
||
|
|
||
|
#define GRUBBY_BADIMAGE_OKAY (1 << 0)
|
||
|
@@ -135,1723 +135,1849 @@ struct singleEntry {
|
||
|
#define DEFAULT_SAVED_GRUB2 -3
|
||
|
|
||
|
struct keywordTypes {
|
||
|
- char * key;
|
||
|
- enum lineType_e type;
|
||
|
- char nextChar;
|
||
|
- char separatorChar;
|
||
|
+ char *key;
|
||
|
+ enum lineType_e type;
|
||
|
+ char nextChar;
|
||
|
+ char separatorChar;
|
||
|
};
|
||
|
|
||
|
struct configFileInfo;
|
||
|
|
||
|
-typedef const char *(*findConfigFunc)(struct configFileInfo *);
|
||
|
-typedef const int (*writeLineFunc)(struct configFileInfo *,
|
||
|
- struct singleLine *line);
|
||
|
-typedef char *(*getEnvFunc)(struct configFileInfo *, char *name);
|
||
|
-typedef int (*setEnvFunc)(struct configFileInfo *, char *name, char *value);
|
||
|
+typedef const char *(*findConfigFunc) (struct configFileInfo *);
|
||
|
+typedef const int (*writeLineFunc) (struct configFileInfo *,
|
||
|
+ struct singleLine * line);
|
||
|
+typedef char *(*getEnvFunc) (struct configFileInfo *, char *name);
|
||
|
+typedef int (*setEnvFunc) (struct configFileInfo *, char *name, char *value);
|
||
|
|
||
|
struct configFileInfo {
|
||
|
- char * defaultConfig;
|
||
|
- findConfigFunc findConfig;
|
||
|
- writeLineFunc writeLine;
|
||
|
- getEnvFunc getEnv;
|
||
|
- setEnvFunc setEnv;
|
||
|
- struct keywordTypes * keywords;
|
||
|
- int caseInsensitive;
|
||
|
- int defaultIsIndex;
|
||
|
- int defaultIsVariable;
|
||
|
- int defaultSupportSaved;
|
||
|
- int defaultIsSaved;
|
||
|
- int defaultIsUnquoted;
|
||
|
- enum lineType_e entryStart;
|
||
|
- enum lineType_e entryEnd;
|
||
|
- int needsBootPrefix;
|
||
|
- int argsInQuotes;
|
||
|
- int maxTitleLength;
|
||
|
- int titleBracketed;
|
||
|
- int titlePosition;
|
||
|
- int mbHyperFirst;
|
||
|
- int mbInitRdIsModule;
|
||
|
- int mbConcatArgs;
|
||
|
- int mbAllowExtraInitRds;
|
||
|
- char *envFile;
|
||
|
+ char *defaultConfig;
|
||
|
+ findConfigFunc findConfig;
|
||
|
+ writeLineFunc writeLine;
|
||
|
+ getEnvFunc getEnv;
|
||
|
+ setEnvFunc setEnv;
|
||
|
+ struct keywordTypes *keywords;
|
||
|
+ int caseInsensitive;
|
||
|
+ int defaultIsIndex;
|
||
|
+ int defaultIsVariable;
|
||
|
+ int defaultSupportSaved;
|
||
|
+ int defaultIsSaved;
|
||
|
+ int defaultIsUnquoted;
|
||
|
+ enum lineType_e entryStart;
|
||
|
+ enum lineType_e entryEnd;
|
||
|
+ int needsBootPrefix;
|
||
|
+ int argsInQuotes;
|
||
|
+ int maxTitleLength;
|
||
|
+ int titleBracketed;
|
||
|
+ int titlePosition;
|
||
|
+ int mbHyperFirst;
|
||
|
+ int mbInitRdIsModule;
|
||
|
+ int mbConcatArgs;
|
||
|
+ int mbAllowExtraInitRds;
|
||
|
+ char *envFile;
|
||
|
};
|
||
|
|
||
|
struct keywordTypes grubKeywords[] = {
|
||
|
- { "title", LT_TITLE, ' ' },
|
||
|
- { "root", LT_BOOTROOT, ' ' },
|
||
|
- { "default", LT_DEFAULT, ' ' },
|
||
|
- { "fallback", LT_FALLBACK, ' ' },
|
||
|
- { "kernel", LT_KERNEL, ' ' },
|
||
|
- { "initrd", LT_INITRD, ' ', ' ' },
|
||
|
- { "module", LT_MBMODULE, ' ' },
|
||
|
- { "kernel", LT_HYPER, ' ' },
|
||
|
- { NULL, 0, 0 },
|
||
|
+ {"title", LT_TITLE, ' '},
|
||
|
+ {"root", LT_BOOTROOT, ' '},
|
||
|
+ {"default", LT_DEFAULT, ' '},
|
||
|
+ {"fallback", LT_FALLBACK, ' '},
|
||
|
+ {"kernel", LT_KERNEL, ' '},
|
||
|
+ {"initrd", LT_INITRD, ' ', ' '},
|
||
|
+ {"module", LT_MBMODULE, ' '},
|
||
|
+ {"kernel", LT_HYPER, ' '},
|
||
|
+ {NULL, 0, 0},
|
||
|
};
|
||
|
|
||
|
-const char *grubFindConfig(struct configFileInfo *cfi) {
|
||
|
- static const char *configFiles[] = {
|
||
|
- "/boot/grub/menu.lst",
|
||
|
- "/etc/grub.conf",
|
||
|
- NULL
|
||
|
- };
|
||
|
- static int i = -1;
|
||
|
+const char *grubFindConfig(struct configFileInfo *cfi)
|
||
|
+{
|
||
|
+ static const char *configFiles[] = {
|
||
|
+ "/boot/grub/menu.lst",
|
||
|
+ "/etc/grub.conf",
|
||
|
+ NULL
|
||
|
+ };
|
||
|
+ static int i = -1;
|
||
|
|
||
|
- if (i == -1) {
|
||
|
- for (i = 0; configFiles[i] != NULL; i++) {
|
||
|
- dbgPrintf("Checking \"%s\": ", configFiles[i]);
|
||
|
- if (!access(configFiles[i], R_OK)) {
|
||
|
- dbgPrintf("found\n");
|
||
|
- return configFiles[i];
|
||
|
- }
|
||
|
- dbgPrintf("not found\n");
|
||
|
+ if (i == -1) {
|
||
|
+ for (i = 0; configFiles[i] != NULL; i++) {
|
||
|
+ dbgPrintf("Checking \"%s\": ", configFiles[i]);
|
||
|
+ if (!access(configFiles[i], R_OK)) {
|
||
|
+ dbgPrintf("found\n");
|
||
|
+ return configFiles[i];
|
||
|
+ }
|
||
|
+ dbgPrintf("not found\n");
|
||
|
+ }
|
||
|
}
|
||
|
- }
|
||
|
- return configFiles[i];
|
||
|
+ return configFiles[i];
|
||
|
}
|
||
|
|
||
|
struct configFileInfo grubConfigType = {
|
||
|
- .findConfig = grubFindConfig,
|
||
|
- .keywords = grubKeywords,
|
||
|
- .defaultIsIndex = 1,
|
||
|
- .defaultSupportSaved = 1,
|
||
|
- .entryStart = LT_TITLE,
|
||
|
- .needsBootPrefix = 1,
|
||
|
- .mbHyperFirst = 1,
|
||
|
- .mbInitRdIsModule = 1,
|
||
|
- .mbAllowExtraInitRds = 1,
|
||
|
- .titlePosition = 1,
|
||
|
+ .findConfig = grubFindConfig,
|
||
|
+ .keywords = grubKeywords,
|
||
|
+ .defaultIsIndex = 1,
|
||
|
+ .defaultSupportSaved = 1,
|
||
|
+ .entryStart = LT_TITLE,
|
||
|
+ .needsBootPrefix = 1,
|
||
|
+ .mbHyperFirst = 1,
|
||
|
+ .mbInitRdIsModule = 1,
|
||
|
+ .mbAllowExtraInitRds = 1,
|
||
|
+ .titlePosition = 1,
|
||
|
};
|
||
|
|
||
|
struct keywordTypes grub2Keywords[] = {
|
||
|
- { "menuentry", LT_MENUENTRY, ' ' },
|
||
|
- { "}", LT_ENTRY_END, ' ' },
|
||
|
- { "echo", LT_ECHO, ' ' },
|
||
|
- { "set", LT_SET_VARIABLE,' ', '=' },
|
||
|
- { "root", LT_BOOTROOT, ' ' },
|
||
|
- { "default", LT_DEFAULT, ' ' },
|
||
|
- { "fallback", LT_FALLBACK, ' ' },
|
||
|
- { "linux", LT_KERNEL, ' ' },
|
||
|
- { "linuxefi", LT_KERNEL_EFI, ' ' },
|
||
|
- { "linux16", LT_KERNEL_16, ' ' },
|
||
|
- { "initrd", LT_INITRD, ' ', ' ' },
|
||
|
- { "initrdefi", LT_INITRD_EFI, ' ', ' ' },
|
||
|
- { "initrd16", LT_INITRD_16, ' ', ' ' },
|
||
|
- { "module", LT_MBMODULE, ' ' },
|
||
|
- { "kernel", LT_HYPER, ' ' },
|
||
|
- { "devicetree", LT_DEVTREE, ' ' },
|
||
|
- { NULL, 0, 0 },
|
||
|
+ {"menuentry", LT_MENUENTRY, ' '},
|
||
|
+ {"}", LT_ENTRY_END, ' '},
|
||
|
+ {"echo", LT_ECHO, ' '},
|
||
|
+ {"set", LT_SET_VARIABLE, ' ', '='},
|
||
|
+ {"root", LT_BOOTROOT, ' '},
|
||
|
+ {"default", LT_DEFAULT, ' '},
|
||
|
+ {"fallback", LT_FALLBACK, ' '},
|
||
|
+ {"linux", LT_KERNEL, ' '},
|
||
|
+ {"linuxefi", LT_KERNEL_EFI, ' '},
|
||
|
+ {"linux16", LT_KERNEL_16, ' '},
|
||
|
+ {"initrd", LT_INITRD, ' ', ' '},
|
||
|
+ {"initrdefi", LT_INITRD_EFI, ' ', ' '},
|
||
|
+ {"initrd16", LT_INITRD_16, ' ', ' '},
|
||
|
+ {"module", LT_MBMODULE, ' '},
|
||
|
+ {"kernel", LT_HYPER, ' '},
|
||
|
+ {"devicetree", LT_DEVTREE, ' '},
|
||
|
+ {NULL, 0, 0},
|
||
|
};
|
||
|
|
||
|
-const char *grub2FindConfig(struct configFileInfo *cfi) {
|
||
|
- static const char *configFiles[] = {
|
||
|
- "/etc/grub2-efi.cfg",
|
||
|
- "/etc/grub2.cfg",
|
||
|
- "/boot/grub2/grub.cfg",
|
||
|
- "/boot/grub2-efi/grub.cfg",
|
||
|
- NULL
|
||
|
- };
|
||
|
- static int i = -1;
|
||
|
- static const char *grub_cfg = "/boot/grub/grub.cfg";
|
||
|
- int rc = -1;
|
||
|
+const char *grub2FindConfig(struct configFileInfo *cfi)
|
||
|
+{
|
||
|
+ static const char *configFiles[] = {
|
||
|
+ "/etc/grub2-efi.cfg",
|
||
|
+ "/etc/grub2.cfg",
|
||
|
+ "/boot/grub2/grub.cfg",
|
||
|
+ "/boot/grub2-efi/grub.cfg",
|
||
|
+ NULL
|
||
|
+ };
|
||
|
+ static int i = -1;
|
||
|
+ static const char *grub_cfg = "/boot/grub/grub.cfg";
|
||
|
+ int rc = -1;
|
||
|
|
||
|
- if (i == -1) {
|
||
|
- for (i = 0; configFiles[i] != NULL; i++) {
|
||
|
- dbgPrintf("Checking \"%s\": ", configFiles[i]);
|
||
|
- if ((rc = access(configFiles[i], R_OK))) {
|
||
|
- if (errno == EACCES) {
|
||
|
- printf("Unable to access bootloader configuration file "
|
||
|
- "\"%s\": %m\n", configFiles[i]);
|
||
|
- exit(1);
|
||
|
+ if (i == -1) {
|
||
|
+ for (i = 0; configFiles[i] != NULL; i++) {
|
||
|
+ dbgPrintf("Checking \"%s\": ", configFiles[i]);
|
||
|
+ if ((rc = access(configFiles[i], R_OK))) {
|
||
|
+ if (errno == EACCES) {
|
||
|
+ printf
|
||
|
+ ("Unable to access bootloader configuration file "
|
||
|
+ "\"%s\": %m\n", configFiles[i]);
|
||
|
+ exit(1);
|
||
|
+ }
|
||
|
+ continue;
|
||
|
+ } else {
|
||
|
+ dbgPrintf("found\n");
|
||
|
+ return configFiles[i];
|
||
|
+ }
|
||
|
}
|
||
|
- continue;
|
||
|
- } else {
|
||
|
+ }
|
||
|
+
|
||
|
+ /* Ubuntu renames grub2 to grub, so check for the grub.d directory
|
||
|
+ * that isn't in grub1, and if it exists, return the config file path
|
||
|
+ * that they use. */
|
||
|
+ if (configFiles[i] == NULL && !access("/etc/grub.d/", R_OK)) {
|
||
|
dbgPrintf("found\n");
|
||
|
- return configFiles[i];
|
||
|
- }
|
||
|
+ return grub_cfg;
|
||
|
}
|
||
|
- }
|
||
|
|
||
|
- /* Ubuntu renames grub2 to grub, so check for the grub.d directory
|
||
|
- * that isn't in grub1, and if it exists, return the config file path
|
||
|
- * that they use. */
|
||
|
- if (configFiles[i] == NULL && !access("/etc/grub.d/", R_OK)) {
|
||
|
- dbgPrintf("found\n");
|
||
|
- return grub_cfg;
|
||
|
- }
|
||
|
-
|
||
|
- dbgPrintf("not found\n");
|
||
|
- return configFiles[i];
|
||
|
+ dbgPrintf("not found\n");
|
||
|
+ return configFiles[i];
|
||
|
}
|
||
|
|
||
|
/* kind of hacky. It'll give the first 1024 bytes, ish. */
|
||
|
static char *grub2GetEnv(struct configFileInfo *info, char *name)
|
||
|
{
|
||
|
- static char buf[1025];
|
||
|
- char *s = NULL;
|
||
|
- char *ret = NULL;
|
||
|
- char *envFile = info->envFile ? info->envFile : "/boot/grub2/grubenv";
|
||
|
- int rc = asprintf(&s, "grub2-editenv %s list | grep '^%s='", envFile, name);
|
||
|
+ static char buf[1025];
|
||
|
+ char *s = NULL;
|
||
|
+ char *ret = NULL;
|
||
|
+ char *envFile = info->envFile ? info->envFile : "/boot/grub2/grubenv";
|
||
|
+ int rc =
|
||
|
+ asprintf(&s, "grub2-editenv %s list | grep '^%s='", envFile, name);
|
||
|
|
||
|
- if (rc < 0)
|
||
|
- return NULL;
|
||
|
+ if (rc < 0)
|
||
|
+ return NULL;
|
||
|
|
||
|
- FILE *f = popen(s, "r");
|
||
|
- if (!f)
|
||
|
- goto out;
|
||
|
+ FILE *f = popen(s, "r");
|
||
|
+ if (!f)
|
||
|
+ goto out;
|
||
|
|
||
|
- memset(buf, '\0', sizeof (buf));
|
||
|
- ret = fgets(buf, 1024, f);
|
||
|
- pclose(f);
|
||
|
+ memset(buf, '\0', sizeof(buf));
|
||
|
+ ret = fgets(buf, 1024, f);
|
||
|
+ pclose(f);
|
||
|
|
||
|
- if (ret) {
|
||
|
- ret += strlen(name) + 1;
|
||
|
- ret[strlen(ret) - 1] = '\0';
|
||
|
- }
|
||
|
- dbgPrintf("grub2GetEnv(%s): %s\n", name, ret);
|
||
|
+ if (ret) {
|
||
|
+ ret += strlen(name) + 1;
|
||
|
+ ret[strlen(ret) - 1] = '\0';
|
||
|
+ }
|
||
|
+ dbgPrintf("grub2GetEnv(%s): %s\n", name, ret);
|
||
|
out:
|
||
|
- free(s);
|
||
|
- return ret;
|
||
|
+ free(s);
|
||
|
+ return ret;
|
||
|
}
|
||
|
|
||
|
static int sPopCount(const char *s, const char *c)
|
||
|
{
|
||
|
- int ret = 0;
|
||
|
- if (!s)
|
||
|
- return -1;
|
||
|
- for (int i = 0; s[i] != '\0'; i++)
|
||
|
- for (int j = 0; c[j] != '\0'; j++)
|
||
|
- if (s[i] == c[j])
|
||
|
- ret++;
|
||
|
- return ret;
|
||
|
+ int ret = 0;
|
||
|
+ if (!s)
|
||
|
+ return -1;
|
||
|
+ for (int i = 0; s[i] != '\0'; i++)
|
||
|
+ for (int j = 0; c[j] != '\0'; j++)
|
||
|
+ if (s[i] == c[j])
|
||
|
+ ret++;
|
||
|
+ return ret;
|
||
|
}
|
||
|
|
||
|
static char *shellEscape(const char *s)
|
||
|
{
|
||
|
- int l = strlen(s) + sPopCount(s, "'") * 2;
|
||
|
+ int l = strlen(s) + sPopCount(s, "'") * 2;
|
||
|
|
||
|
- char *ret = calloc(l+1, sizeof (*ret));
|
||
|
- if (!ret)
|
||
|
- return NULL;
|
||
|
- for (int i = 0, j = 0; s[i] != '\0'; i++, j++) {
|
||
|
- if (s[i] == '\'')
|
||
|
- ret[j++] = '\\';
|
||
|
- ret[j] = s[i];
|
||
|
- }
|
||
|
- return ret;
|
||
|
+ char *ret = calloc(l + 1, sizeof(*ret));
|
||
|
+ if (!ret)
|
||
|
+ return NULL;
|
||
|
+ for (int i = 0, j = 0; s[i] != '\0'; i++, j++) {
|
||
|
+ if (s[i] == '\'')
|
||
|
+ ret[j++] = '\\';
|
||
|
+ ret[j] = s[i];
|
||
|
+ }
|
||
|
+ return ret;
|
||
|
}
|
||
|
|
||
|
static void unquote(char *s)
|
||
|
{
|
||
|
- int l = strlen(s);
|
||
|
+ int l = strlen(s);
|
||
|
|
||
|
- if ((s[l-1] == '\'' && s[0] == '\'') || (s[l-1] == '"' && s[0] == '"')) {
|
||
|
- memmove(s, s+1, l-2);
|
||
|
- s[l-2] = '\0';
|
||
|
- }
|
||
|
+ if ((s[l - 1] == '\'' && s[0] == '\'')
|
||
|
+ || (s[l - 1] == '"' && s[0] == '"')) {
|
||
|
+ memmove(s, s + 1, l - 2);
|
||
|
+ s[l - 2] = '\0';
|
||
|
+ }
|
||
|
}
|
||
|
|
||
|
static int grub2SetEnv(struct configFileInfo *info, char *name, char *value)
|
||
|
{
|
||
|
- char *s = NULL;
|
||
|
- int rc = 0;
|
||
|
- char *envFile = info->envFile ? info->envFile : "/boot/grub2/grubenv";
|
||
|
+ char *s = NULL;
|
||
|
+ int rc = 0;
|
||
|
+ char *envFile = info->envFile ? info->envFile : "/boot/grub2/grubenv";
|
||
|
|
||
|
- unquote(value);
|
||
|
- value = shellEscape(value);
|
||
|
- if (!value)
|
||
|
- return -1;
|
||
|
+ unquote(value);
|
||
|
+ value = shellEscape(value);
|
||
|
+ if (!value)
|
||
|
+ return -1;
|
||
|
|
||
|
- rc = asprintf(&s, "grub2-editenv %s set '%s=%s'", envFile, name, value);
|
||
|
- free(value);
|
||
|
- if (rc <0)
|
||
|
- return -1;
|
||
|
+ rc = asprintf(&s, "grub2-editenv %s set '%s=%s'", envFile, name, value);
|
||
|
+ free(value);
|
||
|
+ if (rc < 0)
|
||
|
+ return -1;
|
||
|
|
||
|
- dbgPrintf("grub2SetEnv(%s): %s\n", name, s);
|
||
|
- rc = system(s);
|
||
|
- free(s);
|
||
|
- return rc;
|
||
|
+ dbgPrintf("grub2SetEnv(%s): %s\n", name, s);
|
||
|
+ rc = system(s);
|
||
|
+ free(s);
|
||
|
+ return rc;
|
||
|
}
|
||
|
|
||
|
/* this is a gigantic hack to avoid clobbering grub2 variables... */
|
||
|
static int is_special_grub2_variable(const char *name)
|
||
|
{
|
||
|
- if (!strcmp(name,"\"${next_entry}\""))
|
||
|
- return 1;
|
||
|
- if (!strcmp(name,"\"${prev_saved_entry}\""))
|
||
|
- return 1;
|
||
|
- return 0;
|
||
|
+ if (!strcmp(name, "\"${next_entry}\""))
|
||
|
+ return 1;
|
||
|
+ if (!strcmp(name, "\"${prev_saved_entry}\""))
|
||
|
+ return 1;
|
||
|
+ return 0;
|
||
|
}
|
||
|
|
||
|
-int sizeOfSingleLine(struct singleLine * line) {
|
||
|
- int count = 0;
|
||
|
+int sizeOfSingleLine(struct singleLine *line)
|
||
|
+{
|
||
|
+ int count = 0;
|
||
|
|
||
|
- for (int i = 0; i < line->numElements; i++) {
|
||
|
- int indentSize = 0;
|
||
|
+ for (int i = 0; i < line->numElements; i++) {
|
||
|
+ int indentSize = 0;
|
||
|
|
||
|
- count = count + strlen(line->elements[i].item);
|
||
|
+ count = count + strlen(line->elements[i].item);
|
||
|
|
||
|
- indentSize = strlen(line->elements[i].indent);
|
||
|
- if (indentSize > 0)
|
||
|
- count = count + indentSize;
|
||
|
- else
|
||
|
- /* be extra safe and add room for whitespaces */
|
||
|
- count = count + 1;
|
||
|
- }
|
||
|
+ indentSize = strlen(line->elements[i].indent);
|
||
|
+ if (indentSize > 0)
|
||
|
+ count = count + indentSize;
|
||
|
+ else
|
||
|
+ /* be extra safe and add room for whitespaces */
|
||
|
+ count = count + 1;
|
||
|
+ }
|
||
|
|
||
|
- /* room for trailing terminator */
|
||
|
- count = count + 1;
|
||
|
+ /* room for trailing terminator */
|
||
|
+ count = count + 1;
|
||
|
|
||
|
- return count;
|
||
|
+ return count;
|
||
|
}
|
||
|
|
||
|
static int isquote(char q)
|
||
|
{
|
||
|
- if (q == '\'' || q == '\"')
|
||
|
- return 1;
|
||
|
- return 0;
|
||
|
+ if (q == '\'' || q == '\"')
|
||
|
+ return 1;
|
||
|
+ return 0;
|
||
|
}
|
||
|
|
||
|
-static int iskernel(enum lineType_e type) {
|
||
|
- return (type == LT_KERNEL || type == LT_KERNEL_EFI || type == LT_KERNEL_16);
|
||
|
+static int iskernel(enum lineType_e type)
|
||
|
+{
|
||
|
+ return (type == LT_KERNEL || type == LT_KERNEL_EFI
|
||
|
+ || type == LT_KERNEL_16);
|
||
|
}
|
||
|
|
||
|
-static int isinitrd(enum lineType_e type) {
|
||
|
- return (type == LT_INITRD || type == LT_INITRD_EFI || type == LT_INITRD_16);
|
||
|
+static int isinitrd(enum lineType_e type)
|
||
|
+{
|
||
|
+ return (type == LT_INITRD || type == LT_INITRD_EFI
|
||
|
+ || type == LT_INITRD_16);
|
||
|
}
|
||
|
|
||
|
-char *grub2ExtractTitle(struct singleLine * line) {
|
||
|
- char * current;
|
||
|
- char * current_indent;
|
||
|
- int current_len;
|
||
|
- int current_indent_len;
|
||
|
- int i;
|
||
|
+char *grub2ExtractTitle(struct singleLine *line)
|
||
|
+{
|
||
|
+ char *current;
|
||
|
+ char *current_indent;
|
||
|
+ int current_len;
|
||
|
+ int current_indent_len;
|
||
|
+ int i;
|
||
|
|
||
|
- /* bail out if line does not start with menuentry */
|
||
|
- if (strcmp(line->elements[0].item, "menuentry"))
|
||
|
- return NULL;
|
||
|
+ /* bail out if line does not start with menuentry */
|
||
|
+ if (strcmp(line->elements[0].item, "menuentry"))
|
||
|
+ return NULL;
|
||
|
|
||
|
- i = 1;
|
||
|
- current = line->elements[i].item;
|
||
|
- current_len = strlen(current);
|
||
|
-
|
||
|
- /* if second word is quoted, strip the quotes and return single word */
|
||
|
- if (isquote(*current) && isquote(current[current_len - 1])) {
|
||
|
- char *tmp;
|
||
|
-
|
||
|
- tmp = strdup(current+1);
|
||
|
- if (!tmp)
|
||
|
- return NULL;
|
||
|
- tmp[strlen(tmp)-1] = '\0';
|
||
|
- return tmp;
|
||
|
- }
|
||
|
-
|
||
|
- /* if no quotes, return second word verbatim */
|
||
|
- if (!isquote(*current))
|
||
|
- return current;
|
||
|
-
|
||
|
- /* second element start with a quote, so we have to find the element
|
||
|
- * whose last character is also quote (assuming it's the closing one) */
|
||
|
- int resultMaxSize;
|
||
|
- char * result;
|
||
|
- /* need to ensure that ' does not match " as we search */
|
||
|
- char quote_char = *current;
|
||
|
-
|
||
|
- resultMaxSize = sizeOfSingleLine(line);
|
||
|
- result = malloc(resultMaxSize);
|
||
|
- snprintf(result, resultMaxSize, "%s", ++current);
|
||
|
-
|
||
|
- i++;
|
||
|
- for (; i < line->numElements; ++i) {
|
||
|
+ i = 1;
|
||
|
current = line->elements[i].item;
|
||
|
current_len = strlen(current);
|
||
|
- current_indent = line->elements[i].indent;
|
||
|
- current_indent_len = strlen(current_indent);
|
||
|
-
|
||
|
- strncat(result, current_indent, current_indent_len);
|
||
|
- if (current[current_len-1] != quote_char) {
|
||
|
- strncat(result, current, current_len);
|
||
|
- } else {
|
||
|
- strncat(result, current, current_len - 1);
|
||
|
- break;
|
||
|
+
|
||
|
+ /* if second word is quoted, strip the quotes and return single word */
|
||
|
+ if (isquote(*current) && isquote(current[current_len - 1])) {
|
||
|
+ char *tmp;
|
||
|
+
|
||
|
+ tmp = strdup(current + 1);
|
||
|
+ if (!tmp)
|
||
|
+ return NULL;
|
||
|
+ tmp[strlen(tmp) - 1] = '\0';
|
||
|
+ return tmp;
|
||
|
+ }
|
||
|
+
|
||
|
+ /* if no quotes, return second word verbatim */
|
||
|
+ if (!isquote(*current))
|
||
|
+ return current;
|
||
|
+
|
||
|
+ /* second element start with a quote, so we have to find the element
|
||
|
+ * whose last character is also quote (assuming it's the closing one) */
|
||
|
+ int resultMaxSize;
|
||
|
+ char *result;
|
||
|
+ /* need to ensure that ' does not match " as we search */
|
||
|
+ char quote_char = *current;
|
||
|
+
|
||
|
+ resultMaxSize = sizeOfSingleLine(line);
|
||
|
+ result = malloc(resultMaxSize);
|
||
|
+ snprintf(result, resultMaxSize, "%s", ++current);
|
||
|
+
|
||
|
+ i++;
|
||
|
+ for (; i < line->numElements; ++i) {
|
||
|
+ current = line->elements[i].item;
|
||
|
+ current_len = strlen(current);
|
||
|
+ current_indent = line->elements[i].indent;
|
||
|
+ current_indent_len = strlen(current_indent);
|
||
|
+
|
||
|
+ strncat(result, current_indent, current_indent_len);
|
||
|
+ if (current[current_len - 1] != quote_char) {
|
||
|
+ strncat(result, current, current_len);
|
||
|
+ } else {
|
||
|
+ strncat(result, current, current_len - 1);
|
||
|
+ break;
|
||
|
+ }
|
||
|
}
|
||
|
- }
|
||
|
- return result;
|
||
|
+ return result;
|
||
|
}
|
||
|
|
||
|
struct configFileInfo grub2ConfigType = {
|
||
|
- .findConfig = grub2FindConfig,
|
||
|
- .getEnv = grub2GetEnv,
|
||
|
- .setEnv = grub2SetEnv,
|
||
|
- .keywords = grub2Keywords,
|
||
|
- .defaultIsIndex = 1,
|
||
|
- .defaultSupportSaved = 1,
|
||
|
- .defaultIsVariable = 1,
|
||
|
- .entryStart = LT_MENUENTRY,
|
||
|
- .entryEnd = LT_ENTRY_END,
|
||
|
- .titlePosition = 1,
|
||
|
- .needsBootPrefix = 1,
|
||
|
- .mbHyperFirst = 1,
|
||
|
- .mbInitRdIsModule = 1,
|
||
|
- .mbAllowExtraInitRds = 1,
|
||
|
+ .findConfig = grub2FindConfig,
|
||
|
+ .getEnv = grub2GetEnv,
|
||
|
+ .setEnv = grub2SetEnv,
|
||
|
+ .keywords = grub2Keywords,
|
||
|
+ .defaultIsIndex = 1,
|
||
|
+ .defaultSupportSaved = 1,
|
||
|
+ .defaultIsVariable = 1,
|
||
|
+ .entryStart = LT_MENUENTRY,
|
||
|
+ .entryEnd = LT_ENTRY_END,
|
||
|
+ .titlePosition = 1,
|
||
|
+ .needsBootPrefix = 1,
|
||
|
+ .mbHyperFirst = 1,
|
||
|
+ .mbInitRdIsModule = 1,
|
||
|
+ .mbAllowExtraInitRds = 1,
|
||
|
};
|
||
|
|
||
|
struct keywordTypes yabootKeywords[] = {
|
||
|
- { "label", LT_TITLE, '=' },
|
||
|
- { "root", LT_ROOT, '=' },
|
||
|
- { "default", LT_DEFAULT, '=' },
|
||
|
- { "image", LT_KERNEL, '=' },
|
||
|
- { "bsd", LT_GENERIC, '=' },
|
||
|
- { "macos", LT_GENERIC, '=' },
|
||
|
- { "macosx", LT_GENERIC, '=' },
|
||
|
- { "magicboot", LT_GENERIC, '=' },
|
||
|
- { "darwin", LT_GENERIC, '=' },
|
||
|
- { "timeout", LT_GENERIC, '=' },
|
||
|
- { "install", LT_GENERIC, '=' },
|
||
|
- { "fstype", LT_GENERIC, '=' },
|
||
|
- { "hfstype", LT_GENERIC, '=' },
|
||
|
- { "delay", LT_GENERIC, '=' },
|
||
|
- { "defaultos", LT_GENERIC, '=' },
|
||
|
- { "init-message", LT_GENERIC, '=' },
|
||
|
- { "enablecdboot", LT_GENERIC, ' ' },
|
||
|
- { "enableofboot", LT_GENERIC, ' ' },
|
||
|
- { "enablenetboot", LT_GENERIC, ' ' },
|
||
|
- { "nonvram", LT_GENERIC, ' ' },
|
||
|
- { "hide", LT_GENERIC, ' ' },
|
||
|
- { "protect", LT_GENERIC, ' ' },
|
||
|
- { "nobless", LT_GENERIC, ' ' },
|
||
|
- { "nonvram", LT_GENERIC, ' ' },
|
||
|
- { "brokenosx", LT_GENERIC, ' ' },
|
||
|
- { "usemount", LT_GENERIC, ' ' },
|
||
|
- { "mntpoint", LT_GENERIC, '=' },
|
||
|
- { "partition", LT_GENERIC, '=' },
|
||
|
- { "device", LT_GENERIC, '=' },
|
||
|
- { "fstype", LT_GENERIC, '=' },
|
||
|
- { "initrd", LT_INITRD, '=', ';' },
|
||
|
- { "append", LT_KERNELARGS, '=' },
|
||
|
- { "boot", LT_BOOT, '=' },
|
||
|
- { "lba", LT_LBA, ' ' },
|
||
|
- { NULL, 0, 0 },
|
||
|
+ {"label", LT_TITLE, '='},
|
||
|
+ {"root", LT_ROOT, '='},
|
||
|
+ {"default", LT_DEFAULT, '='},
|
||
|
+ {"image", LT_KERNEL, '='},
|
||
|
+ {"bsd", LT_GENERIC, '='},
|
||
|
+ {"macos", LT_GENERIC, '='},
|
||
|
+ {"macosx", LT_GENERIC, '='},
|
||
|
+ {"magicboot", LT_GENERIC, '='},
|
||
|
+ {"darwin", LT_GENERIC, '='},
|
||
|
+ {"timeout", LT_GENERIC, '='},
|
||
|
+ {"install", LT_GENERIC, '='},
|
||
|
+ {"fstype", LT_GENERIC, '='},
|
||
|
+ {"hfstype", LT_GENERIC, '='},
|
||
|
+ {"delay", LT_GENERIC, '='},
|
||
|
+ {"defaultos", LT_GENERIC, '='},
|
||
|
+ {"init-message", LT_GENERIC, '='},
|
||
|
+ {"enablecdboot", LT_GENERIC, ' '},
|
||
|
+ {"enableofboot", LT_GENERIC, ' '},
|
||
|
+ {"enablenetboot", LT_GENERIC, ' '},
|
||
|
+ {"nonvram", LT_GENERIC, ' '},
|
||
|
+ {"hide", LT_GENERIC, ' '},
|
||
|
+ {"protect", LT_GENERIC, ' '},
|
||
|
+ {"nobless", LT_GENERIC, ' '},
|
||
|
+ {"nonvram", LT_GENERIC, ' '},
|
||
|
+ {"brokenosx", LT_GENERIC, ' '},
|
||
|
+ {"usemount", LT_GENERIC, ' '},
|
||
|
+ {"mntpoint", LT_GENERIC, '='},
|
||
|
+ {"partition", LT_GENERIC, '='},
|
||
|
+ {"device", LT_GENERIC, '='},
|
||
|
+ {"fstype", LT_GENERIC, '='},
|
||
|
+ {"initrd", LT_INITRD, '=', ';'},
|
||
|
+ {"append", LT_KERNELARGS, '='},
|
||
|
+ {"boot", LT_BOOT, '='},
|
||
|
+ {"lba", LT_LBA, ' '},
|
||
|
+ {NULL, 0, 0},
|
||
|
};
|
||
|
|
||
|
struct keywordTypes liloKeywords[] = {
|
||
|
- { "label", LT_TITLE, '=' },
|
||
|
- { "root", LT_ROOT, '=' },
|
||
|
- { "default", LT_DEFAULT, '=' },
|
||
|
- { "image", LT_KERNEL, '=' },
|
||
|
- { "other", LT_OTHER, '=' },
|
||
|
- { "initrd", LT_INITRD, '=' },
|
||
|
- { "append", LT_KERNELARGS, '=' },
|
||
|
- { "boot", LT_BOOT, '=' },
|
||
|
- { "lba", LT_LBA, ' ' },
|
||
|
- { NULL, 0, 0 },
|
||
|
+ {"label", LT_TITLE, '='},
|
||
|
+ {"root", LT_ROOT, '='},
|
||
|
+ {"default", LT_DEFAULT, '='},
|
||
|
+ {"image", LT_KERNEL, '='},
|
||
|
+ {"other", LT_OTHER, '='},
|
||
|
+ {"initrd", LT_INITRD, '='},
|
||
|
+ {"append", LT_KERNELARGS, '='},
|
||
|
+ {"boot", LT_BOOT, '='},
|
||
|
+ {"lba", LT_LBA, ' '},
|
||
|
+ {NULL, 0, 0},
|
||
|
};
|
||
|
|
||
|
struct keywordTypes eliloKeywords[] = {
|
||
|
- { "label", LT_TITLE, '=' },
|
||
|
- { "root", LT_ROOT, '=' },
|
||
|
- { "default", LT_DEFAULT, '=' },
|
||
|
- { "image", LT_KERNEL, '=' },
|
||
|
- { "initrd", LT_INITRD, '=' },
|
||
|
- { "append", LT_KERNELARGS, '=' },
|
||
|
- { "vmm", LT_HYPER, '=' },
|
||
|
- { NULL, 0, 0 },
|
||
|
+ {"label", LT_TITLE, '='},
|
||
|
+ {"root", LT_ROOT, '='},
|
||
|
+ {"default", LT_DEFAULT, '='},
|
||
|
+ {"image", LT_KERNEL, '='},
|
||
|
+ {"initrd", LT_INITRD, '='},
|
||
|
+ {"append", LT_KERNELARGS, '='},
|
||
|
+ {"vmm", LT_HYPER, '='},
|
||
|
+ {NULL, 0, 0},
|
||
|
};
|
||
|
|
||
|
struct keywordTypes siloKeywords[] = {
|
||
|
- { "label", LT_TITLE, '=' },
|
||
|
- { "root", LT_ROOT, '=' },
|
||
|
- { "default", LT_DEFAULT, '=' },
|
||
|
- { "image", LT_KERNEL, '=' },
|
||
|
- { "other", LT_OTHER, '=' },
|
||
|
- { "initrd", LT_INITRD, '=' },
|
||
|
- { "append", LT_KERNELARGS, '=' },
|
||
|
- { "boot", LT_BOOT, '=' },
|
||
|
- { NULL, 0, 0 },
|
||
|
+ {"label", LT_TITLE, '='},
|
||
|
+ {"root", LT_ROOT, '='},
|
||
|
+ {"default", LT_DEFAULT, '='},
|
||
|
+ {"image", LT_KERNEL, '='},
|
||
|
+ {"other", LT_OTHER, '='},
|
||
|
+ {"initrd", LT_INITRD, '='},
|
||
|
+ {"append", LT_KERNELARGS, '='},
|
||
|
+ {"boot", LT_BOOT, '='},
|
||
|
+ {NULL, 0, 0},
|
||
|
};
|
||
|
|
||
|
struct keywordTypes ziplKeywords[] = {
|
||
|
- { "target", LT_BOOTROOT, '=' },
|
||
|
- { "image", LT_KERNEL, '=' },
|
||
|
- { "ramdisk", LT_INITRD, '=' },
|
||
|
- { "parameters", LT_KERNELARGS, '=' },
|
||
|
- { "default", LT_DEFAULT, '=' },
|
||
|
- { NULL, 0, 0 },
|
||
|
+ {"target", LT_BOOTROOT, '='},
|
||
|
+ {"image", LT_KERNEL, '='},
|
||
|
+ {"ramdisk", LT_INITRD, '='},
|
||
|
+ {"parameters", LT_KERNELARGS, '='},
|
||
|
+ {"default", LT_DEFAULT, '='},
|
||
|
+ {NULL, 0, 0},
|
||
|
};
|
||
|
|
||
|
struct keywordTypes extlinuxKeywords[] = {
|
||
|
- { "label", LT_TITLE, ' ' },
|
||
|
- { "root", LT_ROOT, ' ' },
|
||
|
- { "default", LT_DEFAULT, ' ' },
|
||
|
- { "kernel", LT_KERNEL, ' ' },
|
||
|
- { "initrd", LT_INITRD, ' ', ',' },
|
||
|
- { "append", LT_KERNELARGS, ' ' },
|
||
|
- { "prompt", LT_UNKNOWN, ' ' },
|
||
|
- { "fdt", LT_DEVTREE, ' ' },
|
||
|
- { "fdtdir", LT_DEVTREE, ' ' },
|
||
|
- { NULL, 0, 0 },
|
||
|
+ {"label", LT_TITLE, ' '},
|
||
|
+ {"root", LT_ROOT, ' '},
|
||
|
+ {"default", LT_DEFAULT, ' '},
|
||
|
+ {"kernel", LT_KERNEL, ' '},
|
||
|
+ {"initrd", LT_INITRD, ' ', ','},
|
||
|
+ {"append", LT_KERNELARGS, ' '},
|
||
|
+ {"prompt", LT_UNKNOWN, ' '},
|
||
|
+ {"fdt", LT_DEVTREE, ' '},
|
||
|
+ {"fdtdir", LT_DEVTREE, ' '},
|
||
|
+ {NULL, 0, 0},
|
||
|
};
|
||
|
+
|
||
|
int useextlinuxmenu;
|
||
|
struct configFileInfo eliloConfigType = {
|
||
|
- .defaultConfig = "/boot/efi/EFI/redhat/elilo.conf",
|
||
|
- .keywords = eliloKeywords,
|
||
|
- .entryStart = LT_KERNEL,
|
||
|
- .needsBootPrefix = 1,
|
||
|
- .argsInQuotes = 1,
|
||
|
- .mbConcatArgs = 1,
|
||
|
- .titlePosition = 1,
|
||
|
+ .defaultConfig = "/boot/efi/EFI/redhat/elilo.conf",
|
||
|
+ .keywords = eliloKeywords,
|
||
|
+ .entryStart = LT_KERNEL,
|
||
|
+ .needsBootPrefix = 1,
|
||
|
+ .argsInQuotes = 1,
|
||
|
+ .mbConcatArgs = 1,
|
||
|
+ .titlePosition = 1,
|
||
|
};
|
||
|
|
||
|
struct configFileInfo liloConfigType = {
|
||
|
- .defaultConfig = "/etc/lilo.conf",
|
||
|
- .keywords = liloKeywords,
|
||
|
- .entryStart = LT_KERNEL,
|
||
|
- .argsInQuotes = 1,
|
||
|
- .maxTitleLength = 15,
|
||
|
- .titlePosition = 1,
|
||
|
+ .defaultConfig = "/etc/lilo.conf",
|
||
|
+ .keywords = liloKeywords,
|
||
|
+ .entryStart = LT_KERNEL,
|
||
|
+ .argsInQuotes = 1,
|
||
|
+ .maxTitleLength = 15,
|
||
|
+ .titlePosition = 1,
|
||
|
};
|
||
|
|
||
|
struct configFileInfo yabootConfigType = {
|
||
|
- .defaultConfig = "/etc/yaboot.conf",
|
||
|
- .keywords = yabootKeywords,
|
||
|
- .entryStart = LT_KERNEL,
|
||
|
- .needsBootPrefix = 1,
|
||
|
- .argsInQuotes = 1,
|
||
|
- .maxTitleLength = 15,
|
||
|
- .mbAllowExtraInitRds = 1,
|
||
|
- .titlePosition = 1,
|
||
|
+ .defaultConfig = "/etc/yaboot.conf",
|
||
|
+ .keywords = yabootKeywords,
|
||
|
+ .entryStart = LT_KERNEL,
|
||
|
+ .needsBootPrefix = 1,
|
||
|
+ .argsInQuotes = 1,
|
||
|
+ .maxTitleLength = 15,
|
||
|
+ .mbAllowExtraInitRds = 1,
|
||
|
+ .titlePosition = 1,
|
||
|
};
|
||
|
|
||
|
struct configFileInfo siloConfigType = {
|
||
|
- .defaultConfig = "/etc/silo.conf",
|
||
|
- .keywords = siloKeywords,
|
||
|
- .entryStart = LT_KERNEL,
|
||
|
- .needsBootPrefix = 1,
|
||
|
- .argsInQuotes = 1,
|
||
|
- .maxTitleLength = 15,
|
||
|
- .titlePosition = 1,
|
||
|
+ .defaultConfig = "/etc/silo.conf",
|
||
|
+ .keywords = siloKeywords,
|
||
|
+ .entryStart = LT_KERNEL,
|
||
|
+ .needsBootPrefix = 1,
|
||
|
+ .argsInQuotes = 1,
|
||
|
+ .maxTitleLength = 15,
|
||
|
+ .titlePosition = 1,
|
||
|
};
|
||
|
|
||
|
struct configFileInfo ziplConfigType = {
|
||
|
- .defaultConfig = "/etc/zipl.conf",
|
||
|
- .keywords = ziplKeywords,
|
||
|
- .entryStart = LT_TITLE,
|
||
|
- .argsInQuotes = 1,
|
||
|
- .titleBracketed = 1,
|
||
|
+ .defaultConfig = "/etc/zipl.conf",
|
||
|
+ .keywords = ziplKeywords,
|
||
|
+ .entryStart = LT_TITLE,
|
||
|
+ .argsInQuotes = 1,
|
||
|
+ .titleBracketed = 1,
|
||
|
};
|
||
|
|
||
|
struct configFileInfo extlinuxConfigType = {
|
||
|
- .defaultConfig = "/boot/extlinux/extlinux.conf",
|
||
|
- .keywords = extlinuxKeywords,
|
||
|
- .caseInsensitive = 1,
|
||
|
- .entryStart = LT_TITLE,
|
||
|
- .needsBootPrefix = 1,
|
||
|
- .maxTitleLength = 255,
|
||
|
- .mbAllowExtraInitRds = 1,
|
||
|
- .defaultIsUnquoted = 1,
|
||
|
- .titlePosition = 1,
|
||
|
+ .defaultConfig = "/boot/extlinux/extlinux.conf",
|
||
|
+ .keywords = extlinuxKeywords,
|
||
|
+ .caseInsensitive = 1,
|
||
|
+ .entryStart = LT_TITLE,
|
||
|
+ .needsBootPrefix = 1,
|
||
|
+ .maxTitleLength = 255,
|
||
|
+ .mbAllowExtraInitRds = 1,
|
||
|
+ .defaultIsUnquoted = 1,
|
||
|
+ .titlePosition = 1,
|
||
|
};
|
||
|
|
||
|
struct grubConfig {
|
||
|
- struct singleLine * theLines;
|
||
|
- struct singleEntry * entries;
|
||
|
- char * primaryIndent;
|
||
|
- char * secondaryIndent;
|
||
|
- int defaultImage; /* -1 if none specified -- this value is
|
||
|
- * written out, overriding original */
|
||
|
- int fallbackImage; /* just like defaultImage */
|
||
|
- int flags;
|
||
|
- struct configFileInfo * cfi;
|
||
|
+ struct singleLine *theLines;
|
||
|
+ struct singleEntry *entries;
|
||
|
+ char *primaryIndent;
|
||
|
+ char *secondaryIndent;
|
||
|
+ int defaultImage; /* -1 if none specified -- this value is
|
||
|
+ * written out, overriding original */
|
||
|
+ int fallbackImage; /* just like defaultImage */
|
||
|
+ int flags;
|
||
|
+ struct configFileInfo *cfi;
|
||
|
};
|
||
|
|
||
|
blkid_cache blkid;
|
||
|
|
||
|
-struct singleEntry * findEntryByIndex(struct grubConfig * cfg, int index);
|
||
|
-struct singleEntry * findEntryByPath(struct grubConfig * cfg,
|
||
|
- const char * path, const char * prefix,
|
||
|
- int * index);
|
||
|
-struct singleEntry * findEntryByTitle(struct grubConfig * cfg, char *title,
|
||
|
- int * index);
|
||
|
-static int readFile(int fd, char ** bufPtr);
|
||
|
-static void lineInit(struct singleLine * line);
|
||
|
-struct singleLine * lineDup(struct singleLine * line);
|
||
|
-static void lineFree(struct singleLine * line);
|
||
|
-static int lineWrite(FILE * out, struct singleLine * line,
|
||
|
- struct configFileInfo * cfi);
|
||
|
-static int getNextLine(char ** bufPtr, struct singleLine * line,
|
||
|
- struct configFileInfo * cfi);
|
||
|
-static char * getRootSpecifier(char * str);
|
||
|
-static void requote(struct singleLine *line, struct configFileInfo * cfi);
|
||
|
-static void insertElement(struct singleLine * line,
|
||
|
- const char * item, int insertHere,
|
||
|
- struct configFileInfo * cfi);
|
||
|
-static void removeElement(struct singleLine * line, int removeHere);
|
||
|
-static struct keywordTypes * getKeywordByType(enum lineType_e type,
|
||
|
- struct configFileInfo * cfi);
|
||
|
-static enum lineType_e getTypeByKeyword(char * keyword,
|
||
|
- struct configFileInfo * cfi);
|
||
|
-static struct singleLine * getLineByType(enum lineType_e type,
|
||
|
- struct singleLine * line);
|
||
|
-static int checkForExtLinux(struct grubConfig * config);
|
||
|
-struct singleLine * addLineTmpl(struct singleEntry * entry,
|
||
|
- struct singleLine * tmplLine,
|
||
|
- struct singleLine * prevLine,
|
||
|
- const char * val,
|
||
|
- struct configFileInfo * cfi);
|
||
|
-struct singleLine * addLine(struct singleEntry * entry,
|
||
|
- struct configFileInfo * cfi,
|
||
|
- enum lineType_e type, char * defaultIndent,
|
||
|
- const char * val);
|
||
|
+struct singleEntry *findEntryByIndex(struct grubConfig *cfg, int index);
|
||
|
+struct singleEntry *findEntryByPath(struct grubConfig *cfg,
|
||
|
+ const char *path, const char *prefix,
|
||
|
+ int *index);
|
||
|
+struct singleEntry *findEntryByTitle(struct grubConfig *cfg, char *title,
|
||
|
+ int *index);
|
||
|
+static int readFile(int fd, char **bufPtr);
|
||
|
+static void lineInit(struct singleLine *line);
|
||
|
+struct singleLine *lineDup(struct singleLine *line);
|
||
|
+static void lineFree(struct singleLine *line);
|
||
|
+static int lineWrite(FILE * out, struct singleLine *line,
|
||
|
+ struct configFileInfo *cfi);
|
||
|
+static int getNextLine(char **bufPtr, struct singleLine *line,
|
||
|
+ struct configFileInfo *cfi);
|
||
|
+static char *getRootSpecifier(char *str);
|
||
|
+static void requote(struct singleLine *line, struct configFileInfo *cfi);
|
||
|
+static void insertElement(struct singleLine *line,
|
||
|
+ const char *item, int insertHere,
|
||
|
+ struct configFileInfo *cfi);
|
||
|
+static void removeElement(struct singleLine *line, int removeHere);
|
||
|
+static struct keywordTypes *getKeywordByType(enum lineType_e type,
|
||
|
+ struct configFileInfo *cfi);
|
||
|
+static enum lineType_e getTypeByKeyword(char *keyword,
|
||
|
+ struct configFileInfo *cfi);
|
||
|
+static struct singleLine *getLineByType(enum lineType_e type,
|
||
|
+ struct singleLine *line);
|
||
|
+static int checkForExtLinux(struct grubConfig *config);
|
||
|
+struct singleLine *addLineTmpl(struct singleEntry *entry,
|
||
|
+ struct singleLine *tmplLine,
|
||
|
+ struct singleLine *prevLine,
|
||
|
+ const char *val, struct configFileInfo *cfi);
|
||
|
+struct singleLine *addLine(struct singleEntry *entry,
|
||
|
+ struct configFileInfo *cfi,
|
||
|
+ enum lineType_e type, char *defaultIndent,
|
||
|
+ const char *val);
|
||
|
|
||
|
-static char * sdupprintf(const char *format, ...)
|
||
|
+static char *sdupprintf(const char *format, ...)
|
||
|
#ifdef __GNUC__
|
||
|
- __attribute__ ((format (printf, 1, 2)));
|
||
|
+ __attribute__ ((format(printf, 1, 2)));
|
||
|
#else
|
||
|
- ;
|
||
|
+;
|
||
|
#endif
|
||
|
|
||
|
-static char * sdupprintf(const char *format, ...) {
|
||
|
- char *buf = NULL;
|
||
|
- char c;
|
||
|
- va_list args;
|
||
|
- size_t size = 0;
|
||
|
- va_start(args, format);
|
||
|
-
|
||
|
- /* XXX requires C99 vsnprintf behavior */
|
||
|
- size = vsnprintf(&c, 1, format, args) + 1;
|
||
|
- if (size == -1) {
|
||
|
- printf("ERROR: vsnprintf behavior is not C99\n");
|
||
|
- abort();
|
||
|
- }
|
||
|
+static char *sdupprintf(const char *format, ...)
|
||
|
+{
|
||
|
+ char *buf = NULL;
|
||
|
+ char c;
|
||
|
+ va_list args;
|
||
|
+ size_t size = 0;
|
||
|
+ va_start(args, format);
|
||
|
|
||
|
- va_end(args);
|
||
|
- va_start(args, format);
|
||
|
+ /* XXX requires C99 vsnprintf behavior */
|
||
|
+ size = vsnprintf(&c, 1, format, args) + 1;
|
||
|
+ if (size == -1) {
|
||
|
+ printf("ERROR: vsnprintf behavior is not C99\n");
|
||
|
+ abort();
|
||
|
+ }
|
||
|
|
||
|
- buf = malloc(size);
|
||
|
- if (buf == NULL)
|
||
|
- return NULL;
|
||
|
- vsnprintf(buf, size, format, args);
|
||
|
- va_end (args);
|
||
|
+ va_end(args);
|
||
|
+ va_start(args, format);
|
||
|
|
||
|
- return buf;
|
||
|
+ buf = malloc(size);
|
||
|
+ if (buf == NULL)
|
||
|
+ return NULL;
|
||
|
+ vsnprintf(buf, size, format, args);
|
||
|
+ va_end(args);
|
||
|
+
|
||
|
+ return buf;
|
||
|
}
|
||
|
|
||
|
static enum lineType_e preferredLineType(enum lineType_e type,
|
||
|
- struct configFileInfo *cfi) {
|
||
|
- if (isEfi && cfi == &grub2ConfigType) {
|
||
|
- switch (type) {
|
||
|
- case LT_KERNEL:
|
||
|
- return isEfiOnly ? LT_KERNEL : LT_KERNEL_EFI;
|
||
|
- case LT_INITRD:
|
||
|
- return isEfiOnly ? LT_INITRD : LT_INITRD_EFI;
|
||
|
- default:
|
||
|
- return type;
|
||
|
- }
|
||
|
+ struct configFileInfo *cfi)
|
||
|
+{
|
||
|
+ if (isEfi && cfi == &grub2ConfigType) {
|
||
|
+ switch (type) {
|
||
|
+ case LT_KERNEL:
|
||
|
+ return isEfiOnly ? LT_KERNEL : LT_KERNEL_EFI;
|
||
|
+ case LT_INITRD:
|
||
|
+ return isEfiOnly ? LT_INITRD : LT_INITRD_EFI;
|
||
|
+ default:
|
||
|
+ return type;
|
||
|
+ }
|
||
|
#if defined(__i386__) || defined(__x86_64__)
|
||
|
- } else if (cfi == &grub2ConfigType) {
|
||
|
- switch (type) {
|
||
|
- case LT_KERNEL:
|
||
|
- return LT_KERNEL_16;
|
||
|
- case LT_INITRD:
|
||
|
- return LT_INITRD_16;
|
||
|
- default:
|
||
|
- return type;
|
||
|
- }
|
||
|
+ } else if (cfi == &grub2ConfigType) {
|
||
|
+ switch (type) {
|
||
|
+ case LT_KERNEL:
|
||
|
+ return LT_KERNEL_16;
|
||
|
+ case LT_INITRD:
|
||
|
+ return LT_INITRD_16;
|
||
|
+ default:
|
||
|
+ return type;
|
||
|
+ }
|
||
|
#endif
|
||
|
- }
|
||
|
- return type;
|
||
|
+ }
|
||
|
+ return type;
|
||
|
}
|
||
|
|
||
|
-static struct keywordTypes * getKeywordByType(enum lineType_e type,
|
||
|
- struct configFileInfo * cfi) {
|
||
|
- for (struct keywordTypes *kw = cfi->keywords; kw->key; kw++) {
|
||
|
- if (kw->type == type)
|
||
|
- return kw;
|
||
|
- }
|
||
|
- return NULL;
|
||
|
+static struct keywordTypes *getKeywordByType(enum lineType_e type,
|
||
|
+ struct configFileInfo *cfi)
|
||
|
+{
|
||
|
+ for (struct keywordTypes * kw = cfi->keywords; kw->key; kw++) {
|
||
|
+ if (kw->type == type)
|
||
|
+ return kw;
|
||
|
+ }
|
||
|
+ return NULL;
|
||
|
}
|
||
|
|
||
|
-static char *getKeyByType(enum lineType_e type, struct configFileInfo * cfi) {
|
||
|
- struct keywordTypes *kt = getKeywordByType(type, cfi);
|
||
|
- if (kt)
|
||
|
- return kt->key;
|
||
|
- return "unknown";
|
||
|
+static char *getKeyByType(enum lineType_e type, struct configFileInfo *cfi)
|
||
|
+{
|
||
|
+ struct keywordTypes *kt = getKeywordByType(type, cfi);
|
||
|
+ if (kt)
|
||
|
+ return kt->key;
|
||
|
+ return "unknown";
|
||
|
}
|
||
|
|
||
|
-static char * getpathbyspec(char *device) {
|
||
|
- if (!blkid)
|
||
|
- blkid_get_cache(&blkid, NULL);
|
||
|
+static char *getpathbyspec(char *device)
|
||
|
+{
|
||