Magellan Linux

Diff of /trunk/grubby/grubby.c

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

revision 2957 by niro, Wed Jun 29 14:06:18 2016 UTC revision 2977 by niro, Thu Jun 30 10:24:27 2016 UTC
# Line 582  struct keywordTypes extlinuxKeywords[] = Line 582  struct keywordTypes extlinuxKeywords[] =
582      { "initrd",    LT_INITRD,      ' ', ',' },      { "initrd",    LT_INITRD,      ' ', ',' },
583      { "append",    LT_KERNELARGS,  ' ' },      { "append",    LT_KERNELARGS,  ' ' },
584      { "prompt",     LT_UNKNOWN,     ' ' },      { "prompt",     LT_UNKNOWN,     ' ' },
585        { "fdt",        LT_DEVTREE,     ' ' },
586        { "fdtdir",     LT_DEVTREE,     ' ' },
587      { NULL,    0, 0 },      { NULL,    0, 0 },
588  };  };
589  int useextlinuxmenu;  int useextlinuxmenu;
# Line 827  static int isEntryStart(struct singleLin Line 829  static int isEntryStart(struct singleLin
829    
830  /* extract the title from within brackets (for zipl) */  /* extract the title from within brackets (for zipl) */
831  static char * extractTitle(struct singleLine * line) {  static char * extractTitle(struct singleLine * line) {
832      /* bracketed title... let's extract it (leaks a byte) */      /* bracketed title... let's extract it */
833      char * title = NULL;      char * title = NULL;
834      if (line->type == LT_TITLE) {      if (line->type == LT_TITLE) {
835   title = strdup(line->elements[0].item);   title = strdup(line->elements[0].item + 1);
  title++;  
836   *(title + strlen(title) - 1) = '\0';   *(title + strlen(title) - 1) = '\0';
837      } else if (line->type == LT_MENUENTRY)      } else if (line->type == LT_MENUENTRY)
838   title = strdup(line->elements[1].item);   title = strdup(line->elements[1].item);
# Line 2120  struct singleEntry * findTemplate(struct Line 2121  struct singleEntry * findTemplate(struct
2121   } else {   } else {
2122      entry = findEntryByTitle(cfg, defTitle, &index);      entry = findEntryByTitle(cfg, defTitle, &index);
2123   }   }
2124   if (entry)   if (entry && suitableImage(entry, prefix, skipRemoved, flags)) {
2125      cfg->defaultImage = index;      cfg->defaultImage = index;
2126        if (indexPtr)
2127     *indexPtr = index;
2128        return entry;
2129     }
2130      }      }
2131   }   }
2132      } else if (cfg->defaultImage > -1) {      } else if (cfg->defaultImage > -1) {
# Line 2366  void displayEntry(struct singleEntry * e Line 2371  void displayEntry(struct singleEntry * e
2371      } else {      } else {
2372   char * title;   char * title;
2373   line = getLineByType(LT_MENUENTRY, entry->lines);   line = getLineByType(LT_MENUENTRY, entry->lines);
2374   title = grub2ExtractTitle(line);   if (line) {
2375   if (title)      title = grub2ExtractTitle(line);
2376      printf("title=%s\n", title);      if (title)
2377     printf("title=%s\n", title);
2378     }
2379      }      }
2380    
2381      for (j = 0, line = entry->lines; line; line = line->next) {      for (j = 0, line = entry->lines; line; line = line->next) {
# Line 3305  int updateImage(struct grubConfig * cfg, Line 3312  int updateImage(struct grubConfig * cfg,
3312  }  }
3313    
3314  int addMBInitrd(struct grubConfig * cfg, const char *newMBKernel,  int addMBInitrd(struct grubConfig * cfg, const char *newMBKernel,
3315   const char * image, const char * prefix, const char * initrd) {   const char * image, const char * prefix, const char * initrd,
3316     const char * title) {
3317      struct singleEntry * entry;      struct singleEntry * entry;
3318      struct singleLine * line, * kernelLine, *endLine = NULL;      struct singleLine * line, * kernelLine, *endLine = NULL;
3319      int index = 0;      int index = 0;
# Line 3316  int addMBInitrd(struct grubConfig * cfg, Line 3324  int addMBInitrd(struct grubConfig * cfg,
3324          kernelLine = getLineByType(LT_MBMODULE, entry->lines);          kernelLine = getLineByType(LT_MBMODULE, entry->lines);
3325          if (!kernelLine) continue;          if (!kernelLine) continue;
3326    
3327     /* if title is supplied, the entry's title must match it. */
3328     if (title) {
3329        char *linetitle;
3330    
3331        line = getLineByType(LT_TITLE|LT_MENUENTRY, entry->lines);
3332        if (!line)
3333     continue;
3334    
3335        linetitle = extractTitle(line);
3336        if (!linetitle)
3337     continue;
3338        if (strcmp(title, linetitle)) {
3339     free(linetitle);
3340     continue;
3341        }
3342        free(linetitle);
3343     }
3344    
3345          if (prefix) {          if (prefix) {
3346              int prefixLen = strlen(prefix);              int prefixLen = strlen(prefix);
3347              if (!strncmp(initrd, prefix, prefixLen))              if (!strncmp(initrd, prefix, prefixLen))
# Line 3341  int addMBInitrd(struct grubConfig * cfg, Line 3367  int addMBInitrd(struct grubConfig * cfg,
3367  }  }
3368    
3369  int updateInitrd(struct grubConfig * cfg, const char * image,  int updateInitrd(struct grubConfig * cfg, const char * image,
3370                   const char * prefix, const char * initrd) {                   const char * prefix, const char * initrd, const char * title) {
3371      struct singleEntry * entry;      struct singleEntry * entry;
3372      struct singleLine * line, * kernelLine, *endLine = NULL;      struct singleLine * line, * kernelLine, *endLine = NULL;
3373      int index = 0;      int index = 0;
# Line 3352  int updateInitrd(struct grubConfig * cfg Line 3378  int updateInitrd(struct grubConfig * cfg
3378          kernelLine = getLineByType(LT_KERNEL|LT_KERNEL_EFI|LT_KERNEL_16, entry->lines);          kernelLine = getLineByType(LT_KERNEL|LT_KERNEL_EFI|LT_KERNEL_16, entry->lines);
3379          if (!kernelLine) continue;          if (!kernelLine) continue;
3380    
3381     /* if title is supplied, the entry's title must match it. */
3382     if (title) {
3383        char *linetitle;
3384    
3385        line = getLineByType(LT_TITLE|LT_MENUENTRY, entry->lines);
3386        if (!line)
3387     continue;
3388    
3389        linetitle = extractTitle(line);
3390        if (!linetitle)
3391     continue;
3392        if (strcmp(title, linetitle)) {
3393     free(linetitle);
3394     continue;
3395        }
3396        free(linetitle);
3397     }
3398    
3399          line = getLineByType(LT_INITRD|LT_INITRD_EFI|LT_INITRD_16, entry->lines);          line = getLineByType(LT_INITRD|LT_INITRD_EFI|LT_INITRD_16, entry->lines);
3400          if (line)          if (line)
3401              removeLine(entry, line);              removeLine(entry, line);
# Line 4226  int main(int argc, const char ** argv) { Line 4270  int main(int argc, const char ** argv) {
4270      _("display the title of the default kernel") },      _("display the title of the default kernel") },
4271   { "devtree", 0, POPT_ARG_STRING, &newDevTreePath, 0,   { "devtree", 0, POPT_ARG_STRING, &newDevTreePath, 0,
4272      _("device tree file for new stanza"), _("dtb-path") },      _("device tree file for new stanza"), _("dtb-path") },
4273     { "devtreedir", 0, POPT_ARG_STRING, &newDevTreePath, 0,
4274        _("device tree directory for new stanza"), _("dtb-path") },
4275   { "elilo", 0, POPT_ARG_NONE, &configureELilo, 0,   { "elilo", 0, POPT_ARG_NONE, &configureELilo, 0,
4276      _("configure elilo bootloader") },      _("configure elilo bootloader") },
4277   { "efi", 0, POPT_ARG_NONE, &isEfi, 0,   { "efi", 0, POPT_ARG_NONE, &isEfi, 0,
# Line 4410  int main(int argc, const char ** argv) { Line 4456  int main(int argc, const char ** argv) {
4456      if (newKernelPath && !newKernelTitle) {      if (newKernelPath && !newKernelTitle) {
4457   fprintf(stderr, _("grubby: kernel title must be specified\n"));   fprintf(stderr, _("grubby: kernel title must be specified\n"));
4458   return 1;   return 1;
4459      } else if (!newKernelPath && (newKernelTitle  || copyDefault ||      } else if (!newKernelPath && (copyDefault ||
4460    (newKernelInitrd && !updateKernelPath)||    (newKernelInitrd && !updateKernelPath)||
4461    makeDefault || extraInitrdCount > 0)) {    makeDefault || extraInitrdCount > 0)) {
4462   fprintf(stderr, _("grubby: kernel path expected\n"));   fprintf(stderr, _("grubby: kernel path expected\n"));
# Line 4632  int main(int argc, const char ** argv) { Line 4678  int main(int argc, const char ** argv) {
4678      if (updateKernelPath && newKernelInitrd) {      if (updateKernelPath && newKernelInitrd) {
4679      if (newMBKernel) {      if (newMBKernel) {
4680      if (addMBInitrd(config, newMBKernel, updateKernelPath,      if (addMBInitrd(config, newMBKernel, updateKernelPath,
4681   bootPrefix, newKernelInitrd))   bootPrefix, newKernelInitrd,
4682     newKernelTitle))
4683      return 1;      return 1;
4684      } else {      } else {
4685      if (updateInitrd(config, updateKernelPath, bootPrefix,      if (updateInitrd(config, updateKernelPath, bootPrefix,
4686   newKernelInitrd))   newKernelInitrd, newKernelTitle))
4687   return 1;   return 1;
4688      }      }
4689      }      }

Legend:
Removed from v.2957  
changed lines
  Added in v.2977