Magellan Linux

Diff of /tags/grubby-8_40_20170706/grubby.c

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

revision 2963 by niro, Wed Jun 29 14:41:26 2016 UTC revision 2989 by niro, Thu Jun 30 10:32:12 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 451  char *grub2ExtractTitle(struct singleLin Line 452  char *grub2ExtractTitle(struct singleLin
452       * whose last character is also quote (assuming it's the closing one) */       * whose last character is also quote (assuming it's the closing one) */
453      int resultMaxSize;      int resultMaxSize;
454      char * result;      char * result;
455        /* need to ensure that ' does not match " as we search */
456        char quote_char = *current;
457            
458      resultMaxSize = sizeOfSingleLine(line);      resultMaxSize = sizeOfSingleLine(line);
459      result = malloc(resultMaxSize);      result = malloc(resultMaxSize);
# Line 464  char *grub2ExtractTitle(struct singleLin Line 467  char *grub2ExtractTitle(struct singleLin
467   current_indent_len = strlen(current_indent);   current_indent_len = strlen(current_indent);
468    
469   strncat(result, current_indent, current_indent_len);   strncat(result, current_indent, current_indent_len);
470   if (!isquote(current[current_len-1])) {   if (current[current_len-1] != quote_char) {
471      strncat(result, current, current_len);      strncat(result, current, current_len);
472   } else {   } else {
473      strncat(result, current, current_len - 1);      strncat(result, current, current_len - 1);
# Line 582  struct keywordTypes extlinuxKeywords[] = Line 585  struct keywordTypes extlinuxKeywords[] =
585      { "initrd",    LT_INITRD,      ' ', ',' },      { "initrd",    LT_INITRD,      ' ', ',' },
586      { "append",    LT_KERNELARGS,  ' ' },      { "append",    LT_KERNELARGS,  ' ' },
587      { "prompt",     LT_UNKNOWN,     ' ' },      { "prompt",     LT_UNKNOWN,     ' ' },
588        { "fdt",        LT_DEVTREE,     ' ' },
589        { "fdtdir",     LT_DEVTREE,     ' ' },
590      { NULL,    0, 0 },      { NULL,    0, 0 },
591  };  };
592  int useextlinuxmenu;  int useextlinuxmenu;
# Line 592  struct configFileInfo eliloConfigType = Line 597  struct configFileInfo eliloConfigType =
597      .needsBootPrefix = 1,      .needsBootPrefix = 1,
598      .argsInQuotes = 1,      .argsInQuotes = 1,
599      .mbConcatArgs = 1,      .mbConcatArgs = 1,
600        .titlePosition = 1,
601  };  };
602    
603  struct configFileInfo liloConfigType = {  struct configFileInfo liloConfigType = {
# Line 600  struct configFileInfo liloConfigType = { Line 606  struct configFileInfo liloConfigType = {
606      .entryStart = LT_KERNEL,      .entryStart = LT_KERNEL,
607      .argsInQuotes = 1,      .argsInQuotes = 1,
608      .maxTitleLength = 15,      .maxTitleLength = 15,
609        .titlePosition = 1,
610  };  };
611    
612  struct configFileInfo yabootConfigType = {  struct configFileInfo yabootConfigType = {
# Line 610  struct configFileInfo yabootConfigType = Line 617  struct configFileInfo yabootConfigType =
617      .argsInQuotes = 1,      .argsInQuotes = 1,
618      .maxTitleLength = 15,      .maxTitleLength = 15,
619      .mbAllowExtraInitRds = 1,      .mbAllowExtraInitRds = 1,
620        .titlePosition = 1,
621  };  };
622    
623  struct configFileInfo siloConfigType = {  struct configFileInfo siloConfigType = {
# Line 619  struct configFileInfo siloConfigType = { Line 627  struct configFileInfo siloConfigType = {
627      .needsBootPrefix = 1,      .needsBootPrefix = 1,
628      .argsInQuotes = 1,      .argsInQuotes = 1,
629      .maxTitleLength = 15,      .maxTitleLength = 15,
630        .titlePosition = 1,
631  };  };
632    
633  struct configFileInfo ziplConfigType = {  struct configFileInfo ziplConfigType = {
# Line 638  struct configFileInfo extlinuxConfigType Line 647  struct configFileInfo extlinuxConfigType
647      .maxTitleLength = 255,      .maxTitleLength = 255,
648      .mbAllowExtraInitRds = 1,      .mbAllowExtraInitRds = 1,
649      .defaultIsUnquoted = 1,      .defaultIsUnquoted = 1,
650        .titlePosition = 1,
651  };  };
652    
653  struct grubConfig {  struct grubConfig {
# Line 826  static int isEntryStart(struct singleLin Line 836  static int isEntryStart(struct singleLin
836  }  }
837    
838  /* extract the title from within brackets (for zipl) */  /* extract the title from within brackets (for zipl) */
839  static char * extractTitle(struct singleLine * line) {  static char * extractTitle(struct grubConfig *cfg, struct singleLine * line) {
840      /* bracketed title... let's extract it (leaks a byte) */      /* bracketed title... let's extract it */
841      char * title = NULL;      char * title = NULL;
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 916  static int lineWrite(FILE * out, struct Line 931  static int lineWrite(FILE * out, struct
931   /* Need to handle this, because we strip the quotes from   /* Need to handle this, because we strip the quotes from
932   * menuentry when read it. */   * menuentry when read it. */
933   if (line->type == LT_MENUENTRY && i == 1) {   if (line->type == LT_MENUENTRY && i == 1) {
934      if(!isquote(*line->elements[i].item))      if(!isquote(*line->elements[i].item)) {
935   fprintf(out, "\'%s\'", line->elements[i].item);   int substring = 0;
936      else   /* If the line contains nested quotes, we did not strip
937     * the "interna" quotes and we must use the right quotes
938     * again when writing the updated file. */
939     for (int j = i; j < line->numElements; j++) {
940        if (strchr(line->elements[i].item, '\'') != NULL) {
941           substring = 1;
942           fprintf(out, "\"%s\"", line->elements[i].item);
943           break;
944        }
945     }
946     if (!substring)
947        fprintf(out, "\'%s\'", line->elements[i].item);
948        } else {
949   fprintf(out, "%s", line->elements[i].item);   fprintf(out, "%s", line->elements[i].item);
950        }
951      fprintf(out, "%s", line->elements[i].indent);      fprintf(out, "%s", line->elements[i].indent);
952    
953      continue;      continue;
# Line 1255  static struct grubConfig * readConfig(co Line 1283  static struct grubConfig * readConfig(co
1283      len = 0;      len = 0;
1284      char *extras;      char *extras;
1285      char *title;      char *title;
1286        /* initially unseen value */
1287        char quote_char = '\0';
1288    
1289      for (int i = 1; i < line->numElements; i++) {      for (int i = 1; i < line->numElements; i++) {
1290   len += strlen(line->elements[i].item);   len += strlen(line->elements[i].item);
# Line 1271  static struct grubConfig * readConfig(co Line 1301  static struct grubConfig * readConfig(co
1301      for (int i = 0; i < line->numElements; i++) {      for (int i = 0; i < line->numElements; i++) {
1302   if (!strcmp(line->elements[i].item, "menuentry"))   if (!strcmp(line->elements[i].item, "menuentry"))
1303      continue;      continue;
1304   if (isquote(*line->elements[i].item))   if (isquote(*line->elements[i].item) && quote_char == '\0') {
1305        /* ensure we properly pair off quotes */
1306        quote_char = *line->elements[i].item;
1307      title = line->elements[i].item + 1;      title = line->elements[i].item + 1;
1308   else   } else {
1309      title = line->elements[i].item;      title = line->elements[i].item;
1310     }
1311    
1312   len = strlen(title);   len = strlen(title);
1313          if (isquote(title[len-1])) {          if (title[len-1] == quote_char) {
1314      strncat(buf, title,len-1);      strncat(buf, title,len-1);
1315      break;      break;
1316   } else {   } else {
# Line 1288  static struct grubConfig * readConfig(co Line 1321  static struct grubConfig * readConfig(co
1321    
1322      /* get extras */      /* get extras */
1323      int count = 0;      int count = 0;
1324        quote_char = '\0';
1325      for (int i = 0; i < line->numElements; i++) {      for (int i = 0; i < line->numElements; i++) {
1326   if (count >= 2) {   if (count >= 2) {
1327      strcat(extras, line->elements[i].item);      strcat(extras, line->elements[i].item);
# Line 1298  static struct grubConfig * readConfig(co Line 1332  static struct grubConfig * readConfig(co
1332      continue;      continue;
1333    
1334   /* count ' or ", there should be two in menuentry line. */   /* count ' or ", there should be two in menuentry line. */
1335   if (isquote(*line->elements[i].item))   if (isquote(*line->elements[i].item) && quote_char == '\0') {
1336        /* ensure we properly pair off quotes */
1337                quote_char = *line->elements[i].item;
1338      count++;      count++;
1339     }
1340    
1341   len = strlen(line->elements[i].item);   len = strlen(line->elements[i].item);
1342    
1343   if (isquote(line->elements[i].item[len -1]))   if (line->elements[i].item[len -1] == quote_char)
1344      count++;      count++;
1345    
1346   /* ok, we get the final ' or ", others are extras. */   /* ok, we get the final ' or ", others are extras. */
# Line 1440  static struct grubConfig * readConfig(co Line 1477  static struct grubConfig * readConfig(co
1477                                  line->elements[1].item)) break;                                  line->elements[1].item)) break;
1478                  } else if (line) {                  } else if (line) {
1479                      if (!strcmp(defaultLine->elements[1].item,                      if (!strcmp(defaultLine->elements[1].item,
1480                                  extractTitle(line))) break;                                  extractTitle(cfg, line))) break;
1481                  }                  }
1482   i++;   i++;
1483   entry = NULL;   entry = NULL;
# Line 1491  static void writeDefault(FILE * out, cha Line 1528  static void writeDefault(FILE * out, cha
1528      if (!line)      if (!line)
1529   line = getLineByType(LT_TITLE, entry->lines);   line = getLineByType(LT_TITLE, entry->lines);
1530      if (line) {      if (line) {
1531   title = extractTitle(line);   title = extractTitle(cfg, line);
1532   if (title)   if (title)
1533      cfg->cfi->setEnv(cfg->cfi, "saved_entry", title);      cfg->cfi->setEnv(cfg->cfi, "saved_entry", title);
1534      }      }
# Line 1529  static void writeDefault(FILE * out, cha Line 1566  static void writeDefault(FILE * out, cha
1566              else if (line && (line->numElements == 1) &&              else if (line && (line->numElements == 1) &&
1567                       cfg->cfi->titleBracketed) {                       cfg->cfi->titleBracketed) {
1568   fprintf(out, "%sdefault%s%s\n", indent, separator,   fprintf(out, "%sdefault%s%s\n", indent, separator,
1569                          extractTitle(line));                          extractTitle(cfg, line));
1570              }              }
1571   }   }
1572      }      }
# Line 3331  int addMBInitrd(struct grubConfig * cfg, Line 3368  int addMBInitrd(struct grubConfig * cfg,
3368      if (!line)      if (!line)
3369   continue;   continue;
3370    
3371      linetitle = extractTitle(line);      linetitle = extractTitle(cfg, line);
3372      if (!linetitle)      if (!linetitle)
3373   continue;   continue;
3374      if (strcmp(title, linetitle)) {      if (strcmp(title, linetitle)) {
# Line 3385  int updateInitrd(struct grubConfig * cfg Line 3422  int updateInitrd(struct grubConfig * cfg
3422      if (!line)      if (!line)
3423   continue;   continue;
3424    
3425      linetitle = extractTitle(line);      linetitle = extractTitle(cfg, line);
3426      if (!linetitle)      if (!linetitle)
3427   continue;   continue;
3428      if (strcmp(title, linetitle)) {      if (strcmp(title, linetitle)) {
# Line 4269  int main(int argc, const char ** argv) { Line 4306  int main(int argc, const char ** argv) {
4306      _("display the title of the default kernel") },      _("display the title of the default kernel") },
4307   { "devtree", 0, POPT_ARG_STRING, &newDevTreePath, 0,   { "devtree", 0, POPT_ARG_STRING, &newDevTreePath, 0,
4308      _("device tree file for new stanza"), _("dtb-path") },      _("device tree file for new stanza"), _("dtb-path") },
4309     { "devtreedir", 0, POPT_ARG_STRING, &newDevTreePath, 0,
4310        _("device tree directory for new stanza"), _("dtb-path") },
4311   { "elilo", 0, POPT_ARG_NONE, &configureELilo, 0,   { "elilo", 0, POPT_ARG_NONE, &configureELilo, 0,
4312      _("configure elilo bootloader") },      _("configure elilo bootloader") },
4313   { "efi", 0, POPT_ARG_NONE, &isEfi, 0,   { "efi", 0, POPT_ARG_NONE, &isEfi, 0,
# Line 4409  int main(int argc, const char ** argv) { Line 4448  int main(int argc, const char ** argv) {
4448      }      }
4449    
4450      if (!cfi) {      if (!cfi) {
4451          if (grub2FindConfig(&grub2ConfigType))          if (grub2FindConfig(&grub2ConfigType)) {
4452      cfi = &grub2ConfigType;      cfi = &grub2ConfigType;
4453   else      if (envPath)
4454     cfi->envFile = envPath;
4455            } else
4456        #ifdef __ia64__        #ifdef __ia64__
4457      cfi = &eliloConfigType;      cfi = &eliloConfigType;
4458        #elif __powerpc__        #elif __powerpc__

Legend:
Removed from v.2963  
changed lines
  Added in v.2989