46 |
#define dbgPrintf(format, args...) |
#define dbgPrintf(format, args...) |
47 |
#endif |
#endif |
48 |
|
|
49 |
|
int debug = 0; /* Currently just for template debugging */ |
50 |
|
|
51 |
#define _(A) (A) |
#define _(A) (A) |
52 |
|
|
53 |
#define MAX_EXTRA_INITRDS 16 /* code segment checked by --bootloader-probe */ |
#define MAX_EXTRA_INITRDS 16 /* code segment checked by --bootloader-probe */ |
54 |
#define CODE_SEG_SIZE 128 /* code segment checked by --bootloader-probe */ |
#define CODE_SEG_SIZE 128 /* code segment checked by --bootloader-probe */ |
55 |
|
|
56 |
|
#define NOOP_OPCODE 0x90 |
57 |
|
#define JMP_SHORT_OPCODE 0xeb |
58 |
|
|
59 |
/* comments get lumped in with indention */ |
/* comments get lumped in with indention */ |
60 |
struct lineElement { |
struct lineElement { |
61 |
char * item; |
char * item; |
114 |
|
|
115 |
#define MAIN_DEFAULT (1 << 0) |
#define MAIN_DEFAULT (1 << 0) |
116 |
#define DEFAULT_SAVED -2 |
#define DEFAULT_SAVED -2 |
117 |
|
#define DEFAULT_SAVED_GRUB2 -3 |
118 |
|
|
119 |
struct keywordTypes { |
struct keywordTypes { |
120 |
char * key; |
char * key; |
162 |
{ NULL, 0, 0 }, |
{ NULL, 0, 0 }, |
163 |
}; |
}; |
164 |
|
|
165 |
|
const char *grubFindConfig(struct configFileInfo *cfi) { |
166 |
|
static const char *configFiles[] = { |
167 |
|
"/etc/grub.conf", |
168 |
|
"/boot/grub/grub.conf", |
169 |
|
"/boot/grub/menu.lst", |
170 |
|
NULL |
171 |
|
}; |
172 |
|
static int i = -1; |
173 |
|
|
174 |
|
if (i == -1) { |
175 |
|
for (i = 0; configFiles[i] != NULL; i++) { |
176 |
|
dbgPrintf("Checking \"%s\": ", configFiles[i]); |
177 |
|
if (!access(configFiles[i], R_OK)) { |
178 |
|
dbgPrintf("found\n"); |
179 |
|
return configFiles[i]; |
180 |
|
} |
181 |
|
dbgPrintf("not found\n"); |
182 |
|
} |
183 |
|
} |
184 |
|
return configFiles[i]; |
185 |
|
} |
186 |
|
|
187 |
struct configFileInfo grubConfigType = { |
struct configFileInfo grubConfigType = { |
188 |
.defaultConfig = "/boot/grub/grub.conf", |
.findConfig = grubFindConfig, |
189 |
.keywords = grubKeywords, |
.keywords = grubKeywords, |
190 |
.defaultIsIndex = 1, |
.defaultIsIndex = 1, |
191 |
.defaultSupportSaved = 1, |
.defaultSupportSaved = 1, |
218 |
NULL |
NULL |
219 |
}; |
}; |
220 |
static int i = -1; |
static int i = -1; |
221 |
|
static const char *grub_cfg = "/boot/grub/grub.cfg"; |
222 |
|
|
223 |
if (i == -1) { |
if (i == -1) { |
224 |
for (i = 0; configFiles[i] != NULL; i++) { |
for (i = 0; configFiles[i] != NULL; i++) { |
227 |
dbgPrintf("found\n"); |
dbgPrintf("found\n"); |
228 |
return configFiles[i]; |
return configFiles[i]; |
229 |
} |
} |
|
dbgPrintf("not found\n"); |
|
230 |
} |
} |
231 |
} |
} |
232 |
|
|
233 |
|
/* Ubuntu renames grub2 to grub, so check for the grub.d directory |
234 |
|
* that isn't in grub1, and if it exists, return the config file path |
235 |
|
* that they use. */ |
236 |
|
if (configFiles[i] == NULL && !access("/etc/grub.d/", R_OK)) { |
237 |
|
dbgPrintf("found\n"); |
238 |
|
return grub_cfg; |
239 |
|
} |
240 |
|
|
241 |
|
dbgPrintf("not found\n"); |
242 |
return configFiles[i]; |
return configFiles[i]; |
243 |
} |
} |
244 |
|
|
245 |
|
int sizeOfSingleLine(struct singleLine * line) { |
246 |
|
int i; |
247 |
|
int count = 0; |
248 |
|
|
249 |
|
for (i = 0; i < line->numElements; i++) { |
250 |
|
int indentSize = 0; |
251 |
|
|
252 |
|
count = count + strlen(line->elements[i].item); |
253 |
|
|
254 |
|
indentSize = strlen(line->elements[i].indent); |
255 |
|
if (indentSize > 0) |
256 |
|
count = count + indentSize; |
257 |
|
else |
258 |
|
/* be extra safe and add room for whitespaces */ |
259 |
|
count = count + 1; |
260 |
|
} |
261 |
|
|
262 |
|
/* room for trailing terminator */ |
263 |
|
count = count + 1; |
264 |
|
|
265 |
|
return count; |
266 |
|
} |
267 |
|
|
268 |
|
char *grub2ExtractTitle(struct singleLine * line) { |
269 |
|
char * current; |
270 |
|
char * current_indent; |
271 |
|
int current_len; |
272 |
|
int current_indent_len; |
273 |
|
int i; |
274 |
|
|
275 |
|
/* bail out if line does not start with menuentry */ |
276 |
|
if (strcmp(line->elements[0].item, "menuentry")) |
277 |
|
return NULL; |
278 |
|
|
279 |
|
i = 1; |
280 |
|
current = line->elements[i].item; |
281 |
|
current_len = strlen(current); |
282 |
|
|
283 |
|
/* if second word is quoted, strip the quotes and return single word */ |
284 |
|
if ((*current == '\'') && (*(current + current_len - 1) == '\'')) { |
285 |
|
char *tmp; |
286 |
|
|
287 |
|
tmp = strdup(current); |
288 |
|
*(tmp + current_len - 1) = '\0'; |
289 |
|
return ++tmp; |
290 |
|
} |
291 |
|
|
292 |
|
/* if no quotes, return second word verbatim */ |
293 |
|
if (*current != '\'') { |
294 |
|
return current; |
295 |
|
} |
296 |
|
|
297 |
|
/* second element start with a quote, so we have to find the element |
298 |
|
* whose last character is also quote (assuming it's the closing one) */ |
299 |
|
if (*current == '\'') { |
300 |
|
int resultMaxSize; |
301 |
|
char * result; |
302 |
|
|
303 |
|
resultMaxSize = sizeOfSingleLine(line); |
304 |
|
result = malloc(resultMaxSize); |
305 |
|
snprintf(result, resultMaxSize, "%s", ++current); |
306 |
|
|
307 |
|
i++; |
308 |
|
for (; i < line->numElements; ++i) { |
309 |
|
current = line->elements[i].item; |
310 |
|
current_len = strlen(current); |
311 |
|
current_indent = line->elements[i].indent; |
312 |
|
current_indent_len = strlen(current_indent); |
313 |
|
|
314 |
|
strncat(result, current_indent, current_indent_len); |
315 |
|
if (*(current + current_len - 1) != '\'') { |
316 |
|
strncat(result, current, current_len); |
317 |
|
} else { |
318 |
|
strncat(result, current, current_len - 1); |
319 |
|
break; |
320 |
|
} |
321 |
|
} |
322 |
|
return result; |
323 |
|
} |
324 |
|
|
325 |
|
return NULL; |
326 |
|
} |
327 |
|
|
328 |
struct configFileInfo grub2ConfigType = { |
struct configFileInfo grub2ConfigType = { |
329 |
.findConfig = grub2FindConfig, |
.findConfig = grub2FindConfig, |
330 |
.keywords = grub2Keywords, |
.keywords = grub2Keywords, |
331 |
.defaultIsIndex = 1, |
.defaultIsIndex = 1, |
332 |
.defaultSupportSaved = 0, |
.defaultSupportSaved = 1, |
333 |
.defaultIsVariable = 1, |
.defaultIsVariable = 1, |
334 |
.entryStart = LT_MENUENTRY, |
.entryStart = LT_MENUENTRY, |
335 |
.entryEnd = LT_ENTRY_END, |
.entryEnd = LT_ENTRY_END, |
960 |
cfg->secondaryIndent = strdup(line->indent); |
cfg->secondaryIndent = strdup(line->indent); |
961 |
} |
} |
962 |
|
|
963 |
if (isEntryStart(line, cfi)) { |
if (isEntryStart(line, cfi) || (cfg->entries && !sawEntry)) { |
964 |
sawEntry = 1; |
sawEntry = 1; |
965 |
if (!entry) { |
if (!entry) { |
966 |
cfg->entries = malloc(sizeof(*entry)); |
cfg->entries = malloc(sizeof(*entry)); |
1124 |
|
|
1125 |
dbgPrintf("defaultLine is %s\n", defaultLine ? "set" : "unset"); |
dbgPrintf("defaultLine is %s\n", defaultLine ? "set" : "unset"); |
1126 |
if (defaultLine) { |
if (defaultLine) { |
1127 |
if (cfi->defaultIsVariable) { |
if (defaultLine->numElements > 2 && |
1128 |
|
cfi->defaultSupportSaved && |
1129 |
|
!strncmp(defaultLine->elements[2].item,"\"${saved_entry}\"", 16)) { |
1130 |
|
cfg->defaultImage = DEFAULT_SAVED_GRUB2; |
1131 |
|
} else if (cfi->defaultIsVariable) { |
1132 |
char *value = defaultLine->elements[2].item; |
char *value = defaultLine->elements[2].item; |
1133 |
while (*value && (*value == '"' || *value == '\'' || |
while (*value && (*value == '"' || *value == '\'' || |
1134 |
*value == ' ' || *value == '\t')) |
*value == ' ' || *value == '\t')) |
1185 |
|
|
1186 |
if (cfg->defaultImage == DEFAULT_SAVED) |
if (cfg->defaultImage == DEFAULT_SAVED) |
1187 |
fprintf(out, "%sdefault%ssaved\n", indent, separator); |
fprintf(out, "%sdefault%ssaved\n", indent, separator); |
1188 |
|
else if (cfg->defaultImage == DEFAULT_SAVED_GRUB2) |
1189 |
|
fprintf(out, "%sset default=\"${saved_entry}\"\n", indent); |
1190 |
else if (cfg->defaultImage > -1) { |
else if (cfg->defaultImage > -1) { |
1191 |
if (cfg->cfi->defaultIsIndex) { |
if (cfg->cfi->defaultIsIndex) { |
1192 |
if (cfg->cfi->defaultIsVariable) { |
if (cfg->cfi->defaultIsVariable) { |
1430 |
return NULL; |
return NULL; |
1431 |
} |
} |
1432 |
|
|
1433 |
|
void printEntry(struct singleEntry * entry) { |
1434 |
|
int i; |
1435 |
|
struct singleLine * line; |
1436 |
|
|
1437 |
|
for (line = entry->lines; line; line = line->next) { |
1438 |
|
fprintf(stderr, "DBG: %s", line->indent); |
1439 |
|
for (i = 0; i < line->numElements; i++) { |
1440 |
|
fprintf(stderr, "%s%s", |
1441 |
|
line->elements[i].item, line->elements[i].indent); |
1442 |
|
} |
1443 |
|
fprintf(stderr, "\n"); |
1444 |
|
} |
1445 |
|
} |
1446 |
|
|
1447 |
|
void notSuitablePrintf(struct singleEntry * entry, const char *fmt, ...) |
1448 |
|
{ |
1449 |
|
va_list argp; |
1450 |
|
|
1451 |
|
if (!debug) |
1452 |
|
return; |
1453 |
|
|
1454 |
|
va_start(argp, fmt); |
1455 |
|
fprintf(stderr, "DBG: Image entry failed: "); |
1456 |
|
vfprintf(stderr, fmt, argp); |
1457 |
|
printEntry(entry); |
1458 |
|
va_end(argp); |
1459 |
|
} |
1460 |
|
|
1461 |
|
#define beginswith(s, c) ((s) && (s)[0] == (c)) |
1462 |
|
|
1463 |
|
static int endswith(const char *s, char c) |
1464 |
|
{ |
1465 |
|
int slen; |
1466 |
|
|
1467 |
|
if (!s && !s[0]) |
1468 |
|
return 0; |
1469 |
|
slen = strlen(s) - 1; |
1470 |
|
|
1471 |
|
return s[slen] == c; |
1472 |
|
} |
1473 |
|
|
1474 |
int suitableImage(struct singleEntry * entry, const char * bootPrefix, |
int suitableImage(struct singleEntry * entry, const char * bootPrefix, |
1475 |
int skipRemoved, int flags) { |
int skipRemoved, int flags) { |
1476 |
struct singleLine * line; |
struct singleLine * line; |
1480 |
char * rootspec; |
char * rootspec; |
1481 |
char * rootdev; |
char * rootdev; |
1482 |
|
|
1483 |
if (skipRemoved && entry->skip) return 0; |
if (skipRemoved && entry->skip) { |
1484 |
|
notSuitablePrintf(entry, "marked to skip\n"); |
1485 |
|
return 0; |
1486 |
|
} |
1487 |
|
|
1488 |
line = getLineByType(LT_KERNEL|LT_HYPER, entry->lines); |
line = getLineByType(LT_KERNEL|LT_HYPER, entry->lines); |
1489 |
if (!line || line->numElements < 2) return 0; |
if (!line) { |
1490 |
|
notSuitablePrintf(entry, "no line found\n"); |
1491 |
|
return 0; |
1492 |
|
} |
1493 |
|
if (line->numElements < 2) { |
1494 |
|
notSuitablePrintf(entry, "line has only %d elements\n", |
1495 |
|
line->numElements); |
1496 |
|
return 0; |
1497 |
|
} |
1498 |
|
|
1499 |
if (flags & GRUBBY_BADIMAGE_OKAY) return 1; |
if (flags & GRUBBY_BADIMAGE_OKAY) return 1; |
1500 |
|
|
1501 |
fullName = alloca(strlen(bootPrefix) + |
fullName = alloca(strlen(bootPrefix) + |
1502 |
strlen(line->elements[1].item) + 1); |
strlen(line->elements[1].item) + 1); |
1503 |
rootspec = getRootSpecifier(line->elements[1].item); |
rootspec = getRootSpecifier(line->elements[1].item); |
1504 |
sprintf(fullName, "%s%s", bootPrefix, |
int rootspec_offset = rootspec ? strlen(rootspec) : 0; |
1505 |
line->elements[1].item + (rootspec ? strlen(rootspec) : 0)); |
int hasslash = endswith(bootPrefix, '/') || |
1506 |
if (access(fullName, R_OK)) return 0; |
beginswith(line->elements[1].item + rootspec_offset, '/'); |
1507 |
|
sprintf(fullName, "%s%s%s", bootPrefix, hasslash ? "" : "/", |
1508 |
|
line->elements[1].item + rootspec_offset); |
1509 |
|
if (access(fullName, R_OK)) { |
1510 |
|
notSuitablePrintf(entry, "access to %s failed\n", fullName); |
1511 |
|
return 0; |
1512 |
|
} |
1513 |
for (i = 2; i < line->numElements; i++) |
for (i = 2; i < line->numElements; i++) |
1514 |
if (!strncasecmp(line->elements[i].item, "root=", 5)) break; |
if (!strncasecmp(line->elements[i].item, "root=", 5)) break; |
1515 |
if (i < line->numElements) { |
if (i < line->numElements) { |
1527 |
line = getLineByType(LT_KERNELARGS|LT_MBMODULE, entry->lines); |
line = getLineByType(LT_KERNELARGS|LT_MBMODULE, entry->lines); |
1528 |
|
|
1529 |
/* failed to find one */ |
/* failed to find one */ |
1530 |
if (!line) return 0; |
if (!line) { |
1531 |
|
notSuitablePrintf(entry, "no line found\n"); |
1532 |
|
return 0; |
1533 |
|
} |
1534 |
|
|
1535 |
for (i = 1; i < line->numElements; i++) |
for (i = 1; i < line->numElements; i++) |
1536 |
if (!strncasecmp(line->elements[i].item, "root=", 5)) break; |
if (!strncasecmp(line->elements[i].item, "root=", 5)) break; |
1537 |
if (i < line->numElements) |
if (i < line->numElements) |
1538 |
dev = line->elements[i].item + 5; |
dev = line->elements[i].item + 5; |
1539 |
else { |
else { |
1540 |
|
notSuitablePrintf(entry, "no root= entry found\n"); |
1541 |
/* it failed too... can't find root= */ |
/* it failed too... can't find root= */ |
1542 |
return 0; |
return 0; |
1543 |
} |
} |
1545 |
} |
} |
1546 |
|
|
1547 |
dev = getpathbyspec(dev); |
dev = getpathbyspec(dev); |
1548 |
if (!dev) |
if (!getpathbyspec(dev)) { |
1549 |
|
notSuitablePrintf(entry, "can't find blkid entry for %s\n", dev); |
1550 |
return 0; |
return 0; |
1551 |
|
} else |
1552 |
|
dev = getpathbyspec(dev); |
1553 |
|
|
1554 |
rootdev = findDiskForRoot(); |
rootdev = findDiskForRoot(); |
1555 |
if (!rootdev) |
if (!rootdev) { |
1556 |
|
notSuitablePrintf(entry, "can't find root device\n"); |
1557 |
return 0; |
return 0; |
1558 |
|
} |
1559 |
|
|
1560 |
if (!getuuidbydev(rootdev) || !getuuidbydev(dev)) { |
if (!getuuidbydev(rootdev) || !getuuidbydev(dev)) { |
1561 |
|
notSuitablePrintf(entry, "uuid missing: rootdev %s, dev %s\n", |
1562 |
|
getuuidbydev(rootdev), getuuidbydev(dev)); |
1563 |
free(rootdev); |
free(rootdev); |
1564 |
return 0; |
return 0; |
1565 |
} |
} |
1566 |
|
|
1567 |
if (strcmp(getuuidbydev(rootdev), getuuidbydev(dev))) { |
if (strcmp(getuuidbydev(rootdev), getuuidbydev(dev))) { |
1568 |
|
notSuitablePrintf(entry, "uuid mismatch: rootdev %s, dev %s\n", |
1569 |
|
getuuidbydev(rootdev), getuuidbydev(dev)); |
1570 |
free(rootdev); |
free(rootdev); |
1571 |
return 0; |
return 0; |
1572 |
} |
} |
1794 |
|
|
1795 |
/* defaultImage now points to what we'd like to use, but before any order |
/* defaultImage now points to what we'd like to use, but before any order |
1796 |
changes */ |
changes */ |
1797 |
if (config->defaultImage == DEFAULT_SAVED) |
if ((config->defaultImage == DEFAULT_SAVED) || |
1798 |
|
(config->defaultImage == DEFAULT_SAVED_GRUB2)) |
1799 |
/* default is set to saved, we don't want to change it */ |
/* default is set to saved, we don't want to change it */ |
1800 |
return; |
return; |
1801 |
|
|
1862 |
return; |
return; |
1863 |
} |
} |
1864 |
|
|
1865 |
printf("kernel=%s\n", line->elements[1].item); |
printf("kernel=%s%s\n", prefix, line->elements[1].item); |
1866 |
|
|
1867 |
if (line->numElements >= 3) { |
if (line->numElements >= 3) { |
1868 |
printf("args=\""); |
printf("args=\""); |
2634 |
if (memcmp(boot, bootSect, 3)) |
if (memcmp(boot, bootSect, 3)) |
2635 |
return 0; |
return 0; |
2636 |
|
|
2637 |
if (boot[1] == 0xeb) { |
if (boot[1] == JMP_SHORT_OPCODE) { |
2638 |
offset = boot[2] + 2; |
offset = boot[2] + 2; |
2639 |
} else if (boot[1] == 0xe8 || boot[1] == 0xe9) { |
} else if (boot[1] == 0xe8 || boot[1] == 0xe9) { |
2640 |
offset = (boot[3] << 8) + boot[2] + 2; |
offset = (boot[3] << 8) + boot[2] + 2; |
2641 |
} else if (boot[0] == 0xeb) { |
} else if (boot[0] == JMP_SHORT_OPCODE) { |
2642 |
offset = boot[1] + 2; |
offset = boot[1] + 2; |
2643 |
|
/* |
2644 |
|
* it looks like grub, when copying stage1 into the mbr, patches stage1 |
2645 |
|
* right after the JMP location, replacing other instructions such as |
2646 |
|
* JMPs for NOOPs. So, relax the check a little bit by skipping those |
2647 |
|
* different bytes. |
2648 |
|
*/ |
2649 |
|
if ((bootSect[offset + 1] == NOOP_OPCODE) |
2650 |
|
&& (bootSect[offset + 2] == NOOP_OPCODE)) { |
2651 |
|
offset = offset + 3; |
2652 |
|
} |
2653 |
} else if (boot[0] == 0xe8 || boot[0] == 0xe9) { |
} else if (boot[0] == 0xe8 || boot[0] == 0xe9) { |
2654 |
offset = (boot[2] << 8) + boot[1] + 2; |
offset = (boot[2] << 8) + boot[1] + 2; |
2655 |
} else { |
} else { |
2792 |
} |
} |
2793 |
|
|
2794 |
int checkForGrub2(struct grubConfig * config) { |
int checkForGrub2(struct grubConfig * config) { |
2795 |
if (!access("/boot/grub2", R_OK)) |
if (!access("/etc/grub.d/", R_OK)) |
2796 |
return 2; |
return 2; |
2797 |
|
|
2798 |
return 1; |
return 1; |
3124 |
} |
} |
3125 |
} else if (tmplLine->type == LT_ECHO) { |
} else if (tmplLine->type == LT_ECHO) { |
3126 |
requote(tmplLine, config->cfi); |
requote(tmplLine, config->cfi); |
3127 |
|
static const char *prefix = "'Loading "; |
3128 |
if (tmplLine->numElements > 1 && |
if (tmplLine->numElements > 1 && |
3129 |
strstr(tmplLine->elements[1].item, "'Loading Linux ")) { |
strstr(tmplLine->elements[1].item, prefix) && |
3130 |
char *prefix = "'Loading "; |
masterLine->next && masterLine->next->type == LT_KERNEL) { |
3131 |
char *newTitle = malloc(strlen(prefix) + |
char *newTitle = malloc(strlen(prefix) + |
3132 |
strlen(newKernelTitle) + 2); |
strlen(newKernelTitle) + 2); |
3133 |
|
|
3324 |
struct singleEntry * template = NULL; |
struct singleEntry * template = NULL; |
3325 |
int copyDefault = 0, makeDefault = 0; |
int copyDefault = 0, makeDefault = 0; |
3326 |
int displayDefault = 0; |
int displayDefault = 0; |
3327 |
|
int displayDefaultIndex = 0; |
3328 |
|
int displayDefaultTitle = 0; |
3329 |
struct poptOption options[] = { |
struct poptOption options[] = { |
3330 |
{ "add-kernel", 0, POPT_ARG_STRING, &newKernelPath, 0, |
{ "add-kernel", 0, POPT_ARG_STRING, &newKernelPath, 0, |
3331 |
_("add an entry for the specified kernel"), _("kernel-path") }, |
_("add an entry for the specified kernel"), _("kernel-path") }, |
3356 |
"the kernel referenced by the default image does not exist, " |
"the kernel referenced by the default image does not exist, " |
3357 |
"the first linux entry whose kernel does exist is used as the " |
"the first linux entry whose kernel does exist is used as the " |
3358 |
"template"), NULL }, |
"template"), NULL }, |
3359 |
|
{ "debug", 0, 0, &debug, 0, |
3360 |
|
_("print debugging information for failures") }, |
3361 |
{ "default-kernel", 0, 0, &displayDefault, 0, |
{ "default-kernel", 0, 0, &displayDefault, 0, |
3362 |
_("display the path of the default kernel") }, |
_("display the path of the default kernel") }, |
3363 |
|
{ "default-index", 0, 0, &displayDefaultIndex, 0, |
3364 |
|
_("display the index of the default kernel") }, |
3365 |
|
{ "default-title", 0, 0, &displayDefaultTitle, 0, |
3366 |
|
_("display the title of the default kernel") }, |
3367 |
{ "elilo", 0, POPT_ARG_NONE, &configureELilo, 0, |
{ "elilo", 0, POPT_ARG_NONE, &configureELilo, 0, |
3368 |
_("configure elilo bootloader") }, |
_("configure elilo bootloader") }, |
3369 |
{ "extlinux", 0, POPT_ARG_NONE, &configureExtLinux, 0, |
{ "extlinux", 0, POPT_ARG_NONE, &configureExtLinux, 0, |
3507 |
|
|
3508 |
if (bootloaderProbe && (displayDefault || kernelInfo || newKernelVersion || |
if (bootloaderProbe && (displayDefault || kernelInfo || newKernelVersion || |
3509 |
newKernelPath || removeKernelPath || makeDefault || |
newKernelPath || removeKernelPath || makeDefault || |
3510 |
defaultKernel)) { |
defaultKernel || displayDefaultIndex || displayDefaultTitle)) { |
3511 |
fprintf(stderr, _("grubby: --bootloader-probe may not be used with " |
fprintf(stderr, _("grubby: --bootloader-probe may not be used with " |
3512 |
"specified option")); |
"specified option")); |
3513 |
return 1; |
return 1; |
3550 |
defaultKernel = NULL; |
defaultKernel = NULL; |
3551 |
} |
} |
3552 |
|
|
3553 |
if (!strcmp(grubConfig, "-") && !outputFile) { |
if (grubConfig && !strcmp(grubConfig, "-") && !outputFile) { |
3554 |
fprintf(stderr, _("grubby: output file must be specified if stdin " |
fprintf(stderr, _("grubby: output file must be specified if stdin " |
3555 |
"is used\n")); |
"is used\n")); |
3556 |
return 1; |
return 1; |
3558 |
|
|
3559 |
if (!removeKernelPath && !newKernelPath && !displayDefault && !defaultKernel |
if (!removeKernelPath && !newKernelPath && !displayDefault && !defaultKernel |
3560 |
&& !kernelInfo && !bootloaderProbe && !updateKernelPath |
&& !kernelInfo && !bootloaderProbe && !updateKernelPath |
3561 |
&& !removeMBKernel) { |
&& !removeMBKernel && !displayDefaultIndex && !displayDefaultTitle) { |
3562 |
fprintf(stderr, _("grubby: no action specified\n")); |
fprintf(stderr, _("grubby: no action specified\n")); |
3563 |
return 1; |
return 1; |
3564 |
} |
} |
3597 |
gr2c = checkForGrub2(gconfig); |
gr2c = checkForGrub2(gconfig); |
3598 |
} |
} |
3599 |
|
|
3600 |
if (!access(grubConfigType.defaultConfig, F_OK)) { |
const char *grubconfig = grubFindConfig(&grubConfigType); |
3601 |
gconfig = readConfig(grubConfigType.defaultConfig, &grubConfigType); |
if (!access(grubconfig, F_OK)) { |
3602 |
|
gconfig = readConfig(grubconfig, &grubConfigType); |
3603 |
if (!gconfig) |
if (!gconfig) |
3604 |
grc = 1; |
grc = 1; |
3605 |
else |
else |
3653 |
((rootspec != NULL) ? strlen(rootspec) : 0)); |
((rootspec != NULL) ? strlen(rootspec) : 0)); |
3654 |
|
|
3655 |
return 0; |
return 0; |
3656 |
|
|
3657 |
|
} else if (displayDefaultTitle) { |
3658 |
|
struct singleLine * line; |
3659 |
|
struct singleEntry * entry; |
3660 |
|
|
3661 |
|
if (config->defaultImage == -1) return 0; |
3662 |
|
entry = findEntryByIndex(config, config->defaultImage); |
3663 |
|
if (!entry) return 0; |
3664 |
|
|
3665 |
|
if (!configureGrub2) { |
3666 |
|
line = getLineByType(LT_TITLE, entry->lines); |
3667 |
|
if (!line) return 0; |
3668 |
|
printf("%s\n", line->elements[1].item); |
3669 |
|
|
3670 |
|
} else { |
3671 |
|
char * title; |
3672 |
|
|
3673 |
|
dbgPrintf("This is GRUB2, default title is embeded in menuentry\n"); |
3674 |
|
line = getLineByType(LT_MENUENTRY, entry->lines); |
3675 |
|
if (!line) return 0; |
3676 |
|
title = grub2ExtractTitle(line); |
3677 |
|
if (title) |
3678 |
|
printf("%s\n", title); |
3679 |
|
} |
3680 |
|
return 0; |
3681 |
|
|
3682 |
|
} else if (displayDefaultIndex) { |
3683 |
|
if (config->defaultImage == -1) return 0; |
3684 |
|
printf("%i\n", config->defaultImage); |
3685 |
|
|
3686 |
} else if (kernelInfo) |
} else if (kernelInfo) |
3687 |
return displayInfo(config, kernelInfo, bootPrefix); |
return displayInfo(config, kernelInfo, bootPrefix); |
3688 |
|
|