Magellan Linux

Diff of /trunk/grubby/grubby.c

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

revision 3017 by niro, Tue Jun 27 14:36:53 2017 UTC revision 3018 by niro, Tue Jun 27 14:37:30 2017 UTC
# Line 132  struct singleEntry { Line 132  struct singleEntry {
132  #define NEED_DEVTREE (1 << 6)  #define NEED_DEVTREE (1 << 6)
133    
134  #define MAIN_DEFAULT    (1 << 0)  #define MAIN_DEFAULT    (1 << 0)
135    #define FIRST_ENTRY_INDEX    0 /* boot entry index value begin and increment
136       from this initial value */
137    #define NO_DEFAULT_ENTRY    -1 /* indicates that no specific default boot
138       entry was set or currently exists */
139  #define DEFAULT_SAVED       -2  #define DEFAULT_SAVED       -2
140  #define DEFAULT_SAVED_GRUB2 -3  #define DEFAULT_SAVED_GRUB2 -3
141    
# Line 1615  static struct grubConfig *readConfig(con Line 1619  static struct grubConfig *readConfig(con
1619   *end == ' ' || *end == '\t'))   *end == ' ' || *end == '\t'))
1620   end++;   end++;
1621   if (*end)   if (*end)
1622   cfg->defaultImage = -1;   cfg->defaultImage = NO_DEFAULT_ENTRY;
1623   } else if (defaultLine->numElements == 3) {   } else if (defaultLine->numElements == 3) {
1624   char *value = defaultLine->elements[2].item;   char *value = defaultLine->elements[2].item;
1625   while (*value && (*value == '"' ||   while (*value && (*value == '"' ||
# Line 1628  static struct grubConfig *readConfig(con Line 1632  static struct grubConfig *readConfig(con
1632   *end == ' ' || *end == '\t'))   *end == ' ' || *end == '\t'))
1633   end++;   end++;
1634   if (*end)   if (*end)
1635   cfg->defaultImage = -1;   cfg->defaultImage = NO_DEFAULT_ENTRY;
1636   }   }
1637   } else if (cfi->defaultSupportSaved &&   } else if (cfi->defaultSupportSaved &&
1638     !strncmp(defaultLine->elements[1].item, "saved",     !strncmp(defaultLine->elements[1].item, "saved",
# Line 1638  static struct grubConfig *readConfig(con Line 1642  static struct grubConfig *readConfig(con
1642   cfg->defaultImage =   cfg->defaultImage =
1643      strtol(defaultLine->elements[1].item, &end, 10);      strtol(defaultLine->elements[1].item, &end, 10);
1644   if (*end)   if (*end)
1645   cfg->defaultImage = -1;   cfg->defaultImage = NO_DEFAULT_ENTRY;
1646   } else if (defaultLine->numElements >= 2) {   } else if (defaultLine->numElements >= 2) {
1647   int i = 0;   int i = 0;
1648   while ((entry = findEntryByIndex(cfg, i))) {   while ((entry = findEntryByIndex(cfg, i))) {
# Line 1666  static struct grubConfig *readConfig(con Line 1670  static struct grubConfig *readConfig(con
1670   if (entry) {   if (entry) {
1671   cfg->defaultImage = i;   cfg->defaultImage = i;
1672   } else {   } else {
1673   cfg->defaultImage = -1;   cfg->defaultImage = NO_DEFAULT_ENTRY;
1674   }   }
1675   }   }
1676   } else if (cfg->cfi->defaultIsSaved && cfg->cfi->getEnv) {   } else if (cfg->cfi->defaultIsSaved && cfg->cfi->getEnv) {
# Line 1683  static struct grubConfig *readConfig(con Line 1687  static struct grubConfig *readConfig(con
1687   cfg->defaultImage = index;   cfg->defaultImage = index;
1688   }   }
1689   } else {   } else {
1690   cfg->defaultImage = 0;   cfg->defaultImage = FIRST_ENTRY_INDEX;
1691   }   }
1692    
1693   return cfg;   return cfg;
# Line 1703  static void writeDefault(FILE * out, cha Line 1707  static void writeDefault(FILE * out, cha
1707   fprintf(out, "%sdefault%ssaved\n", indent, separator);   fprintf(out, "%sdefault%ssaved\n", indent, separator);
1708   else if (cfg->cfi->defaultIsSaved) {   else if (cfg->cfi->defaultIsSaved) {
1709   fprintf(out, "%sset default=\"${saved_entry}\"\n", indent);   fprintf(out, "%sset default=\"${saved_entry}\"\n", indent);
1710   if (cfg->defaultImage >= 0 && cfg->cfi->setEnv) {   if (cfg->defaultImage >= FIRST_ENTRY_INDEX && cfg->cfi->setEnv) {
1711   char *title;   char *title;
1712   entry = findEntryByIndex(cfg, cfg->defaultImage);   entry = findEntryByIndex(cfg, cfg->defaultImage);
1713   line = getLineByType(LT_MENUENTRY, entry->lines);   line = getLineByType(LT_MENUENTRY, entry->lines);
# Line 1716  static void writeDefault(FILE * out, cha Line 1720  static void writeDefault(FILE * out, cha
1720   "saved_entry", title);   "saved_entry", title);
1721   }   }
1722   }   }
1723   } else if (cfg->defaultImage > -1) {   } else if (cfg->defaultImage >= FIRST_ENTRY_INDEX) {
1724   if (cfg->cfi->defaultIsIndex) {   if (cfg->cfi->defaultIsIndex) {
1725   if (cfg->cfi->defaultIsVariable) {   if (cfg->cfi->defaultIsVariable) {
1726   fprintf(out, "%sset default=\"%d\"\n", indent,   fprintf(out, "%sset default=\"%d\"\n", indent,
# Line 2420  struct singleEntry *findTemplate(struct Line 2424  struct singleEntry *findTemplate(struct
2424   }   }
2425   }   }
2426   }   }
2427   } else if (cfg->defaultImage > -1) {   } else if (cfg->defaultImage >= FIRST_ENTRY_INDEX) {
2428   entry = findEntryByIndex(cfg, cfg->defaultImage);   entry = findEntryByIndex(cfg, cfg->defaultImage);
2429   if (entry && suitableImage(entry, prefix, skipRemoved, flags)) {   if (entry && suitableImage(entry, prefix, skipRemoved, flags)) {
2430   if (indexPtr)   if (indexPtr)
# Line 2502  void setDefaultImage(struct grubConfig * Line 2506  void setDefaultImage(struct grubConfig *
2506   int i, j;   int i, j;
2507    
2508   if (newBootEntryIsDefault) {   if (newBootEntryIsDefault) {
2509   config->defaultImage = 0;   config->defaultImage = FIRST_ENTRY_INDEX;
2510   return;   return;
2511   } else if ((newDefaultBootEntryIndex >= 0) && config->cfi->defaultIsIndex) {   } else if ((newDefaultBootEntryIndex >= 0) && config->cfi->defaultIsIndex) {
2512   if (findEntryByIndex(config, newDefaultBootEntryIndex))   if (findEntryByIndex(config, newDefaultBootEntryIndex))
2513   config->defaultImage = newDefaultBootEntryIndex;   config->defaultImage = newDefaultBootEntryIndex;
2514   else   else
2515   config->defaultImage = -1;   config->defaultImage = NO_DEFAULT_ENTRY;
2516   return;   return;
2517   } else if (defaultKernelPath) {   } else if (defaultKernelPath) {
2518   i = 0;   i = 0;
2519   if (findEntryByPath(config, defaultKernelPath, prefix, &i)) {   if (findEntryByPath(config, defaultKernelPath, prefix, &i)) {
2520   config->defaultImage = i;   config->defaultImage = i;
2521   } else {   } else {
2522   config->defaultImage = -1;   config->defaultImage = NO_DEFAULT_ENTRY;
2523   return;   return;
2524   }   }
2525   }   }
# Line 2527  void setDefaultImage(struct grubConfig * Line 2531  void setDefaultImage(struct grubConfig *
2531   /* default is set to saved, we don't want to change it */   /* default is set to saved, we don't want to change it */
2532   return;   return;
2533    
2534   if (config->defaultImage > -1)   if (config->defaultImage >= FIRST_ENTRY_INDEX)
2535   entry = findEntryByIndex(config, config->defaultImage);   entry = findEntryByIndex(config, config->defaultImage);
2536   else   else
2537   entry = NULL;   entry = NULL;
# Line 2544  void setDefaultImage(struct grubConfig * Line 2548  void setDefaultImage(struct grubConfig *
2548   config->defaultImage--;   config->defaultImage--;
2549   }   }
2550   } else if (isUserSpecifiedKernelPath) {   } else if (isUserSpecifiedKernelPath) {
2551   config->defaultImage = 0;   config->defaultImage = FIRST_ENTRY_INDEX;
2552   } else {   } else {
2553   /* Either we just erased the default (or the default line was   /* Either we just erased the default (or the default line was
2554   * bad to begin with) and didn't put a new one in. We'll use   * bad to begin with) and didn't put a new one in. We'll use
# Line 2553  void setDefaultImage(struct grubConfig * Line 2557  void setDefaultImage(struct grubConfig *
2557      findTemplate(config, prefix, &config->defaultImage, 1,      findTemplate(config, prefix, &config->defaultImage, 1,
2558   flags);   flags);
2559   if (!newDefault)   if (!newDefault)
2560   config->defaultImage = -1;   config->defaultImage = NO_DEFAULT_ENTRY;
2561   }   }
2562  }  }
2563    
# Line 5178  int main(int argc, const char **argv) Line 5182  int main(int argc, const char **argv)
5182   struct singleEntry *entry;   struct singleEntry *entry;
5183   char *rootspec;   char *rootspec;
5184    
5185   if (config->defaultImage == -1)   if (config->defaultImage == NO_DEFAULT_ENTRY)
5186   return 0;   return 0;
5187   if (config->defaultImage == DEFAULT_SAVED_GRUB2 &&   if (config->defaultImage == DEFAULT_SAVED_GRUB2 &&
5188      cfi->defaultIsSaved)      cfi->defaultIsSaved)
5189   config->defaultImage = 0;   config->defaultImage = FIRST_ENTRY_INDEX;
5190   entry = findEntryByIndex(config, config->defaultImage);   entry = findEntryByIndex(config, config->defaultImage);
5191   if (!entry)   if (!entry)
5192   return 0;   return 0;
# Line 5205  int main(int argc, const char **argv) Line 5209  int main(int argc, const char **argv)
5209   struct singleLine *line;   struct singleLine *line;
5210   struct singleEntry *entry;   struct singleEntry *entry;
5211    
5212   if (config->defaultImage == -1)   if (config->defaultImage == NO_DEFAULT_ENTRY)
5213   return 0;   return 0;
5214   if (config->defaultImage == DEFAULT_SAVED_GRUB2 &&   if (config->defaultImage == DEFAULT_SAVED_GRUB2 &&
5215      cfi->defaultIsSaved)      cfi->defaultIsSaved)
5216   config->defaultImage = 0;   config->defaultImage = FIRST_ENTRY_INDEX;
5217   entry = findEntryByIndex(config, config->defaultImage);   entry = findEntryByIndex(config, config->defaultImage);
5218   if (!entry)   if (!entry)
5219   return 0;   return 0;
# Line 5239  int main(int argc, const char **argv) Line 5243  int main(int argc, const char **argv)
5243   return 0;   return 0;
5244    
5245   } else if (displayDefaultIndex) {   } else if (displayDefaultIndex) {
5246   if (config->defaultImage == -1)   if (config->defaultImage == NO_DEFAULT_ENTRY)
5247   return 0;   return 0;
5248   if (config->defaultImage == DEFAULT_SAVED_GRUB2 &&   if (config->defaultImage == DEFAULT_SAVED_GRUB2 &&
5249      cfi->defaultIsSaved)      cfi->defaultIsSaved)
5250   config->defaultImage = 0;   config->defaultImage = FIRST_ENTRY_INDEX;
5251   printf("%i\n", config->defaultImage);   printf("%i\n", config->defaultImage);
5252   return 0;   return 0;
5253    

Legend:
Removed from v.3017  
changed lines
  Added in v.3018