60 |
|
|
61 |
int isEfi = 0; |
int isEfi = 0; |
62 |
|
|
63 |
|
#if defined(__aarch64__) |
64 |
|
#define isEfiOnly 1 |
65 |
|
#else |
66 |
|
#define isEfiOnly 0 |
67 |
|
#endif |
68 |
|
|
69 |
char *saved_command_line = NULL; |
char *saved_command_line = NULL; |
70 |
|
|
71 |
/* comments get lumped in with indention */ |
/* comments get lumped in with indention */ |
96 |
LT_SET_VARIABLE = 1 << 19, |
LT_SET_VARIABLE = 1 << 19, |
97 |
LT_KERNEL_EFI = 1 << 20, |
LT_KERNEL_EFI = 1 << 20, |
98 |
LT_INITRD_EFI = 1 << 21, |
LT_INITRD_EFI = 1 << 21, |
99 |
LT_UNKNOWN = 1 << 22, |
LT_KERNEL_16 = 1 << 22, |
100 |
|
LT_INITRD_16 = 1 << 23, |
101 |
|
LT_DEVTREE = 1 << 24, |
102 |
|
LT_UNKNOWN = 1 << 25, |
103 |
}; |
}; |
104 |
|
|
105 |
struct singleLine { |
struct singleLine { |
128 |
#define NEED_ARGS (1 << 3) |
#define NEED_ARGS (1 << 3) |
129 |
#define NEED_MB (1 << 4) |
#define NEED_MB (1 << 4) |
130 |
#define NEED_END (1 << 5) |
#define NEED_END (1 << 5) |
131 |
|
#define NEED_DEVTREE (1 << 6) |
132 |
|
|
133 |
#define MAIN_DEFAULT (1 << 0) |
#define MAIN_DEFAULT (1 << 0) |
134 |
#define DEFAULT_SAVED -2 |
#define DEFAULT_SAVED -2 |
161 |
int defaultIsVariable; |
int defaultIsVariable; |
162 |
int defaultSupportSaved; |
int defaultSupportSaved; |
163 |
int defaultIsSaved; |
int defaultIsSaved; |
164 |
|
int defaultIsUnquoted; |
165 |
enum lineType_e entryStart; |
enum lineType_e entryStart; |
166 |
enum lineType_e entryEnd; |
enum lineType_e entryEnd; |
167 |
int needsBootPrefix; |
int needsBootPrefix; |
193 |
"/boot/grub/grub.conf", |
"/boot/grub/grub.conf", |
194 |
"/boot/grub/menu.lst", |
"/boot/grub/menu.lst", |
195 |
"/etc/grub.conf", |
"/etc/grub.conf", |
196 |
|
"/boot/grub2/grub.cfg", |
197 |
|
"/boot/grub2-efi/grub.cfg", |
198 |
NULL |
NULL |
199 |
}; |
}; |
200 |
static int i = -1; |
static int i = -1; |
222 |
.mbHyperFirst = 1, |
.mbHyperFirst = 1, |
223 |
.mbInitRdIsModule = 1, |
.mbInitRdIsModule = 1, |
224 |
.mbAllowExtraInitRds = 1, |
.mbAllowExtraInitRds = 1, |
225 |
|
.titlePosition = 1, |
226 |
}; |
}; |
227 |
|
|
228 |
struct keywordTypes grub2Keywords[] = { |
struct keywordTypes grub2Keywords[] = { |
235 |
{ "fallback", LT_FALLBACK, ' ' }, |
{ "fallback", LT_FALLBACK, ' ' }, |
236 |
{ "linux", LT_KERNEL, ' ' }, |
{ "linux", LT_KERNEL, ' ' }, |
237 |
{ "linuxefi", LT_KERNEL_EFI, ' ' }, |
{ "linuxefi", LT_KERNEL_EFI, ' ' }, |
238 |
|
{ "linux16", LT_KERNEL_16, ' ' }, |
239 |
{ "initrd", LT_INITRD, ' ', ' ' }, |
{ "initrd", LT_INITRD, ' ', ' ' }, |
240 |
{ "initrdefi", LT_INITRD_EFI, ' ', ' ' }, |
{ "initrdefi", LT_INITRD_EFI, ' ', ' ' }, |
241 |
|
{ "initrd16", LT_INITRD_16, ' ', ' ' }, |
242 |
{ "module", LT_MBMODULE, ' ' }, |
{ "module", LT_MBMODULE, ' ' }, |
243 |
{ "kernel", LT_HYPER, ' ' }, |
{ "kernel", LT_HYPER, ' ' }, |
244 |
|
{ "devicetree", LT_DEVTREE, ' ' }, |
245 |
{ NULL, 0, 0 }, |
{ NULL, 0, 0 }, |
246 |
}; |
}; |
247 |
|
|
290 |
static char buf[1025]; |
static char buf[1025]; |
291 |
char *s = NULL; |
char *s = NULL; |
292 |
char *ret = NULL; |
char *ret = NULL; |
293 |
char *envFile = info->envFile ? info->envFile : "/boot/grub2/grubenv"; |
char *envFile = info->envFile ? info->envFile : "/boot/grub/grubenv"; |
294 |
int rc = asprintf(&s, "grub2-editenv %s list | grep '^%s='", envFile, name); |
int rc = asprintf(&s, "grub-editenv %s list | grep '^%s='", envFile, name); |
295 |
|
|
296 |
if (rc < 0) |
if (rc < 0) |
297 |
return NULL; |
return NULL; |
355 |
{ |
{ |
356 |
char *s = NULL; |
char *s = NULL; |
357 |
int rc = 0; |
int rc = 0; |
358 |
char *envFile = info->envFile ? info->envFile : "/boot/grub2/grubenv"; |
char *envFile = info->envFile ? info->envFile : "/boot/grub/grubenv"; |
359 |
|
|
360 |
unquote(value); |
unquote(value); |
361 |
value = shellEscape(value); |
value = shellEscape(value); |
362 |
if (!value) |
if (!value) |
363 |
return -1; |
return -1; |
364 |
|
|
365 |
rc = asprintf(&s, "grub2-editenv %s set '%s=%s'", envFile, name, value); |
rc = asprintf(&s, "grub-editenv %s set '%s=%s'", envFile, name, value); |
366 |
free(value); |
free(value); |
367 |
if (rc <0) |
if (rc <0) |
368 |
return -1; |
return -1; |
413 |
} |
} |
414 |
|
|
415 |
static int iskernel(enum lineType_e type) { |
static int iskernel(enum lineType_e type) { |
416 |
return (type == LT_KERNEL || type == LT_KERNEL_EFI); |
return (type == LT_KERNEL || type == LT_KERNEL_EFI || type == LT_KERNEL_16); |
417 |
} |
} |
418 |
|
|
419 |
static int isinitrd(enum lineType_e type) { |
static int isinitrd(enum lineType_e type) { |
420 |
return (type == LT_INITRD || type == LT_INITRD_EFI); |
return (type == LT_INITRD || type == LT_INITRD_EFI || type == LT_INITRD_16); |
421 |
} |
} |
422 |
|
|
423 |
char *grub2ExtractTitle(struct singleLine * line) { |
char *grub2ExtractTitle(struct singleLine * line) { |
429 |
|
|
430 |
/* bail out if line does not start with menuentry */ |
/* bail out if line does not start with menuentry */ |
431 |
if (strcmp(line->elements[0].item, "menuentry")) |
if (strcmp(line->elements[0].item, "menuentry")) |
432 |
return NULL; |
return NULL; |
433 |
|
|
434 |
i = 1; |
i = 1; |
435 |
current = line->elements[i].item; |
current = line->elements[i].item; |
438 |
/* if second word is quoted, strip the quotes and return single word */ |
/* if second word is quoted, strip the quotes and return single word */ |
439 |
if (isquote(*current) && isquote(current[current_len - 1])) { |
if (isquote(*current) && isquote(current[current_len - 1])) { |
440 |
char *tmp; |
char *tmp; |
441 |
|
|
442 |
tmp = strdup(current); |
tmp = strdup(current+1); |
443 |
*(tmp + current_len - 1) = '\0'; |
if (!tmp) |
444 |
return ++tmp; |
return NULL; |
445 |
|
tmp[strlen(tmp)-1] = '\0'; |
446 |
|
return tmp; |
447 |
} |
} |
448 |
|
|
449 |
/* if no quotes, return second word verbatim */ |
/* if no quotes, return second word verbatim */ |
454 |
* whose last character is also quote (assuming it's the closing one) */ |
* whose last character is also quote (assuming it's the closing one) */ |
455 |
int resultMaxSize; |
int resultMaxSize; |
456 |
char * result; |
char * result; |
457 |
|
/* need to ensure that ' does not match " as we search */ |
458 |
|
char quote_char = *current; |
459 |
|
|
460 |
resultMaxSize = sizeOfSingleLine(line); |
resultMaxSize = sizeOfSingleLine(line); |
461 |
result = malloc(resultMaxSize); |
result = malloc(resultMaxSize); |
462 |
snprintf(result, resultMaxSize, "%s", ++current); |
snprintf(result, resultMaxSize, "%s", ++current); |
463 |
|
|
464 |
i++; |
i++; |
465 |
for (; i < line->numElements; ++i) { |
for (; i < line->numElements; ++i) { |
466 |
current = line->elements[i].item; |
current = line->elements[i].item; |
469 |
current_indent_len = strlen(current_indent); |
current_indent_len = strlen(current_indent); |
470 |
|
|
471 |
strncat(result, current_indent, current_indent_len); |
strncat(result, current_indent, current_indent_len); |
472 |
if (!isquote(current[current_len-1])) { |
if (current[current_len-1] != quote_char) { |
473 |
strncat(result, current, current_len); |
strncat(result, current, current_len); |
474 |
} else { |
} else { |
475 |
strncat(result, current, current_len - 1); |
strncat(result, current, current_len - 1); |
587 |
{ "initrd", LT_INITRD, ' ', ',' }, |
{ "initrd", LT_INITRD, ' ', ',' }, |
588 |
{ "append", LT_KERNELARGS, ' ' }, |
{ "append", LT_KERNELARGS, ' ' }, |
589 |
{ "prompt", LT_UNKNOWN, ' ' }, |
{ "prompt", LT_UNKNOWN, ' ' }, |
590 |
|
{ "fdt", LT_DEVTREE, ' ' }, |
591 |
|
{ "fdtdir", LT_DEVTREE, ' ' }, |
592 |
{ NULL, 0, 0 }, |
{ NULL, 0, 0 }, |
593 |
}; |
}; |
594 |
int useextlinuxmenu; |
int useextlinuxmenu; |
599 |
.needsBootPrefix = 1, |
.needsBootPrefix = 1, |
600 |
.argsInQuotes = 1, |
.argsInQuotes = 1, |
601 |
.mbConcatArgs = 1, |
.mbConcatArgs = 1, |
602 |
|
.titlePosition = 1, |
603 |
}; |
}; |
604 |
|
|
605 |
struct configFileInfo liloConfigType = { |
struct configFileInfo liloConfigType = { |
608 |
.entryStart = LT_KERNEL, |
.entryStart = LT_KERNEL, |
609 |
.argsInQuotes = 1, |
.argsInQuotes = 1, |
610 |
.maxTitleLength = 15, |
.maxTitleLength = 15, |
611 |
|
.titlePosition = 1, |
612 |
}; |
}; |
613 |
|
|
614 |
struct configFileInfo yabootConfigType = { |
struct configFileInfo yabootConfigType = { |
619 |
.argsInQuotes = 1, |
.argsInQuotes = 1, |
620 |
.maxTitleLength = 15, |
.maxTitleLength = 15, |
621 |
.mbAllowExtraInitRds = 1, |
.mbAllowExtraInitRds = 1, |
622 |
|
.titlePosition = 1, |
623 |
}; |
}; |
624 |
|
|
625 |
struct configFileInfo siloConfigType = { |
struct configFileInfo siloConfigType = { |
629 |
.needsBootPrefix = 1, |
.needsBootPrefix = 1, |
630 |
.argsInQuotes = 1, |
.argsInQuotes = 1, |
631 |
.maxTitleLength = 15, |
.maxTitleLength = 15, |
632 |
|
.titlePosition = 1, |
633 |
}; |
}; |
634 |
|
|
635 |
struct configFileInfo ziplConfigType = { |
struct configFileInfo ziplConfigType = { |
648 |
.needsBootPrefix = 1, |
.needsBootPrefix = 1, |
649 |
.maxTitleLength = 255, |
.maxTitleLength = 255, |
650 |
.mbAllowExtraInitRds = 1, |
.mbAllowExtraInitRds = 1, |
651 |
|
.defaultIsUnquoted = 1, |
652 |
|
.titlePosition = 1, |
653 |
}; |
}; |
654 |
|
|
655 |
struct grubConfig { |
struct grubConfig { |
741 |
if (isEfi && cfi == &grub2ConfigType) { |
if (isEfi && cfi == &grub2ConfigType) { |
742 |
switch (type) { |
switch (type) { |
743 |
case LT_KERNEL: |
case LT_KERNEL: |
744 |
return LT_KERNEL_EFI; |
return isEfiOnly ? LT_KERNEL : LT_KERNEL_EFI; |
745 |
|
case LT_INITRD: |
746 |
|
return isEfiOnly ? LT_INITRD : LT_INITRD_EFI; |
747 |
|
default: |
748 |
|
return type; |
749 |
|
} |
750 |
|
#if defined(__i386__) || defined(__x86_64__) |
751 |
|
} else if (cfi == &grub2ConfigType) { |
752 |
|
switch (type) { |
753 |
|
case LT_KERNEL: |
754 |
|
return LT_KERNEL_16; |
755 |
case LT_INITRD: |
case LT_INITRD: |
756 |
return LT_INITRD_EFI; |
return LT_INITRD_16; |
757 |
default: |
default: |
758 |
return type; |
return type; |
759 |
} |
} |
760 |
|
#endif |
761 |
} |
} |
762 |
return type; |
return type; |
763 |
} |
} |
838 |
} |
} |
839 |
|
|
840 |
/* extract the title from within brackets (for zipl) */ |
/* extract the title from within brackets (for zipl) */ |
841 |
static char * extractTitle(struct singleLine * line) { |
static char * extractTitle(struct grubConfig *cfg, struct singleLine * line) { |
842 |
/* bracketed title... let's extract it (leaks a byte) */ |
/* bracketed title... let's extract it */ |
843 |
char * title = NULL; |
char * title = NULL; |
844 |
if (line->type == LT_TITLE) { |
if (line->type == LT_TITLE) { |
845 |
title = strdup(line->elements[0].item); |
char *tmp = line->elements[cfg->cfi->titlePosition].item; |
846 |
title++; |
if (cfg->cfi->titleBracketed) { |
847 |
*(title + strlen(title) - 1) = '\0'; |
tmp++; |
848 |
|
title = strdup(tmp); |
849 |
|
*(title + strlen(title) - 1) = '\0'; |
850 |
|
} else { |
851 |
|
title = strdup(tmp); |
852 |
|
} |
853 |
} else if (line->type == LT_MENUENTRY) |
} else if (line->type == LT_MENUENTRY) |
854 |
title = strdup(line->elements[1].item); |
title = strdup(line->elements[1].item); |
855 |
else |
else |
933 |
/* Need to handle this, because we strip the quotes from |
/* Need to handle this, because we strip the quotes from |
934 |
* menuentry when read it. */ |
* menuentry when read it. */ |
935 |
if (line->type == LT_MENUENTRY && i == 1) { |
if (line->type == LT_MENUENTRY && i == 1) { |
936 |
if(!isquote(*line->elements[i].item)) |
if(!isquote(*line->elements[i].item)) { |
937 |
fprintf(out, "\'%s\'", line->elements[i].item); |
int substring = 0; |
938 |
else |
/* If the line contains nested quotes, we did not strip |
939 |
|
* the "interna" quotes and we must use the right quotes |
940 |
|
* again when writing the updated file. */ |
941 |
|
for (int j = i; j < line->numElements; j++) { |
942 |
|
if (strchr(line->elements[i].item, '\'') != NULL) { |
943 |
|
substring = 1; |
944 |
|
fprintf(out, "\"%s\"", line->elements[i].item); |
945 |
|
break; |
946 |
|
} |
947 |
|
} |
948 |
|
if (!substring) |
949 |
|
fprintf(out, "\'%s\'", line->elements[i].item); |
950 |
|
} else { |
951 |
fprintf(out, "%s", line->elements[i].item); |
fprintf(out, "%s", line->elements[i].item); |
952 |
|
} |
953 |
fprintf(out, "%s", line->elements[i].indent); |
fprintf(out, "%s", line->elements[i].indent); |
954 |
|
|
955 |
continue; |
continue; |
1124 |
return 0; |
return 0; |
1125 |
} |
} |
1126 |
|
|
1127 |
|
static int isnumber(const char *s) |
1128 |
|
{ |
1129 |
|
int i; |
1130 |
|
for (i = 0; s[i] != '\0'; i++) |
1131 |
|
if (s[i] < '0' || s[i] > '9') |
1132 |
|
return 0; |
1133 |
|
return i; |
1134 |
|
} |
1135 |
|
|
1136 |
static struct grubConfig * readConfig(const char * inName, |
static struct grubConfig * readConfig(const char * inName, |
1137 |
struct configFileInfo * cfi) { |
struct configFileInfo * cfi) { |
1138 |
int in; |
int in; |
1223 |
cfg->flags &= ~GRUB_CONFIG_NO_DEFAULT; |
cfg->flags &= ~GRUB_CONFIG_NO_DEFAULT; |
1224 |
defaultLine = line; |
defaultLine = line; |
1225 |
} |
} |
|
} else if (line->type == LT_DEFAULT && line->numElements == 2) { |
|
|
cfg->flags &= ~GRUB_CONFIG_NO_DEFAULT; |
|
|
defaultLine = line; |
|
1226 |
|
|
1227 |
} else if (iskernel(line->type)) { |
} else if (iskernel(line->type)) { |
1228 |
/* if by some freak chance this is multiboot and the "module" |
/* if by some freak chance this is multiboot and the "module" |
1229 |
* lines came earlier in the template, make sure to use LT_HYPER |
* lines came earlier in the template, make sure to use LT_HYPER |
1230 |
* instead of LT_KERNEL now |
* instead of LT_KERNEL now |
1231 |
*/ |
*/ |
1232 |
if (entry->multiboot) |
if (entry && entry->multiboot) |
1233 |
line->type = LT_HYPER; |
line->type = LT_HYPER; |
1234 |
|
|
1235 |
} else if (line->type == LT_MBMODULE) { |
} else if (line->type == LT_MBMODULE) { |
1255 |
cfg->fallbackImage = strtol(line->elements[1].item, &end, 10); |
cfg->fallbackImage = strtol(line->elements[1].item, &end, 10); |
1256 |
if (*end) cfg->fallbackImage = -1; |
if (*end) cfg->fallbackImage = -1; |
1257 |
|
|
1258 |
} else if (line->type == LT_TITLE && line->numElements > 1) { |
} else if ((line->type == LT_DEFAULT && cfi->defaultIsUnquoted) || |
1259 |
/* make the title a single argument (undoing our parsing) */ |
(line->type == LT_TITLE && line->numElements > 1)) { |
1260 |
|
/* make the title/default a single argument (undoing our parsing) */ |
1261 |
len = 0; |
len = 0; |
1262 |
for (int i = 1; i < line->numElements; i++) { |
for (int i = 1; i < line->numElements; i++) { |
1263 |
len += strlen(line->elements[i].item); |
len += strlen(line->elements[i].item); |
1285 |
len = 0; |
len = 0; |
1286 |
char *extras; |
char *extras; |
1287 |
char *title; |
char *title; |
1288 |
|
/* initially unseen value */ |
1289 |
|
char quote_char = '\0'; |
1290 |
|
|
1291 |
for (int i = 1; i < line->numElements; i++) { |
for (int i = 1; i < line->numElements; i++) { |
1292 |
len += strlen(line->elements[i].item); |
len += strlen(line->elements[i].item); |
1303 |
for (int i = 0; i < line->numElements; i++) { |
for (int i = 0; i < line->numElements; i++) { |
1304 |
if (!strcmp(line->elements[i].item, "menuentry")) |
if (!strcmp(line->elements[i].item, "menuentry")) |
1305 |
continue; |
continue; |
1306 |
if (isquote(*line->elements[i].item)) |
if (isquote(*line->elements[i].item) && quote_char == '\0') { |
1307 |
|
/* ensure we properly pair off quotes */ |
1308 |
|
quote_char = *line->elements[i].item; |
1309 |
title = line->elements[i].item + 1; |
title = line->elements[i].item + 1; |
1310 |
else |
} else { |
1311 |
title = line->elements[i].item; |
title = line->elements[i].item; |
1312 |
|
} |
1313 |
|
|
1314 |
len = strlen(title); |
len = strlen(title); |
1315 |
if (isquote(title[len-1])) { |
if (title[len-1] == quote_char) { |
1316 |
strncat(buf, title,len-1); |
strncat(buf, title,len-1); |
1317 |
break; |
break; |
1318 |
} else { |
} else { |
1323 |
|
|
1324 |
/* get extras */ |
/* get extras */ |
1325 |
int count = 0; |
int count = 0; |
1326 |
|
quote_char = '\0'; |
1327 |
for (int i = 0; i < line->numElements; i++) { |
for (int i = 0; i < line->numElements; i++) { |
1328 |
if (count >= 2) { |
if (count >= 2) { |
1329 |
strcat(extras, line->elements[i].item); |
strcat(extras, line->elements[i].item); |
1334 |
continue; |
continue; |
1335 |
|
|
1336 |
/* count ' or ", there should be two in menuentry line. */ |
/* count ' or ", there should be two in menuentry line. */ |
1337 |
if (isquote(*line->elements[i].item)) |
if (isquote(*line->elements[i].item) && quote_char == '\0') { |
1338 |
|
/* ensure we properly pair off quotes */ |
1339 |
|
quote_char = *line->elements[i].item; |
1340 |
count++; |
count++; |
1341 |
|
} |
1342 |
|
|
1343 |
len = strlen(line->elements[i].item); |
len = strlen(line->elements[i].item); |
1344 |
|
|
1345 |
if (isquote(line->elements[i].item[len -1])) |
if (line->elements[i].item[len -1] == quote_char) |
1346 |
count++; |
count++; |
1347 |
|
|
1348 |
/* ok, we get the final ' or ", others are extras. */ |
/* ok, we get the final ' or ", others are extras. */ |
1373 |
} |
} |
1374 |
} |
} |
1375 |
|
|
1376 |
|
if (line->type == LT_DEFAULT && line->numElements == 2) { |
1377 |
|
cfg->flags &= ~GRUB_CONFIG_NO_DEFAULT; |
1378 |
|
defaultLine = line; |
1379 |
|
} |
1380 |
|
|
1381 |
/* If we find a generic config option which should live at the |
/* If we find a generic config option which should live at the |
1382 |
top of the file, move it there. Old versions of grubby were |
top of the file, move it there. Old versions of grubby were |
1383 |
probably responsible for putting new images in the wrong |
probably responsible for putting new images in the wrong |
1441 |
char *defTitle = cfi->getEnv(cfg->cfi, "saved_entry"); |
char *defTitle = cfi->getEnv(cfg->cfi, "saved_entry"); |
1442 |
if (defTitle) { |
if (defTitle) { |
1443 |
int index = 0; |
int index = 0; |
1444 |
entry = findEntryByTitle(cfg, defTitle, &index); |
if (isnumber(defTitle)) { |
1445 |
|
index = atoi(defTitle); |
1446 |
|
entry = findEntryByIndex(cfg, index); |
1447 |
|
} else { |
1448 |
|
entry = findEntryByTitle(cfg, defTitle, &index); |
1449 |
|
} |
1450 |
if (entry) |
if (entry) |
1451 |
cfg->defaultImage = index; |
cfg->defaultImage = index; |
1452 |
} |
} |
1479 |
line->elements[1].item)) break; |
line->elements[1].item)) break; |
1480 |
} else if (line) { |
} else if (line) { |
1481 |
if (!strcmp(defaultLine->elements[1].item, |
if (!strcmp(defaultLine->elements[1].item, |
1482 |
extractTitle(line))) break; |
extractTitle(cfg, line))) break; |
1483 |
} |
} |
1484 |
i++; |
i++; |
1485 |
entry = NULL; |
entry = NULL; |
1495 |
char *defTitle = cfi->getEnv(cfg->cfi, "saved_entry"); |
char *defTitle = cfi->getEnv(cfg->cfi, "saved_entry"); |
1496 |
if (defTitle) { |
if (defTitle) { |
1497 |
int index = 0; |
int index = 0; |
1498 |
entry = findEntryByTitle(cfg, defTitle, &index); |
if (isnumber(defTitle)) { |
1499 |
|
index = atoi(defTitle); |
1500 |
|
entry = findEntryByIndex(cfg, index); |
1501 |
|
} else { |
1502 |
|
entry = findEntryByTitle(cfg, defTitle, &index); |
1503 |
|
} |
1504 |
if (entry) |
if (entry) |
1505 |
cfg->defaultImage = index; |
cfg->defaultImage = index; |
1506 |
} |
} |
1511 |
return cfg; |
return cfg; |
1512 |
} |
} |
1513 |
|
|
1514 |
static void writeDefault(FILE * out, char * indent, |
static void writeDefault(FILE * out, char * indent, |
1515 |
char * separator, struct grubConfig * cfg) { |
char * separator, struct grubConfig * cfg) { |
1516 |
struct singleEntry * entry; |
struct singleEntry * entry; |
1517 |
struct singleLine * line; |
struct singleLine * line; |
1518 |
int i; |
int i; |
1519 |
|
|
1520 |
if (!cfg->defaultImage && cfg->flags == GRUB_CONFIG_NO_DEFAULT) return; |
if (!cfg->defaultImage && cfg->flags == GRUB_CONFIG_NO_DEFAULT) |
1521 |
|
return; |
1522 |
|
|
1523 |
if (cfg->defaultImage == DEFAULT_SAVED) |
if (cfg->defaultImage == DEFAULT_SAVED) |
1524 |
fprintf(out, "%sdefault%ssaved\n", indent, separator); |
fprintf(out, "%sdefault%ssaved\n", indent, separator); |
1531 |
if (!line) |
if (!line) |
1532 |
line = getLineByType(LT_TITLE, entry->lines); |
line = getLineByType(LT_TITLE, entry->lines); |
1533 |
if (line) { |
if (line) { |
1534 |
title = extractTitle(line); |
title = extractTitle(cfg, line); |
1535 |
if (title) |
if (title) |
1536 |
cfg->cfi->setEnv(cfg->cfi, "saved_entry", title); |
cfg->cfi->setEnv(cfg->cfi, "saved_entry", title); |
1537 |
} |
} |
1542 |
fprintf(out, "%sset default=\"%d\"\n", indent, |
fprintf(out, "%sset default=\"%d\"\n", indent, |
1543 |
cfg->defaultImage); |
cfg->defaultImage); |
1544 |
} else { |
} else { |
1545 |
fprintf(out, "%sdefault%s%d\n", indent, separator, |
fprintf(out, "%sdefault%s%d\n", indent, separator, |
1546 |
cfg->defaultImage); |
cfg->defaultImage); |
1547 |
} |
} |
1548 |
} else { |
} else { |
1549 |
int image = cfg->defaultImage; |
int image = cfg->defaultImage; |
1550 |
|
|
1551 |
entry = cfg->entries; |
entry = cfg->entries; |
1552 |
while (entry && entry->skip) entry = entry->next; |
while (entry && entry->skip) |
1553 |
|
entry = entry->next; |
1554 |
|
|
1555 |
i = 0; |
i = 0; |
1556 |
while (entry && i < image) { |
while (entry && i < image) { |
1557 |
entry = entry->next; |
entry = entry->next; |
1558 |
|
|
1559 |
while (entry && entry->skip) entry = entry->next; |
while (entry && entry->skip) |
1560 |
|
entry = entry->next; |
1561 |
i++; |
i++; |
1562 |
} |
} |
1563 |
|
|
1564 |
if (!entry) return; |
if (!entry) |
1565 |
|
return; |
1566 |
|
|
1567 |
line = getLineByType(LT_TITLE, entry->lines); |
line = getLineByType(LT_TITLE, entry->lines); |
1568 |
|
|
1569 |
if (line && line->numElements >= 2) |
if (line && line->numElements >= 2) |
1570 |
fprintf(out, "%sdefault%s%s\n", indent, separator, |
fprintf(out, "%sdefault%s%s\n", indent, separator, |
1571 |
line->elements[1].item); |
line->elements[1].item); |
1572 |
else if (line && (line->numElements == 1) && |
else if (line && (line->numElements == 1) && |
1573 |
cfg->cfi->titleBracketed) { |
cfg->cfi->titleBracketed) { |
1574 |
fprintf(out, "%sdefault%s%s\n", indent, separator, |
char *title = extractTitle(cfg, line); |
1575 |
extractTitle(line)); |
if (title) { |
1576 |
|
fprintf(out, "%sdefault%s%s\n", indent, separator, title); |
1577 |
|
free(title); |
1578 |
|
} |
1579 |
} |
} |
1580 |
} |
} |
1581 |
} |
} |
1882 |
return 0; |
return 0; |
1883 |
} |
} |
1884 |
|
|
1885 |
line = getLineByType(LT_KERNEL|LT_HYPER|LT_KERNEL_EFI, entry->lines); |
line = getLineByType(LT_KERNEL|LT_HYPER|LT_KERNEL_EFI|LT_KERNEL_16, entry->lines); |
1886 |
if (!line) { |
if (!line) { |
1887 |
notSuitablePrintf(entry, 0, "no line found\n"); |
notSuitablePrintf(entry, 0, "no line found\n"); |
1888 |
return 0; |
return 0; |
2006 |
} |
} |
2007 |
|
|
2008 |
indexVars[i + 1] = -1; |
indexVars[i + 1] = -1; |
2009 |
|
|
2010 |
i = 0; |
i = 0; |
2011 |
if (index) { |
if (index) { |
2012 |
while (i < *index) i++; |
while (i < *index) { |
2013 |
if (indexVars[i] == -1) return NULL; |
i++; |
2014 |
|
if (indexVars[i] == -1) return NULL; |
2015 |
|
} |
2016 |
} |
} |
2017 |
|
|
2018 |
entry = findEntryByIndex(config, indexVars[i]); |
entry = findEntryByIndex(config, indexVars[i]); |
2019 |
if (!entry) return NULL; |
if (!entry) return NULL; |
2020 |
|
|
2021 |
line = getLineByType(LT_KERNEL|LT_HYPER|LT_KERNEL_EFI, entry->lines); |
line = getLineByType(LT_KERNEL|LT_HYPER|LT_KERNEL_EFI|LT_KERNEL_16, entry->lines); |
2022 |
if (!line) return NULL; |
if (!line) return NULL; |
2023 |
|
|
2024 |
if (index) *index = indexVars[i]; |
if (index) *index = indexVars[i]; |
2069 |
for (line = entry->lines; line; line = line->next) { |
for (line = entry->lines; line; line = line->next) { |
2070 |
enum lineType_e ct = checkType; |
enum lineType_e ct = checkType; |
2071 |
if (entry->multiboot && checkType == LT_KERNEL) |
if (entry->multiboot && checkType == LT_KERNEL) |
2072 |
ct = LT_KERNEL|LT_KERNEL_EFI|LT_MBMODULE|LT_HYPER; |
ct = LT_KERNEL|LT_KERNEL_EFI|LT_MBMODULE|LT_HYPER|LT_KERNEL_16; |
2073 |
else if (checkType & LT_KERNEL) |
else if (checkType & LT_KERNEL) |
2074 |
ct = checkType | LT_KERNEL_EFI; |
ct = checkType | LT_KERNEL_EFI | LT_KERNEL_16; |
2075 |
line = getLineByType(ct, line); |
line = getLineByType(ct, line); |
2076 |
if (!line) |
if (!line) |
2077 |
break; /* not found in this entry */ |
break; /* not found in this entry */ |
2093 |
* non-Linux boot entries (could find netbsd etc, though, which is |
* non-Linux boot entries (could find netbsd etc, though, which is |
2094 |
* unfortunate) |
* unfortunate) |
2095 |
*/ |
*/ |
2096 |
if (line && getLineByType(LT_KERNEL|LT_HYPER|LT_KERNEL_EFI, entry->lines)) |
if (line && getLineByType(LT_KERNEL|LT_HYPER|LT_KERNEL_EFI|LT_KERNEL_16, entry->lines)) |
2097 |
break; /* found 'im! */ |
break; /* found 'im! */ |
2098 |
} |
} |
2099 |
|
|
2160 |
char *defTitle = cfg->cfi->getEnv(cfg->cfi, "saved_entry"); |
char *defTitle = cfg->cfi->getEnv(cfg->cfi, "saved_entry"); |
2161 |
if (defTitle) { |
if (defTitle) { |
2162 |
int index = 0; |
int index = 0; |
2163 |
entry = findEntryByTitle(cfg, defTitle, &index); |
if (isnumber(defTitle)) { |
2164 |
|
index = atoi(defTitle); |
2165 |
|
entry = findEntryByIndex(cfg, index); |
2166 |
|
} else { |
2167 |
|
entry = findEntryByTitle(cfg, defTitle, &index); |
2168 |
|
} |
2169 |
|
if (entry && suitableImage(entry, prefix, skipRemoved, flags)) { |
2170 |
|
cfg->defaultImage = index; |
2171 |
|
if (indexPtr) |
2172 |
|
*indexPtr = index; |
2173 |
|
return entry; |
2174 |
|
} |
2175 |
} |
} |
2176 |
} |
} |
2177 |
} else if (cfg->defaultImage > -1) { |
} else if (cfg->defaultImage > -1) { |
2328 |
struct singleLine * line; |
struct singleLine * line; |
2329 |
char * root = NULL; |
char * root = NULL; |
2330 |
int i; |
int i; |
2331 |
|
int j; |
2332 |
|
|
2333 |
printf("index=%d\n", index); |
printf("index=%d\n", index); |
2334 |
|
|
2335 |
line = getLineByType(LT_KERNEL|LT_HYPER|LT_KERNEL_EFI, entry->lines); |
line = getLineByType(LT_KERNEL|LT_HYPER|LT_KERNEL_EFI|LT_KERNEL_16, entry->lines); |
2336 |
if (!line) { |
if (!line) { |
2337 |
printf("non linux entry\n"); |
printf("non linux entry\n"); |
2338 |
return; |
return; |
2397 |
printf("root=%s\n", s); |
printf("root=%s\n", s); |
2398 |
} |
} |
2399 |
|
|
2400 |
line = getLineByType(LT_INITRD|LT_INITRD_EFI, entry->lines); |
line = getLineByType(LT_INITRD|LT_INITRD_EFI|LT_INITRD_16, entry->lines); |
2401 |
|
|
2402 |
if (line && line->numElements >= 2) { |
if (line && line->numElements >= 2) { |
2403 |
if (!strncmp(prefix, line->elements[1].item, strlen(prefix))) |
if (!strncmp(prefix, line->elements[1].item, strlen(prefix))) |
2416 |
} else { |
} else { |
2417 |
char * title; |
char * title; |
2418 |
line = getLineByType(LT_MENUENTRY, entry->lines); |
line = getLineByType(LT_MENUENTRY, entry->lines); |
2419 |
title = grub2ExtractTitle(line); |
if (line) { |
2420 |
if (title) |
title = grub2ExtractTitle(line); |
2421 |
printf("title=%s\n", title); |
if (title) |
2422 |
|
printf("title=%s\n", title); |
2423 |
|
} |
2424 |
|
} |
2425 |
|
|
2426 |
|
for (j = 0, line = entry->lines; line; line = line->next) { |
2427 |
|
if ((line->type & LT_MBMODULE) && line->numElements >= 2) { |
2428 |
|
if (!strncmp(prefix, line->elements[1].item, strlen(prefix))) |
2429 |
|
printf("mbmodule%d=", j); |
2430 |
|
else |
2431 |
|
printf("mbmodule%d=%s", j, prefix); |
2432 |
|
|
2433 |
|
for (i = 1; i < line->numElements; i++) |
2434 |
|
printf("%s%s", line->elements[i].item, line->elements[i].indent); |
2435 |
|
printf("\n"); |
2436 |
|
j++; |
2437 |
|
} |
2438 |
} |
} |
2439 |
} |
} |
2440 |
|
|
2830 |
insertElement(newLine, val, 1, cfi); |
insertElement(newLine, val, 1, cfi); |
2831 |
|
|
2832 |
/* but try to keep the rootspec from the template... sigh */ |
/* but try to keep the rootspec from the template... sigh */ |
2833 |
if (tmplLine->type & (LT_HYPER|LT_KERNEL|LT_MBMODULE|LT_INITRD|LT_KERNEL_EFI|LT_INITRD_EFI)) { |
if (tmplLine->type & (LT_HYPER|LT_KERNEL|LT_MBMODULE|LT_INITRD|LT_KERNEL_EFI|LT_INITRD_EFI|LT_KERNEL_16|LT_INITRD_16)) { |
2834 |
char * rootspec = getRootSpecifier(tmplLine->elements[1].item); |
char * rootspec = getRootSpecifier(tmplLine->elements[1].item); |
2835 |
if (rootspec != NULL) { |
if (rootspec != NULL) { |
2836 |
free(newLine->elements[1].item); |
free(newLine->elements[1].item); |
3200 |
firstElement = 2; |
firstElement = 2; |
3201 |
|
|
3202 |
} else { |
} else { |
3203 |
line = getLineByType(LT_KERNEL|LT_MBMODULE|LT_KERNEL_EFI, entry->lines); |
line = getLineByType(LT_KERNEL|LT_MBMODULE|LT_KERNEL_EFI|LT_KERNEL_16, entry->lines); |
3204 |
if (!line) { |
if (!line) { |
3205 |
/* no LT_KERNEL or LT_MBMODULE in this entry? */ |
/* no LT_KERNEL or LT_MBMODULE in this entry? */ |
3206 |
continue; |
continue; |
3356 |
return rc; |
return rc; |
3357 |
} |
} |
3358 |
|
|
3359 |
|
int addMBInitrd(struct grubConfig * cfg, const char *newMBKernel, |
3360 |
|
const char * image, const char * prefix, const char * initrd, |
3361 |
|
const char * title) { |
3362 |
|
struct singleEntry * entry; |
3363 |
|
struct singleLine * line, * kernelLine, *endLine = NULL; |
3364 |
|
int index = 0; |
3365 |
|
|
3366 |
|
if (!image) return 0; |
3367 |
|
|
3368 |
|
for (; (entry = findEntryByPath(cfg, image, prefix, &index)); index++) { |
3369 |
|
kernelLine = getLineByType(LT_MBMODULE, entry->lines); |
3370 |
|
if (!kernelLine) continue; |
3371 |
|
|
3372 |
|
/* if title is supplied, the entry's title must match it. */ |
3373 |
|
if (title) { |
3374 |
|
char *linetitle; |
3375 |
|
|
3376 |
|
line = getLineByType(LT_TITLE|LT_MENUENTRY, entry->lines); |
3377 |
|
if (!line) |
3378 |
|
continue; |
3379 |
|
|
3380 |
|
linetitle = extractTitle(cfg, line); |
3381 |
|
if (!linetitle) |
3382 |
|
continue; |
3383 |
|
if (strcmp(title, linetitle)) { |
3384 |
|
free(linetitle); |
3385 |
|
continue; |
3386 |
|
} |
3387 |
|
free(linetitle); |
3388 |
|
} |
3389 |
|
|
3390 |
|
if (prefix) { |
3391 |
|
int prefixLen = strlen(prefix); |
3392 |
|
if (!strncmp(initrd, prefix, prefixLen)) |
3393 |
|
initrd += prefixLen; |
3394 |
|
} |
3395 |
|
endLine = getLineByType(LT_ENTRY_END, entry->lines); |
3396 |
|
if (endLine) |
3397 |
|
removeLine(entry, endLine); |
3398 |
|
line = addLine(entry, cfg->cfi, preferredLineType(LT_MBMODULE,cfg->cfi), |
3399 |
|
kernelLine->indent, initrd); |
3400 |
|
if (!line) |
3401 |
|
return 1; |
3402 |
|
if (endLine) { |
3403 |
|
line = addLine(entry, cfg->cfi, LT_ENTRY_END, "", NULL); |
3404 |
|
if (!line) |
3405 |
|
return 1; |
3406 |
|
} |
3407 |
|
|
3408 |
|
break; |
3409 |
|
} |
3410 |
|
|
3411 |
|
return 0; |
3412 |
|
} |
3413 |
|
|
3414 |
int updateInitrd(struct grubConfig * cfg, const char * image, |
int updateInitrd(struct grubConfig * cfg, const char * image, |
3415 |
const char * prefix, const char * initrd) { |
const char * prefix, const char * initrd, const char * title) { |
3416 |
struct singleEntry * entry; |
struct singleEntry * entry; |
3417 |
struct singleLine * line, * kernelLine, *endLine = NULL; |
struct singleLine * line, * kernelLine, *endLine = NULL; |
3418 |
int index = 0; |
int index = 0; |
3420 |
if (!image) return 0; |
if (!image) return 0; |
3421 |
|
|
3422 |
for (; (entry = findEntryByPath(cfg, image, prefix, &index)); index++) { |
for (; (entry = findEntryByPath(cfg, image, prefix, &index)); index++) { |
3423 |
kernelLine = getLineByType(LT_KERNEL|LT_KERNEL_EFI, entry->lines); |
kernelLine = getLineByType(LT_KERNEL|LT_KERNEL_EFI|LT_KERNEL_16, entry->lines); |
3424 |
if (!kernelLine) continue; |
if (!kernelLine) continue; |
3425 |
|
|
3426 |
line = getLineByType(LT_INITRD|LT_INITRD_EFI, entry->lines); |
/* if title is supplied, the entry's title must match it. */ |
3427 |
|
if (title) { |
3428 |
|
char *linetitle; |
3429 |
|
|
3430 |
|
line = getLineByType(LT_TITLE|LT_MENUENTRY, entry->lines); |
3431 |
|
if (!line) |
3432 |
|
continue; |
3433 |
|
|
3434 |
|
linetitle = extractTitle(cfg, line); |
3435 |
|
if (!linetitle) |
3436 |
|
continue; |
3437 |
|
if (strcmp(title, linetitle)) { |
3438 |
|
free(linetitle); |
3439 |
|
continue; |
3440 |
|
} |
3441 |
|
free(linetitle); |
3442 |
|
} |
3443 |
|
|
3444 |
|
line = getLineByType(LT_INITRD|LT_INITRD_EFI|LT_INITRD_16, entry->lines); |
3445 |
if (line) |
if (line) |
3446 |
removeLine(entry, line); |
removeLine(entry, line); |
3447 |
if (prefix) { |
if (prefix) { |
3452 |
endLine = getLineByType(LT_ENTRY_END, entry->lines); |
endLine = getLineByType(LT_ENTRY_END, entry->lines); |
3453 |
if (endLine) |
if (endLine) |
3454 |
removeLine(entry, endLine); |
removeLine(entry, endLine); |
3455 |
line = addLine(entry, cfg->cfi, preferredLineType(LT_INITRD, cfg->cfi), |
enum lineType_e lt; |
3456 |
kernelLine->indent, initrd); |
switch(kernelLine->type) { |
3457 |
|
case LT_KERNEL: |
3458 |
|
lt = LT_INITRD; |
3459 |
|
break; |
3460 |
|
case LT_KERNEL_EFI: |
3461 |
|
lt = LT_INITRD_EFI; |
3462 |
|
break; |
3463 |
|
case LT_KERNEL_16: |
3464 |
|
lt = LT_INITRD_16; |
3465 |
|
break; |
3466 |
|
default: |
3467 |
|
lt = preferredLineType(LT_INITRD, cfg->cfi); |
3468 |
|
} |
3469 |
|
line = addLine(entry, cfg->cfi, lt, kernelLine->indent, initrd); |
3470 |
if (!line) |
if (!line) |
3471 |
return 1; |
return 1; |
3472 |
if (endLine) { |
if (endLine) { |
3825 |
const char * newKernelPath, const char * newKernelTitle, |
const char * newKernelPath, const char * newKernelTitle, |
3826 |
const char * newKernelArgs, const char * newKernelInitrd, |
const char * newKernelArgs, const char * newKernelInitrd, |
3827 |
const char ** extraInitrds, int extraInitrdCount, |
const char ** extraInitrds, int extraInitrdCount, |
3828 |
const char * newMBKernel, const char * newMBKernelArgs) { |
const char * newMBKernel, const char * newMBKernelArgs, |
3829 |
|
const char * newDevTreePath) { |
3830 |
struct singleEntry * new; |
struct singleEntry * new; |
3831 |
struct singleLine * newLine = NULL, * tmplLine = NULL, * masterLine = NULL; |
struct singleLine * newLine = NULL, * tmplLine = NULL, * masterLine = NULL; |
3832 |
int needs; |
int needs; |
3867 |
needs |= NEED_MB; |
needs |= NEED_MB; |
3868 |
new->multiboot = 1; |
new->multiboot = 1; |
3869 |
} |
} |
3870 |
|
if (newDevTreePath && getKeywordByType(LT_DEVTREE, config->cfi)) |
3871 |
|
needs |= NEED_DEVTREE; |
3872 |
|
|
3873 |
if (template) { |
if (template) { |
3874 |
for (masterLine = template->lines; |
for (masterLine = template->lines; |
4054 |
newLine = addLineTmpl(new, tmplLine, newLine, NULL, |
newLine = addLineTmpl(new, tmplLine, newLine, NULL, |
4055 |
config->cfi); |
config->cfi); |
4056 |
} |
} |
4057 |
|
} else if (tmplLine->type == LT_DEVTREE && |
4058 |
|
tmplLine->numElements == 2 && newDevTreePath) { |
4059 |
|
newLine = addLineTmpl(new, tmplLine, newLine, |
4060 |
|
newDevTreePath + strlen(prefix), |
4061 |
|
config->cfi); |
4062 |
|
needs &= ~NEED_DEVTREE; |
4063 |
|
} else if (tmplLine->type == LT_ENTRY_END && needs & NEED_DEVTREE) { |
4064 |
|
const char *ndtp = newDevTreePath; |
4065 |
|
if (!strncmp(newDevTreePath, prefix, strlen(prefix))) |
4066 |
|
ndtp += strlen(prefix); |
4067 |
|
newLine = addLine(new, config->cfi, LT_DEVTREE, |
4068 |
|
config->secondaryIndent, |
4069 |
|
ndtp); |
4070 |
|
needs &= ~NEED_DEVTREE; |
4071 |
|
newLine = addLineTmpl(new, tmplLine, newLine, NULL, config->cfi); |
4072 |
} else { |
} else { |
4073 |
/* pass through other lines from the template */ |
/* pass through other lines from the template */ |
4074 |
newLine = addLineTmpl(new, tmplLine, newLine, NULL, config->cfi); |
newLine = addLineTmpl(new, tmplLine, newLine, NULL, config->cfi); |
4082 |
switch (config->cfi->entryStart) { |
switch (config->cfi->entryStart) { |
4083 |
case LT_KERNEL: |
case LT_KERNEL: |
4084 |
case LT_KERNEL_EFI: |
case LT_KERNEL_EFI: |
4085 |
|
case LT_KERNEL_16: |
4086 |
if (new->multiboot && config->cfi->mbHyperFirst) { |
if (new->multiboot && config->cfi->mbHyperFirst) { |
4087 |
/* fall through to LT_HYPER */ |
/* fall through to LT_HYPER */ |
4088 |
} else { |
} else { |
4144 |
} |
} |
4145 |
} |
} |
4146 |
|
|
4147 |
|
struct singleLine *endLine = NULL; |
4148 |
|
endLine = getLineByType(LT_ENTRY_END, new->lines); |
4149 |
|
if (endLine) { |
4150 |
|
removeLine(new, endLine); |
4151 |
|
needs |= NEED_END; |
4152 |
|
} |
4153 |
|
|
4154 |
/* add the remainder of the lines, i.e. those that either |
/* add the remainder of the lines, i.e. those that either |
4155 |
* weren't present in the template, or in the case of no template, |
* weren't present in the template, or in the case of no template, |
4156 |
* all the lines following the entryStart. |
* all the lines following the entryStart. |
4196 |
free(initrdVal); |
free(initrdVal); |
4197 |
needs &= ~NEED_INITRD; |
needs &= ~NEED_INITRD; |
4198 |
} |
} |
4199 |
|
if (needs & NEED_DEVTREE) { |
4200 |
|
newLine = addLine(new, config->cfi, LT_DEVTREE, |
4201 |
|
config->secondaryIndent, |
4202 |
|
newDevTreePath); |
4203 |
|
needs &= ~NEED_DEVTREE; |
4204 |
|
} |
4205 |
|
|
4206 |
|
/* NEEDS_END must be last on bootloaders that need it... */ |
4207 |
if (needs & NEED_END) { |
if (needs & NEED_END) { |
4208 |
newLine = addLine(new, config->cfi, LT_ENTRY_END, |
newLine = addLine(new, config->cfi, LT_ENTRY_END, |
4209 |
config->secondaryIndent, NULL); |
config->secondaryIndent, NULL); |
4221 |
return 0; |
return 0; |
4222 |
} |
} |
4223 |
|
|
|
static void traceback(int signum) |
|
|
{ |
|
|
void *array[40]; |
|
|
size_t size; |
|
|
|
|
|
signal(SIGSEGV, SIG_DFL); |
|
|
memset(array, '\0', sizeof (array)); |
|
|
size = backtrace(array, 40); |
|
|
|
|
|
fprintf(stderr, "grubby received SIGSEGV! Backtrace (%ld):\n", |
|
|
(unsigned long)size); |
|
|
backtrace_symbols_fd(array, size, STDERR_FILENO); |
|
|
exit(1); |
|
|
} |
|
|
|
|
4224 |
int main(int argc, const char ** argv) { |
int main(int argc, const char ** argv) { |
4225 |
poptContext optCon; |
poptContext optCon; |
4226 |
const char * grubConfig = NULL; |
const char * grubConfig = NULL; |
4240 |
char * newKernelArgs = NULL; |
char * newKernelArgs = NULL; |
4241 |
char * newKernelInitrd = NULL; |
char * newKernelInitrd = NULL; |
4242 |
char * newKernelTitle = NULL; |
char * newKernelTitle = NULL; |
4243 |
char * newKernelVersion = NULL; |
char * newDevTreePath = NULL; |
4244 |
char * newMBKernel = NULL; |
char * newMBKernel = NULL; |
4245 |
char * newMBKernelArgs = NULL; |
char * newMBKernelArgs = NULL; |
4246 |
char * removeMBKernelArgs = NULL; |
char * removeMBKernelArgs = NULL; |
4298 |
_("display the index of the default kernel") }, |
_("display the index of the default kernel") }, |
4299 |
{ "default-title", 0, 0, &displayDefaultTitle, 0, |
{ "default-title", 0, 0, &displayDefaultTitle, 0, |
4300 |
_("display the title of the default kernel") }, |
_("display the title of the default kernel") }, |
4301 |
|
{ "devtree", 0, POPT_ARG_STRING, &newDevTreePath, 0, |
4302 |
|
_("device tree file for new stanza"), _("dtb-path") }, |
4303 |
|
{ "devtreedir", 0, POPT_ARG_STRING, &newDevTreePath, 0, |
4304 |
|
_("device tree directory for new stanza"), _("dtb-path") }, |
4305 |
{ "elilo", 0, POPT_ARG_NONE, &configureELilo, 0, |
{ "elilo", 0, POPT_ARG_NONE, &configureELilo, 0, |
4306 |
_("configure elilo bootloader") }, |
_("configure elilo bootloader") }, |
4307 |
{ "efi", 0, POPT_ARG_NONE, &isEfi, 0, |
{ "efi", 0, POPT_ARG_NONE, &isEfi, 0, |
4363 |
|
|
4364 |
useextlinuxmenu=0; |
useextlinuxmenu=0; |
4365 |
|
|
|
signal(SIGSEGV, traceback); |
|
|
|
|
4366 |
int i = 0; |
int i = 0; |
4367 |
for (int j = 1; j < argc; j++) |
for (int j = 1; j < argc; j++) |
4368 |
i += strlen(argv[j]) + 1; |
i += strlen(argv[j]) + 1; |
4440 |
} |
} |
4441 |
|
|
4442 |
if (!cfi) { |
if (!cfi) { |
4443 |
if (grub2FindConfig(&grub2ConfigType)) |
if (grub2FindConfig(&grub2ConfigType)) { |
4444 |
cfi = &grub2ConfigType; |
cfi = &grub2ConfigType; |
4445 |
else |
if (envPath) |
4446 |
|
cfi->envFile = envPath; |
4447 |
|
} else |
4448 |
#ifdef __ia64__ |
#ifdef __ia64__ |
4449 |
cfi = &eliloConfigType; |
cfi = &eliloConfigType; |
4450 |
#elif __powerpc__ |
#elif __powerpc__ |
4467 |
grubConfig = cfi->defaultConfig; |
grubConfig = cfi->defaultConfig; |
4468 |
} |
} |
4469 |
|
|
4470 |
if (bootloaderProbe && (displayDefault || kernelInfo || newKernelVersion || |
if (bootloaderProbe && (displayDefault || kernelInfo || |
4471 |
newKernelPath || removeKernelPath || makeDefault || |
newKernelPath || removeKernelPath || makeDefault || |
4472 |
defaultKernel || displayDefaultIndex || displayDefaultTitle || |
defaultKernel || displayDefaultIndex || displayDefaultTitle || |
4473 |
(defaultIndex >= 0))) { |
(defaultIndex >= 0))) { |
4476 |
return 1; |
return 1; |
4477 |
} |
} |
4478 |
|
|
4479 |
if ((displayDefault || kernelInfo) && (newKernelVersion || newKernelPath || |
if ((displayDefault || kernelInfo) && (newKernelPath || |
4480 |
removeKernelPath)) { |
removeKernelPath)) { |
4481 |
fprintf(stderr, _("grubby: --default-kernel and --info may not " |
fprintf(stderr, _("grubby: --default-kernel and --info may not " |
4482 |
"be used when adding or removing kernels\n")); |
"be used when adding or removing kernels\n")); |
4486 |
if (newKernelPath && !newKernelTitle) { |
if (newKernelPath && !newKernelTitle) { |
4487 |
fprintf(stderr, _("grubby: kernel title must be specified\n")); |
fprintf(stderr, _("grubby: kernel title must be specified\n")); |
4488 |
return 1; |
return 1; |
4489 |
} else if (!newKernelPath && (newKernelTitle || copyDefault || |
} else if (!newKernelPath && (copyDefault || |
4490 |
(newKernelInitrd && !updateKernelPath)|| |
(newKernelInitrd && !updateKernelPath)|| |
4491 |
makeDefault || extraInitrdCount > 0)) { |
makeDefault || extraInitrdCount > 0)) { |
4492 |
fprintf(stderr, _("grubby: kernel path expected\n")); |
fprintf(stderr, _("grubby: kernel path expected\n")); |
4645 |
if (!entry) return 0; |
if (!entry) return 0; |
4646 |
if (!suitableImage(entry, bootPrefix, 0, flags)) return 0; |
if (!suitableImage(entry, bootPrefix, 0, flags)) return 0; |
4647 |
|
|
4648 |
line = getLineByType(LT_KERNEL|LT_HYPER|LT_KERNEL_EFI, entry->lines); |
line = getLineByType(LT_KERNEL|LT_HYPER|LT_KERNEL_EFI|LT_KERNEL_16, entry->lines); |
4649 |
if (!line) return 0; |
if (!line) return 0; |
4650 |
|
|
4651 |
rootspec = getRootSpecifier(line->elements[1].item); |
rootspec = getRootSpecifier(line->elements[1].item); |
4658 |
struct singleLine * line; |
struct singleLine * line; |
4659 |
struct singleEntry * entry; |
struct singleEntry * entry; |
4660 |
|
|
4661 |
if (config->defaultImage == -1) return 0; |
if (config->defaultImage == -1) |
4662 |
|
return 0; |
4663 |
if (config->defaultImage == DEFAULT_SAVED_GRUB2 && |
if (config->defaultImage == DEFAULT_SAVED_GRUB2 && |
4664 |
cfi->defaultIsSaved) |
cfi->defaultIsSaved) |
4665 |
config->defaultImage = 0; |
config->defaultImage = 0; |
4666 |
entry = findEntryByIndex(config, config->defaultImage); |
entry = findEntryByIndex(config, config->defaultImage); |
4667 |
if (!entry) return 0; |
if (!entry) |
4668 |
|
return 0; |
4669 |
|
|
4670 |
if (!configureGrub2) { |
if (!configureGrub2) { |
4671 |
line = getLineByType(LT_TITLE, entry->lines); |
char *title; |
4672 |
if (!line) return 0; |
line = getLineByType(LT_TITLE, entry->lines); |
4673 |
printf("%s\n", line->elements[1].item); |
if (!line) |
4674 |
|
return 0; |
4675 |
|
title = extractTitle(config, line); |
4676 |
|
if (!title) |
4677 |
|
return 0; |
4678 |
|
printf("%s\n", title); |
4679 |
|
free(title); |
4680 |
} else { |
} else { |
4681 |
char * title; |
char * title; |
4682 |
|
|
4683 |
dbgPrintf("This is GRUB2, default title is embeded in menuentry\n"); |
dbgPrintf("This is GRUB2, default title is embeded in menuentry\n"); |
4684 |
line = getLineByType(LT_MENUENTRY, entry->lines); |
line = getLineByType(LT_MENUENTRY, entry->lines); |
4685 |
if (!line) return 0; |
if (!line) |
4686 |
title = grub2ExtractTitle(line); |
return 0; |
4687 |
if (title) |
title = grub2ExtractTitle(line); |
4688 |
printf("%s\n", title); |
if (title) |
4689 |
|
printf("%s\n", title); |
4690 |
} |
} |
4691 |
return 0; |
return 0; |
4692 |
|
|
4714 |
if (updateImage(config, updateKernelPath, bootPrefix, newKernelArgs, |
if (updateImage(config, updateKernelPath, bootPrefix, newKernelArgs, |
4715 |
removeArgs, newMBKernelArgs, removeMBKernelArgs)) return 1; |
removeArgs, newMBKernelArgs, removeMBKernelArgs)) return 1; |
4716 |
if (updateKernelPath && newKernelInitrd) { |
if (updateKernelPath && newKernelInitrd) { |
4717 |
if (updateInitrd(config, updateKernelPath, bootPrefix, |
if (newMBKernel) { |
4718 |
newKernelInitrd)) return 1; |
if (addMBInitrd(config, newMBKernel, updateKernelPath, |
4719 |
|
bootPrefix, newKernelInitrd, |
4720 |
|
newKernelTitle)) |
4721 |
|
return 1; |
4722 |
|
} else { |
4723 |
|
if (updateInitrd(config, updateKernelPath, bootPrefix, |
4724 |
|
newKernelInitrd, newKernelTitle)) |
4725 |
|
return 1; |
4726 |
|
} |
4727 |
} |
} |
4728 |
if (addNewKernel(config, template, bootPrefix, newKernelPath, |
if (addNewKernel(config, template, bootPrefix, newKernelPath, |
4729 |
newKernelTitle, newKernelArgs, newKernelInitrd, |
newKernelTitle, newKernelArgs, newKernelInitrd, |
4730 |
(const char **)extraInitrds, extraInitrdCount, |
(const char **)extraInitrds, extraInitrdCount, |
4731 |
newMBKernel, newMBKernelArgs)) return 1; |
newMBKernel, newMBKernelArgs, newDevTreePath)) return 1; |
4732 |
|
|
4733 |
|
|
4734 |
if (numEntries(config) == 0) { |
if (numEntries(config) == 0) { |