36 |
#include <signal.h> |
#include <signal.h> |
37 |
#include <blkid/blkid.h> |
#include <blkid/blkid.h> |
38 |
|
|
39 |
|
#include "log.h" |
40 |
|
|
41 |
#ifndef DEBUG |
#ifndef DEBUG |
42 |
#define DEBUG 0 |
#define DEBUG 0 |
43 |
#endif |
#endif |
58 |
#define NOOP_OPCODE 0x90 |
#define NOOP_OPCODE 0x90 |
59 |
#define JMP_SHORT_OPCODE 0xeb |
#define JMP_SHORT_OPCODE 0xeb |
60 |
|
|
61 |
|
int isEfi = 0; |
62 |
|
|
63 |
|
char *saved_command_line = NULL; |
64 |
|
|
65 |
/* comments get lumped in with indention */ |
/* comments get lumped in with indention */ |
66 |
struct lineElement { |
struct lineElement { |
67 |
char * item; |
char * item; |
88 |
LT_MENUENTRY = 1 << 17, |
LT_MENUENTRY = 1 << 17, |
89 |
LT_ENTRY_END = 1 << 18, |
LT_ENTRY_END = 1 << 18, |
90 |
LT_SET_VARIABLE = 1 << 19, |
LT_SET_VARIABLE = 1 << 19, |
91 |
LT_UNKNOWN = 1 << 20, |
LT_KERNEL_EFI = 1 << 20, |
92 |
|
LT_INITRD_EFI = 1 << 21, |
93 |
|
LT_UNKNOWN = 1 << 22, |
94 |
}; |
}; |
95 |
|
|
96 |
struct singleLine { |
struct singleLine { |
142 |
findConfigFunc findConfig; |
findConfigFunc findConfig; |
143 |
writeLineFunc writeLine; |
writeLineFunc writeLine; |
144 |
struct keywordTypes * keywords; |
struct keywordTypes * keywords; |
145 |
|
int caseInsensitive; |
146 |
int defaultIsIndex; |
int defaultIsIndex; |
147 |
int defaultIsVariable; |
int defaultIsVariable; |
148 |
int defaultSupportSaved; |
int defaultSupportSaved; |
214 |
{ "default", LT_DEFAULT, ' ' }, |
{ "default", LT_DEFAULT, ' ' }, |
215 |
{ "fallback", LT_FALLBACK, ' ' }, |
{ "fallback", LT_FALLBACK, ' ' }, |
216 |
{ "linux", LT_KERNEL, ' ' }, |
{ "linux", LT_KERNEL, ' ' }, |
217 |
|
{ "linuxefi", LT_KERNEL_EFI, ' ' }, |
218 |
{ "initrd", LT_INITRD, ' ', ' ' }, |
{ "initrd", LT_INITRD, ' ', ' ' }, |
219 |
|
{ "initrdefi", LT_INITRD_EFI, ' ', ' ' }, |
220 |
{ "module", LT_MBMODULE, ' ' }, |
{ "module", LT_MBMODULE, ' ' }, |
221 |
{ "kernel", LT_HYPER, ' ' }, |
{ "kernel", LT_HYPER, ' ' }, |
222 |
{ NULL, 0, 0 }, |
{ NULL, 0, 0 }, |
282 |
return 0; |
return 0; |
283 |
} |
} |
284 |
|
|
285 |
|
static int iskernel(enum lineType_e type) { |
286 |
|
return (type == LT_KERNEL || type == LT_KERNEL_EFI); |
287 |
|
} |
288 |
|
|
289 |
|
static int isinitrd(enum lineType_e type) { |
290 |
|
return (type == LT_INITRD || type == LT_INITRD_EFI); |
291 |
|
} |
292 |
|
|
293 |
char *grub2ExtractTitle(struct singleLine * line) { |
char *grub2ExtractTitle(struct singleLine * line) { |
294 |
char * current; |
char * current; |
295 |
char * current_indent; |
char * current_indent; |
501 |
struct configFileInfo extlinuxConfigType = { |
struct configFileInfo extlinuxConfigType = { |
502 |
.defaultConfig = "/boot/extlinux/extlinux.conf", |
.defaultConfig = "/boot/extlinux/extlinux.conf", |
503 |
.keywords = extlinuxKeywords, |
.keywords = extlinuxKeywords, |
504 |
|
.caseInsensitive = 1, |
505 |
.entryStart = LT_TITLE, |
.entryStart = LT_TITLE, |
506 |
.needsBootPrefix = 1, |
.needsBootPrefix = 1, |
507 |
.maxTitleLength = 255, |
.maxTitleLength = 255, |
590 |
return buf; |
return buf; |
591 |
} |
} |
592 |
|
|
593 |
|
static enum lineType_e preferredLineType(enum lineType_e type, |
594 |
|
struct configFileInfo *cfi) { |
595 |
|
if (isEfi && cfi == &grub2ConfigType) { |
596 |
|
switch (type) { |
597 |
|
case LT_KERNEL: |
598 |
|
return LT_KERNEL_EFI; |
599 |
|
case LT_INITRD: |
600 |
|
return LT_INITRD_EFI; |
601 |
|
default: |
602 |
|
return type; |
603 |
|
} |
604 |
|
} |
605 |
|
return type; |
606 |
|
} |
607 |
|
|
608 |
static struct keywordTypes * getKeywordByType(enum lineType_e type, |
static struct keywordTypes * getKeywordByType(enum lineType_e type, |
609 |
struct configFileInfo * cfi) { |
struct configFileInfo * cfi) { |
610 |
for (struct keywordTypes *kw = cfi->keywords; kw->key; kw++) { |
for (struct keywordTypes *kw = cfi->keywords; kw->key; kw++) { |
638 |
static enum lineType_e getTypeByKeyword(char * keyword, |
static enum lineType_e getTypeByKeyword(char * keyword, |
639 |
struct configFileInfo * cfi) { |
struct configFileInfo * cfi) { |
640 |
for (struct keywordTypes *kw = cfi->keywords; kw->key; kw++) { |
for (struct keywordTypes *kw = cfi->keywords; kw->key; kw++) { |
641 |
if (!strcmp(keyword, kw->key)) |
if (cfi->caseInsensitive) { |
642 |
return kw->type; |
if (!strcasecmp(keyword, kw->key)) |
643 |
|
return kw->type; |
644 |
|
} else { |
645 |
|
if (!strcmp(keyword, kw->key)) |
646 |
|
return kw->type; |
647 |
|
} |
648 |
} |
} |
649 |
return LT_UNKNOWN; |
return LT_UNKNOWN; |
650 |
} |
} |
1034 |
cfg->flags &= ~GRUB_CONFIG_NO_DEFAULT; |
cfg->flags &= ~GRUB_CONFIG_NO_DEFAULT; |
1035 |
defaultLine = line; |
defaultLine = line; |
1036 |
|
|
1037 |
} else if (line->type == LT_KERNEL) { |
} else if (iskernel(line->type)) { |
1038 |
/* if by some freak chance this is multiboot and the "module" |
/* if by some freak chance this is multiboot and the "module" |
1039 |
* lines came earlier in the template, make sure to use LT_HYPER |
* lines came earlier in the template, make sure to use LT_HYPER |
1040 |
* instead of LT_KERNEL now |
* instead of LT_KERNEL now |
1051 |
for (struct singleLine *l = entry->lines; l; l = l->next) { |
for (struct singleLine *l = entry->lines; l; l = l->next) { |
1052 |
if (l->type == LT_HYPER) |
if (l->type == LT_HYPER) |
1053 |
break; |
break; |
1054 |
else if (l->type == LT_KERNEL) { |
else if (iskernel(l->type)) { |
1055 |
l->type = LT_HYPER; |
l->type = LT_HYPER; |
1056 |
break; |
break; |
1057 |
} |
} |
1350 |
|
|
1351 |
/* most likely the symlink is relative, so change our |
/* most likely the symlink is relative, so change our |
1352 |
directory to the dir of the symlink */ |
directory to the dir of the symlink */ |
1353 |
rc = chdir(dirname(outName)); |
char *dir = strdupa(outName); |
1354 |
|
rc = chdir(dirname(dir)); |
1355 |
do { |
do { |
1356 |
buf = alloca(len + 1); |
buf = alloca(len + 1); |
1357 |
rc = readlink(basename(outName), buf, len); |
rc = readlink(basename(outName), buf, len); |
1538 |
return NULL; |
return NULL; |
1539 |
} |
} |
1540 |
|
|
1541 |
void printEntry(struct singleEntry * entry) { |
void printEntry(struct singleEntry * entry, FILE *f) { |
1542 |
int i; |
int i; |
1543 |
struct singleLine * line; |
struct singleLine * line; |
1544 |
|
|
1545 |
for (line = entry->lines; line; line = line->next) { |
for (line = entry->lines; line; line = line->next) { |
1546 |
fprintf(stderr, "DBG: %s", line->indent); |
log_message(f, "DBG: %s", line->indent); |
1547 |
for (i = 0; i < line->numElements; i++) { |
for (i = 0; i < line->numElements; i++) { |
1548 |
/* Need to handle this, because we strip the quotes from |
/* Need to handle this, because we strip the quotes from |
1549 |
* menuentry when read it. */ |
* menuentry when read it. */ |
1550 |
if (line->type == LT_MENUENTRY && i == 1) { |
if (line->type == LT_MENUENTRY && i == 1) { |
1551 |
if(!isquote(*line->elements[i].item)) |
if(!isquote(*line->elements[i].item)) |
1552 |
fprintf(stderr, "\'%s\'", line->elements[i].item); |
log_message(f, "\'%s\'", line->elements[i].item); |
1553 |
else |
else |
1554 |
fprintf(stderr, "%s", line->elements[i].item); |
log_message(f, "%s", line->elements[i].item); |
1555 |
fprintf(stderr, "%s", line->elements[i].indent); |
log_message(f, "%s", line->elements[i].indent); |
1556 |
|
|
1557 |
continue; |
continue; |
1558 |
} |
} |
1559 |
|
|
1560 |
fprintf(stderr, "%s%s", |
log_message(f, "%s%s", |
1561 |
line->elements[i].item, line->elements[i].indent); |
line->elements[i].item, line->elements[i].indent); |
1562 |
} |
} |
1563 |
fprintf(stderr, "\n"); |
log_message(f, "\n"); |
1564 |
} |
} |
1565 |
} |
} |
1566 |
|
|
1567 |
void notSuitablePrintf(struct singleEntry * entry, const char *fmt, ...) |
void notSuitablePrintf(struct singleEntry * entry, int okay, const char *fmt, ...) |
1568 |
{ |
{ |
1569 |
va_list argp; |
static int once; |
1570 |
|
va_list argp, argq; |
1571 |
|
|
1572 |
if (!debug) |
va_start(argp, fmt); |
1573 |
|
|
1574 |
|
va_copy(argq, argp); |
1575 |
|
if (!once) { |
1576 |
|
log_time(NULL); |
1577 |
|
log_message(NULL, "command line: %s\n", saved_command_line); |
1578 |
|
} |
1579 |
|
log_message(NULL, "DBG: Image entry %s: ", okay ? "succeeded" : "failed"); |
1580 |
|
log_vmessage(NULL, fmt, argq); |
1581 |
|
|
1582 |
|
printEntry(entry, NULL); |
1583 |
|
va_end(argq); |
1584 |
|
|
1585 |
|
if (!debug) { |
1586 |
|
once = 1; |
1587 |
|
va_end(argp); |
1588 |
return; |
return; |
1589 |
|
} |
1590 |
|
|
1591 |
va_start(argp, fmt); |
if (okay) { |
1592 |
|
va_end(argp); |
1593 |
|
return; |
1594 |
|
} |
1595 |
|
|
1596 |
|
if (!once) |
1597 |
|
log_message(stderr, "DBG: command line: %s\n", saved_command_line); |
1598 |
|
once = 1; |
1599 |
fprintf(stderr, "DBG: Image entry failed: "); |
fprintf(stderr, "DBG: Image entry failed: "); |
1600 |
vfprintf(stderr, fmt, argp); |
vfprintf(stderr, fmt, argp); |
1601 |
printEntry(entry); |
printEntry(entry, stderr); |
1602 |
va_end(argp); |
va_end(argp); |
1603 |
} |
} |
1604 |
|
|
1625 |
char * rootdev; |
char * rootdev; |
1626 |
|
|
1627 |
if (skipRemoved && entry->skip) { |
if (skipRemoved && entry->skip) { |
1628 |
notSuitablePrintf(entry, "marked to skip\n"); |
notSuitablePrintf(entry, 0, "marked to skip\n"); |
1629 |
return 0; |
return 0; |
1630 |
} |
} |
1631 |
|
|
1632 |
line = getLineByType(LT_KERNEL|LT_HYPER, entry->lines); |
line = getLineByType(LT_KERNEL|LT_HYPER|LT_KERNEL_EFI, entry->lines); |
1633 |
if (!line) { |
if (!line) { |
1634 |
notSuitablePrintf(entry, "no line found\n"); |
notSuitablePrintf(entry, 0, "no line found\n"); |
1635 |
return 0; |
return 0; |
1636 |
} |
} |
1637 |
if (line->numElements < 2) { |
if (line->numElements < 2) { |
1638 |
notSuitablePrintf(entry, "line has only %d elements\n", |
notSuitablePrintf(entry, 0, "line has only %d elements\n", |
1639 |
line->numElements); |
line->numElements); |
1640 |
return 0; |
return 0; |
1641 |
} |
} |
1642 |
|
|
1643 |
if (flags & GRUBBY_BADIMAGE_OKAY) return 1; |
if (flags & GRUBBY_BADIMAGE_OKAY) { |
1644 |
|
notSuitablePrintf(entry, 1, "\n"); |
1645 |
|
return 1; |
1646 |
|
} |
1647 |
|
|
1648 |
fullName = alloca(strlen(bootPrefix) + |
fullName = alloca(strlen(bootPrefix) + |
1649 |
strlen(line->elements[1].item) + 1); |
strlen(line->elements[1].item) + 1); |
1654 |
sprintf(fullName, "%s%s%s", bootPrefix, hasslash ? "" : "/", |
sprintf(fullName, "%s%s%s", bootPrefix, hasslash ? "" : "/", |
1655 |
line->elements[1].item + rootspec_offset); |
line->elements[1].item + rootspec_offset); |
1656 |
if (access(fullName, R_OK)) { |
if (access(fullName, R_OK)) { |
1657 |
notSuitablePrintf(entry, "access to %s failed\n", fullName); |
notSuitablePrintf(entry, 0, "access to %s failed\n", fullName); |
1658 |
return 0; |
return 0; |
1659 |
} |
} |
1660 |
for (i = 2; i < line->numElements; i++) |
for (i = 2; i < line->numElements; i++) |
1675 |
|
|
1676 |
/* failed to find one */ |
/* failed to find one */ |
1677 |
if (!line) { |
if (!line) { |
1678 |
notSuitablePrintf(entry, "no line found\n"); |
notSuitablePrintf(entry, 0, "no line found\n"); |
1679 |
return 0; |
return 0; |
1680 |
} |
} |
1681 |
|
|
1684 |
if (i < line->numElements) |
if (i < line->numElements) |
1685 |
dev = line->elements[i].item + 5; |
dev = line->elements[i].item + 5; |
1686 |
else { |
else { |
1687 |
notSuitablePrintf(entry, "no root= entry found\n"); |
notSuitablePrintf(entry, 0, "no root= entry found\n"); |
1688 |
/* it failed too... can't find root= */ |
/* it failed too... can't find root= */ |
1689 |
return 0; |
return 0; |
1690 |
} |
} |
1693 |
|
|
1694 |
dev = getpathbyspec(dev); |
dev = getpathbyspec(dev); |
1695 |
if (!getpathbyspec(dev)) { |
if (!getpathbyspec(dev)) { |
1696 |
notSuitablePrintf(entry, "can't find blkid entry for %s\n", dev); |
notSuitablePrintf(entry, 0, "can't find blkid entry for %s\n", dev); |
1697 |
return 0; |
return 0; |
1698 |
} else |
} else |
1699 |
dev = getpathbyspec(dev); |
dev = getpathbyspec(dev); |
1700 |
|
|
1701 |
rootdev = findDiskForRoot(); |
rootdev = findDiskForRoot(); |
1702 |
if (!rootdev) { |
if (!rootdev) { |
1703 |
notSuitablePrintf(entry, "can't find root device\n"); |
notSuitablePrintf(entry, 0, "can't find root device\n"); |
1704 |
return 0; |
return 0; |
1705 |
} |
} |
1706 |
|
|
1707 |
if (!getuuidbydev(rootdev) || !getuuidbydev(dev)) { |
if (!getuuidbydev(rootdev) || !getuuidbydev(dev)) { |
1708 |
notSuitablePrintf(entry, "uuid missing: rootdev %s, dev %s\n", |
notSuitablePrintf(entry, 0, "uuid missing: rootdev %s, dev %s\n", |
1709 |
getuuidbydev(rootdev), getuuidbydev(dev)); |
getuuidbydev(rootdev), getuuidbydev(dev)); |
1710 |
free(rootdev); |
free(rootdev); |
1711 |
return 0; |
return 0; |
1712 |
} |
} |
1713 |
|
|
1714 |
if (strcmp(getuuidbydev(rootdev), getuuidbydev(dev))) { |
if (strcmp(getuuidbydev(rootdev), getuuidbydev(dev))) { |
1715 |
notSuitablePrintf(entry, "uuid mismatch: rootdev %s, dev %s\n", |
notSuitablePrintf(entry, 0, "uuid mismatch: rootdev %s, dev %s\n", |
1716 |
getuuidbydev(rootdev), getuuidbydev(dev)); |
getuuidbydev(rootdev), getuuidbydev(dev)); |
1717 |
free(rootdev); |
free(rootdev); |
1718 |
return 0; |
return 0; |
1719 |
} |
} |
1720 |
|
|
1721 |
free(rootdev); |
free(rootdev); |
1722 |
|
notSuitablePrintf(entry, 1, "\n"); |
1723 |
|
|
1724 |
return 1; |
return 1; |
1725 |
} |
} |
1763 |
entry = findEntryByIndex(config, indexVars[i]); |
entry = findEntryByIndex(config, indexVars[i]); |
1764 |
if (!entry) return NULL; |
if (!entry) return NULL; |
1765 |
|
|
1766 |
line = getLineByType(LT_KERNEL|LT_HYPER, entry->lines); |
line = getLineByType(LT_KERNEL|LT_HYPER|LT_KERNEL_EFI, entry->lines); |
1767 |
if (!line) return NULL; |
if (!line) return NULL; |
1768 |
|
|
1769 |
if (index) *index = indexVars[i]; |
if (index) *index = indexVars[i]; |
1812 |
|
|
1813 |
/* check all the lines matching checkType */ |
/* check all the lines matching checkType */ |
1814 |
for (line = entry->lines; line; line = line->next) { |
for (line = entry->lines; line; line = line->next) { |
1815 |
line = getLineByType(entry->multiboot && checkType == LT_KERNEL ? |
enum lineType_e ct = checkType; |
1816 |
LT_KERNEL|LT_MBMODULE|LT_HYPER : |
if (entry->multiboot && checkType == LT_KERNEL) |
1817 |
checkType, line); |
ct = LT_KERNEL|LT_KERNEL_EFI|LT_MBMODULE|LT_HYPER; |
1818 |
if (!line) break; /* not found in this entry */ |
else if (checkType & LT_KERNEL) |
1819 |
|
ct = checkType | LT_KERNEL_EFI; |
1820 |
|
line = getLineByType(ct, line); |
1821 |
|
if (!line) |
1822 |
|
break; /* not found in this entry */ |
1823 |
|
|
1824 |
if (line && line->type != LT_MENUENTRY && |
if (line && line->type != LT_MENUENTRY && |
1825 |
line->numElements >= 2) { |
line->numElements >= 2) { |
1838 |
* non-Linux boot entries (could find netbsd etc, though, which is |
* non-Linux boot entries (could find netbsd etc, though, which is |
1839 |
* unfortunate) |
* unfortunate) |
1840 |
*/ |
*/ |
1841 |
if (line && getLineByType(LT_KERNEL|LT_HYPER, entry->lines)) |
if (line && getLineByType(LT_KERNEL|LT_HYPER|LT_KERNEL_EFI, entry->lines)) |
1842 |
break; /* found 'im! */ |
break; /* found 'im! */ |
1843 |
} |
} |
1844 |
|
|
2027 |
|
|
2028 |
printf("index=%d\n", index); |
printf("index=%d\n", index); |
2029 |
|
|
2030 |
line = getLineByType(LT_KERNEL|LT_HYPER, entry->lines); |
line = getLineByType(LT_KERNEL|LT_HYPER|LT_KERNEL_EFI, entry->lines); |
2031 |
if (!line) { |
if (!line) { |
2032 |
printf("non linux entry\n"); |
printf("non linux entry\n"); |
2033 |
return; |
return; |
2092 |
printf("root=%s\n", s); |
printf("root=%s\n", s); |
2093 |
} |
} |
2094 |
|
|
2095 |
line = getLineByType(LT_INITRD, entry->lines); |
line = getLineByType(LT_INITRD|LT_INITRD_EFI, entry->lines); |
2096 |
|
|
2097 |
if (line && line->numElements >= 2) { |
if (line && line->numElements >= 2) { |
2098 |
if (!strncmp(prefix, line->elements[1].item, strlen(prefix))) |
if (!strncmp(prefix, line->elements[1].item, strlen(prefix))) |
2493 |
{ |
{ |
2494 |
struct singleLine * newLine = lineDup(tmplLine); |
struct singleLine * newLine = lineDup(tmplLine); |
2495 |
|
|
2496 |
|
if (isEfi && cfi == &grub2ConfigType) { |
2497 |
|
enum lineType_e old = newLine->type; |
2498 |
|
newLine->type = preferredLineType(newLine->type, cfi); |
2499 |
|
if (old != newLine->type) |
2500 |
|
newLine->elements[0].item = getKeyByType(newLine->type, cfi); |
2501 |
|
} |
2502 |
|
|
2503 |
if (val) { |
if (val) { |
2504 |
/* override the inherited value with our own. |
/* override the inherited value with our own. |
2505 |
* This is a little weak because it only applies to elements[1] |
* This is a little weak because it only applies to elements[1] |
2509 |
insertElement(newLine, val, 1, cfi); |
insertElement(newLine, val, 1, cfi); |
2510 |
|
|
2511 |
/* but try to keep the rootspec from the template... sigh */ |
/* but try to keep the rootspec from the template... sigh */ |
2512 |
if (tmplLine->type & (LT_HYPER|LT_KERNEL|LT_MBMODULE|LT_INITRD)) { |
if (tmplLine->type & (LT_HYPER|LT_KERNEL|LT_MBMODULE|LT_INITRD|LT_KERNEL_EFI|LT_INITRD_EFI)) { |
2513 |
char * rootspec = getRootSpecifier(tmplLine->elements[1].item); |
char * rootspec = getRootSpecifier(tmplLine->elements[1].item); |
2514 |
if (rootspec != NULL) { |
if (rootspec != NULL) { |
2515 |
free(newLine->elements[1].item); |
free(newLine->elements[1].item); |
2546 |
/* NB: This function shouldn't allocate items on the heap, rather on the |
/* NB: This function shouldn't allocate items on the heap, rather on the |
2547 |
* stack since it calls addLineTmpl which will make copies. |
* stack since it calls addLineTmpl which will make copies. |
2548 |
*/ |
*/ |
|
|
|
2549 |
if (type == LT_TITLE && cfi->titleBracketed) { |
if (type == LT_TITLE && cfi->titleBracketed) { |
2550 |
/* we're doing a bracketed title (zipl) */ |
/* we're doing a bracketed title (zipl) */ |
2551 |
tmpl.type = type; |
tmpl.type = type; |
2879 |
firstElement = 2; |
firstElement = 2; |
2880 |
|
|
2881 |
} else { |
} else { |
2882 |
line = getLineByType(LT_KERNEL|LT_MBMODULE, entry->lines); |
line = getLineByType(LT_KERNEL|LT_MBMODULE|LT_KERNEL_EFI, entry->lines); |
2883 |
if (!line) { |
if (!line) { |
2884 |
/* no LT_KERNEL or LT_MBMODULE in this entry? */ |
/* no LT_KERNEL or LT_MBMODULE in this entry? */ |
2885 |
continue; |
continue; |
3044 |
if (!image) return 0; |
if (!image) return 0; |
3045 |
|
|
3046 |
for (; (entry = findEntryByPath(cfg, image, prefix, &index)); index++) { |
for (; (entry = findEntryByPath(cfg, image, prefix, &index)); index++) { |
3047 |
kernelLine = getLineByType(LT_KERNEL, entry->lines); |
kernelLine = getLineByType(LT_KERNEL|LT_KERNEL_EFI, entry->lines); |
3048 |
if (!kernelLine) continue; |
if (!kernelLine) continue; |
3049 |
|
|
3050 |
line = getLineByType(LT_INITRD, entry->lines); |
line = getLineByType(LT_INITRD|LT_INITRD_EFI, entry->lines); |
3051 |
if (line) |
if (line) |
3052 |
removeLine(entry, line); |
removeLine(entry, line); |
3053 |
if (prefix) { |
if (prefix) { |
3058 |
endLine = getLineByType(LT_ENTRY_END, entry->lines); |
endLine = getLineByType(LT_ENTRY_END, entry->lines); |
3059 |
if (endLine) |
if (endLine) |
3060 |
removeLine(entry, endLine); |
removeLine(entry, endLine); |
3061 |
line = addLine(entry, cfg->cfi, LT_INITRD, kernelLine->indent, initrd); |
line = addLine(entry, cfg->cfi, preferredLineType(LT_INITRD, cfg->cfi), |
3062 |
|
kernelLine->indent, initrd); |
3063 |
if (!line) |
if (!line) |
3064 |
return 1; |
return 1; |
3065 |
if (endLine) { |
if (endLine) { |
3472 |
while (*chptr && isspace(*chptr)) chptr++; |
while (*chptr && isspace(*chptr)) chptr++; |
3473 |
if (*chptr == '#') continue; |
if (*chptr == '#') continue; |
3474 |
|
|
3475 |
if (tmplLine->type == LT_KERNEL && |
if (iskernel(tmplLine->type) && tmplLine->numElements >= 2) { |
|
tmplLine->numElements >= 2) { |
|
3476 |
if (!template->multiboot && (needs & NEED_MB)) { |
if (!template->multiboot && (needs & NEED_MB)) { |
3477 |
/* it's not a multiboot template and this is the kernel |
/* it's not a multiboot template and this is the kernel |
3478 |
* line. Try to be intelligent about inserting the |
* line. Try to be intelligent about inserting the |
3549 |
/* template is multi but new is not, |
/* template is multi but new is not, |
3550 |
* insert the kernel in the first module slot |
* insert the kernel in the first module slot |
3551 |
*/ |
*/ |
3552 |
tmplLine->type = LT_KERNEL; |
tmplLine->type = preferredLineType(LT_KERNEL, config->cfi); |
3553 |
free(tmplLine->elements[0].item); |
free(tmplLine->elements[0].item); |
3554 |
tmplLine->elements[0].item = |
tmplLine->elements[0].item = |
3555 |
strdup(getKeywordByType(LT_KERNEL, config->cfi)->key); |
strdup(getKeywordByType(tmplLine->type, |
3556 |
|
config->cfi)->key); |
3557 |
newLine = addLineTmpl(new, tmplLine, newLine, |
newLine = addLineTmpl(new, tmplLine, newLine, |
3558 |
newKernelPath + strlen(prefix), config->cfi); |
newKernelPath + strlen(prefix), |
3559 |
|
config->cfi); |
3560 |
needs &= ~NEED_KERNEL; |
needs &= ~NEED_KERNEL; |
3561 |
} else if (needs & NEED_INITRD) { |
} else if (needs & NEED_INITRD) { |
3562 |
char *initrdVal; |
char *initrdVal; |
3563 |
/* template is multi but new is not, |
/* template is multi but new is not, |
3564 |
* insert the initrd in the second module slot |
* insert the initrd in the second module slot |
3565 |
*/ |
*/ |
3566 |
tmplLine->type = LT_INITRD; |
tmplLine->type = preferredLineType(LT_INITRD, config->cfi); |
3567 |
free(tmplLine->elements[0].item); |
free(tmplLine->elements[0].item); |
3568 |
tmplLine->elements[0].item = |
tmplLine->elements[0].item = |
3569 |
strdup(getKeywordByType(LT_INITRD, config->cfi)->key); |
strdup(getKeywordByType(tmplLine->type, |
3570 |
|
config->cfi)->key); |
3571 |
initrdVal = getInitrdVal(config, prefix, tmplLine, newKernelInitrd, extraInitrds, extraInitrdCount); |
initrdVal = getInitrdVal(config, prefix, tmplLine, newKernelInitrd, extraInitrds, extraInitrdCount); |
3572 |
newLine = addLineTmpl(new, tmplLine, newLine, initrdVal, config->cfi); |
newLine = addLineTmpl(new, tmplLine, newLine, initrdVal, config->cfi); |
3573 |
free(initrdVal); |
free(initrdVal); |
3574 |
needs &= ~NEED_INITRD; |
needs &= ~NEED_INITRD; |
3575 |
} |
} |
3576 |
|
|
3577 |
} else if (tmplLine->type == LT_INITRD && |
} else if (isinitrd(tmplLine->type) && tmplLine->numElements >= 2) { |
|
tmplLine->numElements >= 2) { |
|
3578 |
if (needs & NEED_INITRD && |
if (needs & NEED_INITRD && |
3579 |
new->multiboot && !template->multiboot && |
new->multiboot && !template->multiboot && |
3580 |
config->cfi->mbInitRdIsModule) { |
config->cfi->mbInitRdIsModule) { |
3628 |
static const char *prefix = "'Loading "; |
static const char *prefix = "'Loading "; |
3629 |
if (tmplLine->numElements > 1 && |
if (tmplLine->numElements > 1 && |
3630 |
strstr(tmplLine->elements[1].item, prefix) && |
strstr(tmplLine->elements[1].item, prefix) && |
3631 |
masterLine->next && masterLine->next->type == LT_KERNEL) { |
masterLine->next && |
3632 |
|
iskernel(masterLine->next->type)) { |
3633 |
char *newTitle = malloc(strlen(prefix) + |
char *newTitle = malloc(strlen(prefix) + |
3634 |
strlen(newKernelTitle) + 2); |
strlen(newKernelTitle) + 2); |
3635 |
|
|
3656 |
*/ |
*/ |
3657 |
switch (config->cfi->entryStart) { |
switch (config->cfi->entryStart) { |
3658 |
case LT_KERNEL: |
case LT_KERNEL: |
3659 |
|
case LT_KERNEL_EFI: |
3660 |
if (new->multiboot && config->cfi->mbHyperFirst) { |
if (new->multiboot && config->cfi->mbHyperFirst) { |
3661 |
/* fall through to LT_HYPER */ |
/* fall through to LT_HYPER */ |
3662 |
} else { |
} else { |
3663 |
newLine = addLine(new, config->cfi, LT_KERNEL, |
newLine = addLine(new, config->cfi, |
3664 |
|
preferredLineType(LT_KERNEL, config->cfi), |
3665 |
config->primaryIndent, |
config->primaryIndent, |
3666 |
newKernelPath + strlen(prefix)); |
newKernelPath + strlen(prefix)); |
3667 |
needs &= ~NEED_KERNEL; |
needs &= ~NEED_KERNEL; |
3737 |
if (needs & NEED_KERNEL) { |
if (needs & NEED_KERNEL) { |
3738 |
newLine = addLine(new, config->cfi, |
newLine = addLine(new, config->cfi, |
3739 |
(new->multiboot && getKeywordByType(LT_MBMODULE, |
(new->multiboot && getKeywordByType(LT_MBMODULE, |
3740 |
config->cfi)) ? |
config->cfi)) |
3741 |
LT_MBMODULE : LT_KERNEL, |
? LT_MBMODULE |
3742 |
|
: preferredLineType(LT_KERNEL, config->cfi), |
3743 |
config->secondaryIndent, |
config->secondaryIndent, |
3744 |
newKernelPath + strlen(prefix)); |
newKernelPath + strlen(prefix)); |
3745 |
needs &= ~NEED_KERNEL; |
needs &= ~NEED_KERNEL; |
3755 |
initrdVal = getInitrdVal(config, prefix, NULL, newKernelInitrd, extraInitrds, extraInitrdCount); |
initrdVal = getInitrdVal(config, prefix, NULL, newKernelInitrd, extraInitrds, extraInitrdCount); |
3756 |
newLine = addLine(new, config->cfi, |
newLine = addLine(new, config->cfi, |
3757 |
(new->multiboot && getKeywordByType(LT_MBMODULE, |
(new->multiboot && getKeywordByType(LT_MBMODULE, |
3758 |
config->cfi)) ? |
config->cfi)) |
3759 |
LT_MBMODULE : LT_INITRD, |
? LT_MBMODULE |
3760 |
|
: preferredLineType(LT_INITRD, config->cfi), |
3761 |
config->secondaryIndent, |
config->secondaryIndent, |
3762 |
initrdVal); |
initrdVal); |
3763 |
free(initrdVal); |
free(initrdVal); |
3789 |
memset(array, '\0', sizeof (array)); |
memset(array, '\0', sizeof (array)); |
3790 |
size = backtrace(array, 40); |
size = backtrace(array, 40); |
3791 |
|
|
3792 |
fprintf(stderr, "grubby recieved SIGSEGV! Backtrace (%ld):\n", |
fprintf(stderr, "grubby received SIGSEGV! Backtrace (%ld):\n", |
3793 |
(unsigned long)size); |
(unsigned long)size); |
3794 |
backtrace_symbols_fd(array, size, STDERR_FILENO); |
backtrace_symbols_fd(array, size, STDERR_FILENO); |
3795 |
exit(1); |
exit(1); |
3873 |
_("display the title of the default kernel") }, |
_("display the title of the default kernel") }, |
3874 |
{ "elilo", 0, POPT_ARG_NONE, &configureELilo, 0, |
{ "elilo", 0, POPT_ARG_NONE, &configureELilo, 0, |
3875 |
_("configure elilo bootloader") }, |
_("configure elilo bootloader") }, |
3876 |
|
{ "efi", 0, POPT_ARG_NONE, &isEfi, 0, |
3877 |
|
_("force grub2 stanzas to use efi") }, |
3878 |
{ "extlinux", 0, POPT_ARG_NONE, &configureExtLinux, 0, |
{ "extlinux", 0, POPT_ARG_NONE, &configureExtLinux, 0, |
3879 |
_("configure extlinux bootloader (from syslinux)") }, |
_("configure extlinux bootloader (from syslinux)") }, |
3880 |
{ "grub", 0, POPT_ARG_NONE, &configureGrub, 0, |
{ "grub", 0, POPT_ARG_NONE, &configureGrub, 0, |
3887 |
{ "initrd", 0, POPT_ARG_STRING, &newKernelInitrd, 0, |
{ "initrd", 0, POPT_ARG_STRING, &newKernelInitrd, 0, |
3888 |
_("initrd image for the new kernel"), _("initrd-path") }, |
_("initrd image for the new kernel"), _("initrd-path") }, |
3889 |
{ "extra-initrd", 'i', POPT_ARG_STRING, NULL, 'i', |
{ "extra-initrd", 'i', POPT_ARG_STRING, NULL, 'i', |
3890 |
_("auxilliary initrd image for things other than the new kernel"), _("initrd-path") }, |
_("auxiliary initrd image for things other than the new kernel"), _("initrd-path") }, |
3891 |
{ "lilo", 0, POPT_ARG_NONE, &configureLilo, 0, |
{ "lilo", 0, POPT_ARG_NONE, &configureLilo, 0, |
3892 |
_("configure lilo bootloader") }, |
_("configure lilo bootloader") }, |
3893 |
{ "make-default", 0, 0, &makeDefault, 0, |
{ "make-default", 0, 0, &makeDefault, 0, |
3931 |
|
|
3932 |
signal(SIGSEGV, traceback); |
signal(SIGSEGV, traceback); |
3933 |
|
|
3934 |
|
int i = 0; |
3935 |
|
for (int j = 1; j < argc; j++) |
3936 |
|
i += strlen(argv[j]) + 1; |
3937 |
|
saved_command_line = malloc(i); |
3938 |
|
if (!saved_command_line) { |
3939 |
|
fprintf(stderr, "grubby: %m\n"); |
3940 |
|
exit(1); |
3941 |
|
} |
3942 |
|
saved_command_line[0] = '\0'; |
3943 |
|
for (int j = 1; j < argc; j++) { |
3944 |
|
strcat(saved_command_line, argv[j]); |
3945 |
|
strncat(saved_command_line, j == argc -1 ? "" : " ", 1); |
3946 |
|
} |
3947 |
|
|
3948 |
optCon = poptGetContext("grubby", argc, argv, options, 0); |
optCon = poptGetContext("grubby", argc, argv, options, 0); |
3949 |
poptReadDefaultConfig(optCon, 1); |
poptReadDefaultConfig(optCon, 1); |
3950 |
|
|
4201 |
if (!entry) return 0; |
if (!entry) return 0; |
4202 |
if (!suitableImage(entry, bootPrefix, 0, flags)) return 0; |
if (!suitableImage(entry, bootPrefix, 0, flags)) return 0; |
4203 |
|
|
4204 |
line = getLineByType(LT_KERNEL|LT_HYPER, entry->lines); |
line = getLineByType(LT_KERNEL|LT_HYPER|LT_KERNEL_EFI, entry->lines); |
4205 |
if (!line) return 0; |
if (!line) return 0; |
4206 |
|
|
4207 |
rootspec = getRootSpecifier(line->elements[1].item); |
rootspec = getRootSpecifier(line->elements[1].item); |