--- trunk/mkinitrd-magellan/grubby/grubby.c 2010/09/14 19:47:52 1156 +++ trunk/grubby/grubby.c 2012/02/17 23:23:07 1694 @@ -36,7 +36,9 @@ #include #include +#ifndef DEBUG #define DEBUG 0 +#endif #if DEBUG #define dbgPrintf(format, args...) fprintf(stderr, format , ## args) @@ -115,7 +117,7 @@ struct keywordTypes * keywords; int defaultIsIndex; int defaultSupportSaved; - enum lineType_e entrySeparator; + enum lineType_e entryStart; int needsBootPrefix; int argsInQuotes; int maxTitleLength; @@ -139,19 +141,15 @@ }; struct configFileInfo grubConfigType = { - "/boot/grub/grub.conf", /* defaultConfig */ - grubKeywords, /* keywords */ - 1, /* defaultIsIndex */ - 1, /* defaultSupportSaved */ - LT_TITLE, /* entrySeparator */ - 1, /* needsBootPrefix */ - 0, /* argsInQuotes */ - 0, /* maxTitleLength */ - 0, /* titleBracketed */ - 1, /* mbHyperFirst */ - 1, /* mbInitRdIsModule */ - 0, /* mbConcatArgs */ - 1, /* mbAllowExtraInitRds */ + .defaultConfig = "/boot/grub/grub.conf", + .keywords = grubKeywords, + .defaultIsIndex = 1, + .defaultSupportSaved = 1, + .entryStart = LT_TITLE, + .needsBootPrefix = 1, + .mbHyperFirst = 1, + .mbInitRdIsModule = 1, + .mbAllowExtraInitRds = 1, }; struct keywordTypes yabootKeywords[] = { @@ -249,99 +247,56 @@ }; int useextlinuxmenu; struct configFileInfo eliloConfigType = { - "/boot/efi/EFI/redhat/elilo.conf", /* defaultConfig */ - eliloKeywords, /* keywords */ - 0, /* defaultIsIndex */ - 0, /* defaultSupportSaved */ - LT_KERNEL, /* entrySeparator */ - 1, /* needsBootPrefix */ - 1, /* argsInQuotes */ - 0, /* maxTitleLength */ - 0, /* titleBracketed */ - 0, /* mbHyperFirst */ - 0, /* mbInitRdIsModule */ - 1, /* mbConcatArgs */ - 0, /* mbAllowExtraInitRds */ + .defaultConfig = "/boot/efi/EFI/redhat/elilo.conf", + .keywords = eliloKeywords, + .entryStart = LT_KERNEL, + .needsBootPrefix = 1, + .argsInQuotes = 1, + .mbConcatArgs = 1, }; struct configFileInfo liloConfigType = { - "/etc/lilo.conf", /* defaultConfig */ - liloKeywords, /* keywords */ - 0, /* defaultIsIndex */ - 0, /* defaultSupportSaved */ - LT_KERNEL, /* entrySeparator */ - 0, /* needsBootPrefix */ - 1, /* argsInQuotes */ - 15, /* maxTitleLength */ - 0, /* titleBracketed */ - 0, /* mbHyperFirst */ - 0, /* mbInitRdIsModule */ - 0, /* mbConcatArgs */ - 0, /* mbAllowExtraInitRds */ + .defaultConfig = "/etc/lilo.conf", + .keywords = liloKeywords, + .entryStart = LT_KERNEL, + .argsInQuotes = 1, + .maxTitleLength = 15, }; struct configFileInfo yabootConfigType = { - "/etc/yaboot.conf", /* defaultConfig */ - yabootKeywords, /* keywords */ - 0, /* defaultIsIndex */ - 0, /* defaultSupportSaved */ - LT_KERNEL, /* entrySeparator */ - 1, /* needsBootPrefix */ - 1, /* argsInQuotes */ - 15, /* maxTitleLength */ - 0, /* titleBracketed */ - 0, /* mbHyperFirst */ - 0, /* mbInitRdIsModule */ - 0, /* mbConcatArgs */ - 1, /* mbAllowExtraInitRds */ + .defaultConfig = "/etc/yaboot.conf", + .keywords = yabootKeywords, + .entryStart = LT_KERNEL, + .needsBootPrefix = 1, + .argsInQuotes = 1, + .maxTitleLength = 15, + .mbAllowExtraInitRds = 1, }; struct configFileInfo siloConfigType = { - "/etc/silo.conf", /* defaultConfig */ - siloKeywords, /* keywords */ - 0, /* defaultIsIndex */ - 0, /* defaultSupportSaved */ - LT_KERNEL, /* entrySeparator */ - 1, /* needsBootPrefix */ - 1, /* argsInQuotes */ - 15, /* maxTitleLength */ - 0, /* titleBracketed */ - 0, /* mbHyperFirst */ - 0, /* mbInitRdIsModule */ - 0, /* mbConcatArgs */ - 0, /* mbAllowExtraInitRds */ + .defaultConfig = "/etc/silo.conf", + .keywords = siloKeywords, + .entryStart = LT_KERNEL, + .needsBootPrefix = 1, + .argsInQuotes = 1, + .maxTitleLength = 15, }; struct configFileInfo ziplConfigType = { - "/etc/zipl.conf", /* defaultConfig */ - ziplKeywords, /* keywords */ - 0, /* defaultIsIndex */ - 0, /* defaultSupportSaved */ - LT_TITLE, /* entrySeparator */ - 0, /* needsBootPrefix */ - 1, /* argsInQuotes */ - 0, /* maxTitleLength */ - 1, /* titleBracketed */ - 0, /* mbHyperFirst */ - 0, /* mbInitRdIsModule */ - 0, /* mbConcatArgs */ - 0, /* mbAllowExtraInitRds */ + .defaultConfig = "/etc/zipl.conf", + .keywords = ziplKeywords, + .entryStart = LT_TITLE, + .argsInQuotes = 1, + .titleBracketed = 1, }; struct configFileInfo extlinuxConfigType = { - "/boot/extlinux/extlinux.conf", /* defaultConfig */ - extlinuxKeywords, /* keywords */ - 0, /* defaultIsIndex */ - 0, /* defaultSupportSaved */ - LT_TITLE, /* entrySeparator */ - 1, /* needsBootPrefix */ - 0, /* argsInQuotes */ - 255, /* maxTitleLength */ - 0, /* titleBracketed */ - 0, /* mbHyperFirst */ - 0, /* mbInitRdIsModule */ - 0, /* mbConcatArgs */ - 1, /* mbAllowExtraInitRds */ + .defaultConfig = "/boot/extlinux/extlinux.conf", + .keywords = extlinuxKeywords, + .entryStart = LT_TITLE, + .needsBootPrefix = 1, + .maxTitleLength = 255, + .mbAllowExtraInitRds = 1, }; struct grubConfig { @@ -484,9 +439,9 @@ return 0; } -static int isEntrySeparator(struct singleLine * line, +static int isEntryStart(struct singleLine * line, struct configFileInfo * cfi) { - return line->type == cfi->entrySeparator || line->type == LT_OTHER || + return line->type == cfi->entryStart || line->type == LT_OTHER || (cfi->titleBracketed && isBracketedTitle(line)); } @@ -809,7 +764,7 @@ cfg->secondaryIndent = strdup(line->indent); } - if (isEntrySeparator(line, cfi)) { + if (isEntryStart(line, cfi)) { sawEntry = 1; if (!entry) { cfg->entries = malloc(sizeof(*entry)); @@ -1293,6 +1248,10 @@ if (!rootdev) return 0; + if (!getuuidbydev(rootdev) || !getuuidbydev(dev)) { + free(rootdev); + return 0; + } if (strcmp(getuuidbydev(rootdev), getuuidbydev(dev))) { free(rootdev); @@ -1975,7 +1934,7 @@ const char ** arg; int useKernelArgs, useRoot; int firstElement; - int *usedElements, *usedArgs; + int *usedElements; int doreplace; if (!image) return 0; @@ -2010,9 +1969,6 @@ useRoot = (getKeywordByType(LT_ROOT, cfg->cfi) && !multibootArgs); - for (k = 0, arg = newArgs; *arg; arg++, k++) ; - usedArgs = calloc(k, sizeof(*usedArgs)); - for (; (entry = findEntryByPath(cfg, image, prefix, &index)); index++) { if (multibootArgs && !entry->multiboot) @@ -2088,7 +2044,6 @@ usedElements = calloc(line->numElements, sizeof(*usedElements)); for (k = 0, arg = newArgs; *arg; arg++, k++) { - if (usedArgs[k]) continue; doreplace = 1; for (i = firstElement; i < line->numElements; i++) { @@ -2103,7 +2058,6 @@ continue; if (!argMatch(line->elements[i].item, *arg)) { usedElements[i]=1; - usedArgs[k]=1; break; } } @@ -2173,7 +2127,6 @@ } } - free(usedArgs); free(newArgs); free(oldArgs); @@ -2722,7 +2675,7 @@ /* don't have a template, so start the entry with the * appropriate starting line */ - switch (config->cfi->entrySeparator) { + switch (config->cfi->entryStart) { case LT_KERNEL: if (new->multiboot && config->cfi->mbHyperFirst) { /* fall through to LT_HYPER */ @@ -2774,7 +2727,7 @@ /* add the remainder of the lines, i.e. those that either * weren't present in the template, or in the case of no template, - * all the lines following the entrySeparator. + * all the lines following the entryStart. */ if (needs & NEED_TITLE) { newLine = addLine(new, config->cfi, LT_TITLE,