Magellan Linux

Diff of /trunk/grubby/grubby.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2700 by niro, Wed Jul 16 10:52:01 2014 UTC revision 2980 by niro, Thu Jun 30 10:26:25 2016 UTC
# Line 222  struct configFileInfo grubConfigType = { Line 222  struct configFileInfo grubConfigType = {
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[] = {
# Line 582  struct keywordTypes extlinuxKeywords[] = Line 583  struct keywordTypes extlinuxKeywords[] =
583      { "initrd",    LT_INITRD,      ' ', ',' },      { "initrd",    LT_INITRD,      ' ', ',' },
584      { "append",    LT_KERNELARGS,  ' ' },      { "append",    LT_KERNELARGS,  ' ' },
585      { "prompt",     LT_UNKNOWN,     ' ' },      { "prompt",     LT_UNKNOWN,     ' ' },
586        { "fdt",        LT_DEVTREE,     ' ' },
587        { "fdtdir",     LT_DEVTREE,     ' ' },
588      { NULL,    0, 0 },      { NULL,    0, 0 },
589  };  };
590  int useextlinuxmenu;  int useextlinuxmenu;
# Line 592  struct configFileInfo eliloConfigType = Line 595  struct configFileInfo eliloConfigType =
595      .needsBootPrefix = 1,      .needsBootPrefix = 1,
596      .argsInQuotes = 1,      .argsInQuotes = 1,
597      .mbConcatArgs = 1,      .mbConcatArgs = 1,
598        .titlePosition = 1,
599  };  };
600    
601  struct configFileInfo liloConfigType = {  struct configFileInfo liloConfigType = {
# Line 600  struct configFileInfo liloConfigType = { Line 604  struct configFileInfo liloConfigType = {
604      .entryStart = LT_KERNEL,      .entryStart = LT_KERNEL,
605      .argsInQuotes = 1,      .argsInQuotes = 1,
606      .maxTitleLength = 15,      .maxTitleLength = 15,
607        .titlePosition = 1,
608  };  };
609    
610  struct configFileInfo yabootConfigType = {  struct configFileInfo yabootConfigType = {
# Line 610  struct configFileInfo yabootConfigType = Line 615  struct configFileInfo yabootConfigType =
615      .argsInQuotes = 1,      .argsInQuotes = 1,
616      .maxTitleLength = 15,      .maxTitleLength = 15,
617      .mbAllowExtraInitRds = 1,      .mbAllowExtraInitRds = 1,
618        .titlePosition = 1,
619  };  };
620    
621  struct configFileInfo siloConfigType = {  struct configFileInfo siloConfigType = {
# Line 619  struct configFileInfo siloConfigType = { Line 625  struct configFileInfo siloConfigType = {
625      .needsBootPrefix = 1,      .needsBootPrefix = 1,
626      .argsInQuotes = 1,      .argsInQuotes = 1,
627      .maxTitleLength = 15,      .maxTitleLength = 15,
628        .titlePosition = 1,
629  };  };
630    
631  struct configFileInfo ziplConfigType = {  struct configFileInfo ziplConfigType = {
# Line 638  struct configFileInfo extlinuxConfigType Line 645  struct configFileInfo extlinuxConfigType
645      .maxTitleLength = 255,      .maxTitleLength = 255,
646      .mbAllowExtraInitRds = 1,      .mbAllowExtraInitRds = 1,
647      .defaultIsUnquoted = 1,      .defaultIsUnquoted = 1,
648        .titlePosition = 1,
649  };  };
650    
651  struct grubConfig {  struct grubConfig {
# Line 826  static int isEntryStart(struct singleLin Line 834  static int isEntryStart(struct singleLin
834  }  }
835    
836  /* extract the title from within brackets (for zipl) */  /* extract the title from within brackets (for zipl) */
837  static char * extractTitle(struct singleLine * line) {  static char * extractTitle(struct grubConfig *cfg, struct singleLine * line) {
838      /* bracketed title... let's extract it (leaks a byte) */      /* bracketed title... let's extract it */
839      char * title = NULL;      char * title = NULL;
840        if (cfg->cfi == &grub2ConfigType)
841     return grub2ExtractTitle(line);
842      if (line->type == LT_TITLE) {      if (line->type == LT_TITLE) {
843   title = strdup(line->elements[0].item);   char *tmp = line->elements[cfg->cfi->titlePosition].item;
844   title++;   if (cfg->cfi->titleBracketed) {
845   *(title + strlen(title) - 1) = '\0';      tmp++;
846        title = strdup(tmp);
847        *(title + strlen(title) - 1) = '\0';
848     } else {
849        title = strdup(tmp);
850     }
851      } else if (line->type == LT_MENUENTRY)      } else if (line->type == LT_MENUENTRY)
852   title = strdup(line->elements[1].item);   title = strdup(line->elements[1].item);
853      else      else
# Line 1440  static struct grubConfig * readConfig(co Line 1455  static struct grubConfig * readConfig(co
1455                                  line->elements[1].item)) break;                                  line->elements[1].item)) break;
1456                  } else if (line) {                  } else if (line) {
1457                      if (!strcmp(defaultLine->elements[1].item,                      if (!strcmp(defaultLine->elements[1].item,
1458                                  extractTitle(line))) break;                                  extractTitle(cfg, line))) break;
1459                  }                  }
1460   i++;   i++;
1461   entry = NULL;   entry = NULL;
# Line 1491  static void writeDefault(FILE * out, cha Line 1506  static void writeDefault(FILE * out, cha
1506      if (!line)      if (!line)
1507   line = getLineByType(LT_TITLE, entry->lines);   line = getLineByType(LT_TITLE, entry->lines);
1508      if (line) {      if (line) {
1509   title = extractTitle(line);   title = extractTitle(cfg, line);
1510   if (title)   if (title)
1511      cfg->cfi->setEnv(cfg->cfi, "saved_entry", title);      cfg->cfi->setEnv(cfg->cfi, "saved_entry", title);
1512      }      }
# Line 1529  static void writeDefault(FILE * out, cha Line 1544  static void writeDefault(FILE * out, cha
1544              else if (line && (line->numElements == 1) &&              else if (line && (line->numElements == 1) &&
1545                       cfg->cfi->titleBracketed) {                       cfg->cfi->titleBracketed) {
1546   fprintf(out, "%sdefault%s%s\n", indent, separator,   fprintf(out, "%sdefault%s%s\n", indent, separator,
1547                          extractTitle(line));                          extractTitle(cfg, line));
1548              }              }
1549   }   }
1550      }      }
# Line 1960  struct singleEntry * findEntryByPath(str Line 1975  struct singleEntry * findEntryByPath(str
1975   }   }
1976    
1977   indexVars[i + 1] = -1;   indexVars[i + 1] = -1;
1978    
1979   i = 0;   i = 0;
1980   if (index) {   if (index) {
1981      while (i < *index) i++;      while (i < *index) {
1982      if (indexVars[i] == -1) return NULL;   i++;
1983     if (indexVars[i] == -1) return NULL;
1984        }
1985   }   }
1986    
1987   entry = findEntryByIndex(config, indexVars[i]);   entry = findEntryByIndex(config, indexVars[i]);
# Line 2118  struct singleEntry * findTemplate(struct Line 2135  struct singleEntry * findTemplate(struct
2135   } else {   } else {
2136      entry = findEntryByTitle(cfg, defTitle, &index);      entry = findEntryByTitle(cfg, defTitle, &index);
2137   }   }
2138   if (entry)   if (entry && suitableImage(entry, prefix, skipRemoved, flags)) {
2139      cfg->defaultImage = index;      cfg->defaultImage = index;
2140        if (indexPtr)
2141     *indexPtr = index;
2142        return entry;
2143     }
2144      }      }
2145   }   }
2146      } else if (cfg->defaultImage > -1) {      } else if (cfg->defaultImage > -1) {
# Line 2276  void displayEntry(struct singleEntry * e Line 2297  void displayEntry(struct singleEntry * e
2297      struct singleLine * line;      struct singleLine * line;
2298      char * root = NULL;      char * root = NULL;
2299      int i;      int i;
2300        int j;
2301    
2302      printf("index=%d\n", index);      printf("index=%d\n", index);
2303    
# Line 2363  void displayEntry(struct singleEntry * e Line 2385  void displayEntry(struct singleEntry * e
2385      } else {      } else {
2386   char * title;   char * title;
2387   line = getLineByType(LT_MENUENTRY, entry->lines);   line = getLineByType(LT_MENUENTRY, entry->lines);
2388   title = grub2ExtractTitle(line);   if (line) {
2389   if (title)      title = grub2ExtractTitle(line);
2390      printf("title=%s\n", title);      if (title)
2391     printf("title=%s\n", title);
2392     }
2393        }
2394    
2395        for (j = 0, line = entry->lines; line; line = line->next) {
2396     if ((line->type & LT_MBMODULE) && line->numElements >= 2) {
2397        if (!strncmp(prefix, line->elements[1].item, strlen(prefix)))
2398     printf("mbmodule%d=", j);
2399        else
2400     printf("mbmodule%d=%s", j, prefix);
2401    
2402        for (i = 1; i < line->numElements; i++)
2403     printf("%s%s", line->elements[i].item, line->elements[i].indent);
2404        printf("\n");
2405        j++;
2406     }
2407      }      }
2408  }  }
2409    
# Line 3288  int updateImage(struct grubConfig * cfg, Line 3326  int updateImage(struct grubConfig * cfg,
3326  }  }
3327    
3328  int addMBInitrd(struct grubConfig * cfg, const char *newMBKernel,  int addMBInitrd(struct grubConfig * cfg, const char *newMBKernel,
3329   const char * image, const char * prefix, const char * initrd) {   const char * image, const char * prefix, const char * initrd,
3330     const char * title) {
3331      struct singleEntry * entry;      struct singleEntry * entry;
3332      struct singleLine * line, * kernelLine, *endLine = NULL;      struct singleLine * line, * kernelLine, *endLine = NULL;
3333      int index = 0;      int index = 0;
3334    
3335      if (!image) return 0;      if (!image) return 0;
3336    
3337      for (; (entry = findEntryByPath(cfg, newMBKernel, prefix, &index)); index++) {      for (; (entry = findEntryByPath(cfg, image, prefix, &index)); index++) {
3338          kernelLine = getLineByType(LT_MBMODULE, entry->lines);          kernelLine = getLineByType(LT_MBMODULE, entry->lines);
3339          if (!kernelLine) continue;          if (!kernelLine) continue;
3340    
3341     /* if title is supplied, the entry's title must match it. */
3342     if (title) {
3343        char *linetitle;
3344    
3345        line = getLineByType(LT_TITLE|LT_MENUENTRY, entry->lines);
3346        if (!line)
3347     continue;
3348    
3349        linetitle = extractTitle(cfg, line);
3350        if (!linetitle)
3351     continue;
3352        if (strcmp(title, linetitle)) {
3353     free(linetitle);
3354     continue;
3355        }
3356        free(linetitle);
3357     }
3358    
3359          if (prefix) {          if (prefix) {
3360              int prefixLen = strlen(prefix);              int prefixLen = strlen(prefix);
3361              if (!strncmp(initrd, prefix, prefixLen))              if (!strncmp(initrd, prefix, prefixLen))
# Line 3324  int addMBInitrd(struct grubConfig * cfg, Line 3381  int addMBInitrd(struct grubConfig * cfg,
3381  }  }
3382    
3383  int updateInitrd(struct grubConfig * cfg, const char * image,  int updateInitrd(struct grubConfig * cfg, const char * image,
3384                   const char * prefix, const char * initrd) {                   const char * prefix, const char * initrd, const char * title) {
3385      struct singleEntry * entry;      struct singleEntry * entry;
3386      struct singleLine * line, * kernelLine, *endLine = NULL;      struct singleLine * line, * kernelLine, *endLine = NULL;
3387      int index = 0;      int index = 0;
# Line 3335  int updateInitrd(struct grubConfig * cfg Line 3392  int updateInitrd(struct grubConfig * cfg
3392          kernelLine = getLineByType(LT_KERNEL|LT_KERNEL_EFI|LT_KERNEL_16, entry->lines);          kernelLine = getLineByType(LT_KERNEL|LT_KERNEL_EFI|LT_KERNEL_16, entry->lines);
3393          if (!kernelLine) continue;          if (!kernelLine) continue;
3394    
3395     /* if title is supplied, the entry's title must match it. */
3396     if (title) {
3397        char *linetitle;
3398    
3399        line = getLineByType(LT_TITLE|LT_MENUENTRY, entry->lines);
3400        if (!line)
3401     continue;
3402    
3403        linetitle = extractTitle(cfg, line);
3404        if (!linetitle)
3405     continue;
3406        if (strcmp(title, linetitle)) {
3407     free(linetitle);
3408     continue;
3409        }
3410        free(linetitle);
3411     }
3412    
3413          line = getLineByType(LT_INITRD|LT_INITRD_EFI|LT_INITRD_16, entry->lines);          line = getLineByType(LT_INITRD|LT_INITRD_EFI|LT_INITRD_16, entry->lines);
3414          if (line)          if (line)
3415              removeLine(entry, line);              removeLine(entry, line);
# Line 4038  int addNewKernel(struct grubConfig * con Line 4113  int addNewKernel(struct grubConfig * con
4113   }   }
4114      }      }
4115    
4116        struct singleLine *endLine = NULL;
4117        endLine = getLineByType(LT_ENTRY_END, new->lines);
4118        if (endLine) {
4119        removeLine(new, endLine);
4120        needs |= NEED_END;
4121        }
4122    
4123      /* add the remainder of the lines, i.e. those that either      /* add the remainder of the lines, i.e. those that either
4124       * 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,
4125       * all the lines following the entryStart.       * all the lines following the entryStart.
# Line 4096  int addNewKernel(struct grubConfig * con Line 4178  int addNewKernel(struct grubConfig * con
4178   config->secondaryIndent, NULL);   config->secondaryIndent, NULL);
4179   needs &= ~NEED_END;   needs &= ~NEED_END;
4180      }      }
4181    
4182      if (needs) {      if (needs) {
4183   printf(_("grubby: needs=%d, aborting\n"), needs);   printf(_("grubby: needs=%d, aborting\n"), needs);
4184   abort();   abort();
# Line 4201  int main(int argc, const char ** argv) { Line 4284  int main(int argc, const char ** argv) {
4284      _("display the title of the default kernel") },      _("display the title of the default kernel") },
4285   { "devtree", 0, POPT_ARG_STRING, &newDevTreePath, 0,   { "devtree", 0, POPT_ARG_STRING, &newDevTreePath, 0,
4286      _("device tree file for new stanza"), _("dtb-path") },      _("device tree file for new stanza"), _("dtb-path") },
4287     { "devtreedir", 0, POPT_ARG_STRING, &newDevTreePath, 0,
4288        _("device tree directory for new stanza"), _("dtb-path") },
4289   { "elilo", 0, POPT_ARG_NONE, &configureELilo, 0,   { "elilo", 0, POPT_ARG_NONE, &configureELilo, 0,
4290      _("configure elilo bootloader") },      _("configure elilo bootloader") },
4291   { "efi", 0, POPT_ARG_NONE, &isEfi, 0,   { "efi", 0, POPT_ARG_NONE, &isEfi, 0,
# Line 4385  int main(int argc, const char ** argv) { Line 4470  int main(int argc, const char ** argv) {
4470      if (newKernelPath && !newKernelTitle) {      if (newKernelPath && !newKernelTitle) {
4471   fprintf(stderr, _("grubby: kernel title must be specified\n"));   fprintf(stderr, _("grubby: kernel title must be specified\n"));
4472   return 1;   return 1;
4473      } else if (!newKernelPath && (newKernelTitle  || copyDefault ||      } else if (!newKernelPath && (copyDefault ||
4474    (newKernelInitrd && !updateKernelPath)||    (newKernelInitrd && !updateKernelPath)||
4475    makeDefault || extraInitrdCount > 0)) {    makeDefault || extraInitrdCount > 0)) {
4476   fprintf(stderr, _("grubby: kernel path expected\n"));   fprintf(stderr, _("grubby: kernel path expected\n"));
# Line 4607  int main(int argc, const char ** argv) { Line 4692  int main(int argc, const char ** argv) {
4692      if (updateKernelPath && newKernelInitrd) {      if (updateKernelPath && newKernelInitrd) {
4693      if (newMBKernel) {      if (newMBKernel) {
4694      if (addMBInitrd(config, newMBKernel, updateKernelPath,      if (addMBInitrd(config, newMBKernel, updateKernelPath,
4695   bootPrefix, newKernelInitrd))   bootPrefix, newKernelInitrd,
4696     newKernelTitle))
4697      return 1;      return 1;
4698      } else {      } else {
4699      if (updateInitrd(config, updateKernelPath, bootPrefix,      if (updateInitrd(config, updateKernelPath, bootPrefix,
4700   newKernelInitrd))   newKernelInitrd, newKernelTitle))
4701   return 1;   return 1;
4702      }      }
4703      }      }

Legend:
Removed from v.2700  
changed lines
  Added in v.2980