Magellan Linux

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

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

revision 1850 by niro, Mon Jul 2 13:09:12 2012 UTC revision 1864 by niro, Mon Jul 2 13:20:31 2012 UTC
# Line 164  struct keywordTypes grubKeywords[] = { Line 164  struct keywordTypes grubKeywords[] = {
164    
165  const char *grubFindConfig(struct configFileInfo *cfi) {  const char *grubFindConfig(struct configFileInfo *cfi) {
166      static const char *configFiles[] = {      static const char *configFiles[] = {
  "/etc/grub.conf",  
167   "/boot/grub/grub.conf",   "/boot/grub/grub.conf",
168   "/boot/grub/menu.lst",   "/boot/grub/menu.lst",
169     "/etc/grub.conf",
170   NULL   NULL
171      };      };
172      static int i = -1;      static int i = -1;
# Line 1867  void markRemovedImage(struct grubConfig Line 1867  void markRemovedImage(struct grubConfig
1867    
1868  void setDefaultImage(struct grubConfig * config, int hasNew,  void setDefaultImage(struct grubConfig * config, int hasNew,
1869       const char * defaultKernelPath, int newIsDefault,       const char * defaultKernelPath, int newIsDefault,
1870       const char * prefix, int flags) {       const char * prefix, int flags, int index) {
1871      struct singleEntry * entry, * entry2, * newDefault;      struct singleEntry * entry, * entry2, * newDefault;
1872      int i, j;      int i, j;
1873    
1874      if (newIsDefault) {      if (newIsDefault) {
1875   config->defaultImage = 0;   config->defaultImage = 0;
1876   return;   return;
1877        } else if ((index >= 0) && config->cfi->defaultIsIndex) {
1878     if (findEntryByIndex(config, index))
1879        config->defaultImage = index;
1880     else
1881        config->defaultImage = -1;
1882     return;
1883      } else if (defaultKernelPath) {      } else if (defaultKernelPath) {
1884   i = 0;   i = 0;
1885   if (findEntryByPath(config, defaultKernelPath, prefix, &i)) {   if (findEntryByPath(config, defaultKernelPath, prefix, &i)) {
# Line 2350  void dumpSysconfigGrub(void) { Line 2356  void dumpSysconfigGrub(void) {
2356      char * boot = NULL;      char * boot = NULL;
2357      int lba;      int lba;
2358    
2359      if (!isSuseSystem()) {      if (isSuseSystem()) {
2360          if (parseSysconfigGrub(&lba, &boot)) {          if (parseSuseGrubConf(&lba, &boot)) {
2361      free(boot);      free(boot);
2362      return;      return;
2363   }   }
2364      } else {      } else {
2365          if (parseSuseGrubConf(&lba, &boot)) {          if (parseSysconfigGrub(&lba, &boot)) {
2366      free(boot);      free(boot);
2367      return;      return;
2368   }   }
# Line 3179  int checkForGrub(struct grubConfig * con Line 3185  int checkForGrub(struct grubConfig * con
3185      int fd;      int fd;
3186      unsigned char bootSect[512];      unsigned char bootSect[512];
3187      char * boot;      char * boot;
3188      int onSuse;      int onSuse = isSuseSystem();
3189    
3190      onSuse = isSuseSystem();  
3191      if (!onSuse) {      if (onSuse) {
3192   if (parseSysconfigGrub(NULL, &boot)) return 0;   if (parseSuseGrubConf(NULL, &boot))
3193        return 0;
3194      } else {      } else {
3195   if (parseSuseGrubConf(NULL, &boot)) return 0;   if (parseSysconfigGrub(NULL, &boot))
3196        return 0;
3197      }      }
3198    
3199      /* assume grub is not installed -- not an error condition */      /* assume grub is not installed -- not an error condition */
# Line 3205  int checkForGrub(struct grubConfig * con Line 3213  int checkForGrub(struct grubConfig * con
3213      }      }
3214      close(fd);      close(fd);
3215    
3216      if (!onSuse)      /* The more elaborate checks do not work on SuSE. The checks done
3217   return checkDeviceBootloader(boot, bootSect);       * seem to be reasonble (at least for now), so just return success
3218      else       */
3219   /*      if (onSuse)
  * The more elaborate checks do not work on SuSE. The checks done  
  * seem to be reasonble (at least for now), so just return success  
  */  
3220   return 2;   return 2;
3221    
3222        return checkDeviceBootloader(boot, bootSect);
3223  }  }
3224    
3225  int checkForExtLinux(struct grubConfig * config) {  int checkForExtLinux(struct grubConfig * config) {
# Line 3245  int checkForExtLinux(struct grubConfig * Line 3252  int checkForExtLinux(struct grubConfig *
3252      return checkDeviceBootloader(boot, bootSect);      return checkDeviceBootloader(boot, bootSect);
3253  }  }
3254    
3255    int checkForYaboot(struct grubConfig * config) {
3256        /*
3257         * This is a simplistic check that we consider good enough for own puporses
3258         *
3259         * If we were to properly check if yaboot is *installed* we'd need to:
3260         * 1) get the system boot device (LT_BOOT)
3261         * 2) considering it's a raw filesystem, check if the yaboot binary matches
3262         *    the content on the boot device
3263         * 3) if not, copy the binary to a temporary file and run "addnote" on it
3264         * 4) check again if binary and boot device contents match
3265         */
3266        if (!access("/etc/yaboot.conf", R_OK))
3267     return 2;
3268    
3269        return 1;
3270    }
3271    
3272    int checkForElilo(struct grubConfig * config) {
3273        if (!access("/etc/elilo.conf", R_OK))
3274     return 2;
3275    
3276        return 1;
3277    }
3278    
3279  static char * getRootSpecifier(char * str) {  static char * getRootSpecifier(char * str) {
3280      char * idx, * rootspec = NULL;      char * idx, * rootspec = NULL;
3281    
# Line 3715  int main(int argc, const char ** argv) { Line 3746  int main(int argc, const char ** argv) {
3746      int displayDefault = 0;      int displayDefault = 0;
3747      int displayDefaultIndex = 0;      int displayDefaultIndex = 0;
3748      int displayDefaultTitle = 0;      int displayDefaultTitle = 0;
3749        int defaultIndex = -1;
3750      struct poptOption options[] = {      struct poptOption options[] = {
3751   { "add-kernel", 0, POPT_ARG_STRING, &newKernelPath, 0,   { "add-kernel", 0, POPT_ARG_STRING, &newKernelPath, 0,
3752      _("add an entry for the specified kernel"), _("kernel-path") },      _("add an entry for the specified kernel"), _("kernel-path") },
# Line 3732  int main(int argc, const char ** argv) { Line 3764  int main(int argc, const char ** argv) {
3764   { "boot-filesystem", 0, POPT_ARG_STRING, &bootPrefix, 0,   { "boot-filesystem", 0, POPT_ARG_STRING, &bootPrefix, 0,
3765      _("filestystem which contains /boot directory (for testing only)"),      _("filestystem which contains /boot directory (for testing only)"),
3766      _("bootfs") },      _("bootfs") },
3767  #if defined(__i386__) || defined(__x86_64__)  #if defined(__i386__) || defined(__x86_64__) || defined (__powerpc64__) || defined (__ia64__)
3768   { "bootloader-probe", 0, POPT_ARG_NONE, &bootloaderProbe, 0,   { "bootloader-probe", 0, POPT_ARG_NONE, &bootloaderProbe, 0,
3769      _("check if lilo is installed on lilo.conf boot sector") },      _("check which bootloader is installed on boot sector") },
3770  #endif  #endif
3771   { "config-file", 'c', POPT_ARG_STRING, &grubConfig, 0,   { "config-file", 'c', POPT_ARG_STRING, &grubConfig, 0,
3772      _("path to grub config file to update (\"-\" for stdin)"),      _("path to grub config file to update (\"-\" for stdin)"),
# Line 3787  int main(int argc, const char ** argv) { Line 3819  int main(int argc, const char ** argv) {
3819   { "set-default", 0, POPT_ARG_STRING, &defaultKernel, 0,   { "set-default", 0, POPT_ARG_STRING, &defaultKernel, 0,
3820      _("make the first entry referencing the specified kernel "      _("make the first entry referencing the specified kernel "
3821        "the default"), _("kernel-path") },        "the default"), _("kernel-path") },
3822     { "set-default-index", 0, POPT_ARG_INT, &defaultIndex, 0,
3823        _("make the given entry index the default entry"),
3824        _("entry-index") },
3825   { "silo", 0, POPT_ARG_NONE, &configureSilo, 0,   { "silo", 0, POPT_ARG_NONE, &configureSilo, 0,
3826      _("configure silo bootloader") },      _("configure silo bootloader") },
3827   { "title", 0, POPT_ARG_STRING, &newKernelTitle, 0,   { "title", 0, POPT_ARG_STRING, &newKernelTitle, 0,
# Line 3895  int main(int argc, const char ** argv) { Line 3930  int main(int argc, const char ** argv) {
3930      }      }
3931    
3932      if (bootloaderProbe && (displayDefault || kernelInfo || newKernelVersion ||      if (bootloaderProbe && (displayDefault || kernelInfo || newKernelVersion ||
3933    newKernelPath || removeKernelPath || makeDefault ||      newKernelPath || removeKernelPath || makeDefault ||
3934    defaultKernel || displayDefaultIndex || displayDefaultTitle)) {      defaultKernel || displayDefaultIndex || displayDefaultTitle ||
3935        (defaultIndex >= 0))) {
3936   fprintf(stderr, _("grubby: --bootloader-probe may not be used with "   fprintf(stderr, _("grubby: --bootloader-probe may not be used with "
3937    "specified option"));    "specified option"));
3938   return 1;   return 1;
# Line 3938  int main(int argc, const char ** argv) { Line 3974  int main(int argc, const char ** argv) {
3974   makeDefault = 1;   makeDefault = 1;
3975   defaultKernel = NULL;   defaultKernel = NULL;
3976      }      }
3977        else if (defaultKernel && (defaultIndex >= 0)) {
3978     fprintf(stderr, _("grubby: --set-default and --set-default-index "
3979      "may not be used together\n"));
3980     return 1;
3981        }
3982    
3983      if (grubConfig && !strcmp(grubConfig, "-") && !outputFile) {      if (grubConfig && !strcmp(grubConfig, "-") && !outputFile) {
3984   fprintf(stderr, _("grubby: output file must be specified if stdin "   fprintf(stderr, _("grubby: output file must be specified if stdin "
# Line 3946  int main(int argc, const char ** argv) { Line 3987  int main(int argc, const char ** argv) {
3987      }      }
3988    
3989      if (!removeKernelPath && !newKernelPath && !displayDefault && !defaultKernel      if (!removeKernelPath && !newKernelPath && !displayDefault && !defaultKernel
3990   && !kernelInfo && !bootloaderProbe && !updateKernelPath   && !kernelInfo && !bootloaderProbe && !updateKernelPath
3991          && !removeMBKernel && !displayDefaultIndex && !displayDefaultTitle) {   && !removeMBKernel && !displayDefaultIndex && !displayDefaultTitle
3992     && (defaultIndex == -1)) {
3993   fprintf(stderr, _("grubby: no action specified\n"));   fprintf(stderr, _("grubby: no action specified\n"));
3994   return 1;   return 1;
3995      }      }
# Line 3974  int main(int argc, const char ** argv) { Line 4016  int main(int argc, const char ** argv) {
4016      }      }
4017    
4018      if (bootloaderProbe) {      if (bootloaderProbe) {
4019   int lrc = 0, grc = 0, gr2c = 0, erc = 0;   int lrc = 0, grc = 0, gr2c = 0, extrc = 0, yrc = 0, erc = 0;
4020   struct grubConfig * lconfig, * gconfig;   struct grubConfig * lconfig, * gconfig, * yconfig, * econfig;
4021    
4022   const char *grub2config = grub2FindConfig(&grub2ConfigType);   const char *grub2config = grub2FindConfig(&grub2ConfigType);
4023   if (grub2config) {   if (grub2config) {
# Line 4003  int main(int argc, const char ** argv) { Line 4045  int main(int argc, const char ** argv) {
4045   lrc = checkForLilo(lconfig);   lrc = checkForLilo(lconfig);
4046   }   }
4047    
4048     if (!access(eliloConfigType.defaultConfig, F_OK)) {
4049        econfig = readConfig(eliloConfigType.defaultConfig,
4050     &eliloConfigType);
4051        if (!econfig)
4052     erc = 1;
4053        else
4054     erc = checkForElilo(econfig);
4055     }
4056    
4057   if (!access(extlinuxConfigType.defaultConfig, F_OK)) {   if (!access(extlinuxConfigType.defaultConfig, F_OK)) {
4058      lconfig = readConfig(extlinuxConfigType.defaultConfig, &extlinuxConfigType);      lconfig = readConfig(extlinuxConfigType.defaultConfig, &extlinuxConfigType);
4059      if (!lconfig)      if (!lconfig)
4060   erc = 1;   extrc = 1;
4061      else      else
4062   erc = checkForExtLinux(lconfig);   extrc = checkForExtLinux(lconfig);
4063   }   }
4064    
4065   if (lrc == 1 || grc == 1 || gr2c == 1) return 1;  
4066     if (!access(yabootConfigType.defaultConfig, F_OK)) {
4067        yconfig = readConfig(yabootConfigType.defaultConfig,
4068     &yabootConfigType);
4069        if (!yconfig)
4070     yrc = 1;
4071        else
4072     yrc = checkForYaboot(yconfig);
4073     }
4074    
4075     if (lrc == 1 || grc == 1 || gr2c == 1 || extrc == 1 || yrc == 1 ||
4076     erc == 1)
4077        return 1;
4078    
4079   if (lrc == 2) printf("lilo\n");   if (lrc == 2) printf("lilo\n");
4080   if (gr2c == 2) printf("grub2\n");   if (gr2c == 2) printf("grub2\n");
4081   if (grc == 2) printf("grub\n");   if (grc == 2) printf("grub\n");
4082   if (erc == 2) printf("extlinux\n");   if (extrc == 2) printf("extlinux\n");
4083     if (yrc == 2) printf("yaboot\n");
4084     if (erc == 2) printf("elilo\n");
4085    
4086   return 0;   return 0;
4087      }      }
# Line 4083  int main(int argc, const char ** argv) { Line 4148  int main(int argc, const char ** argv) {
4148      markRemovedImage(config, removeKernelPath, bootPrefix);      markRemovedImage(config, removeKernelPath, bootPrefix);
4149      markRemovedImage(config, removeMBKernel, bootPrefix);      markRemovedImage(config, removeMBKernel, bootPrefix);
4150      setDefaultImage(config, newKernelPath != NULL, defaultKernel, makeDefault,      setDefaultImage(config, newKernelPath != NULL, defaultKernel, makeDefault,
4151      bootPrefix, flags);      bootPrefix, flags, defaultIndex);
4152      setFallbackImage(config, newKernelPath != NULL);      setFallbackImage(config, newKernelPath != NULL);
4153      if (updateImage(config, updateKernelPath, bootPrefix, newKernelArgs,      if (updateImage(config, updateKernelPath, bootPrefix, newKernelArgs,
4154                      removeArgs, newMBKernelArgs, removeMBKernelArgs)) return 1;                      removeArgs, newMBKernelArgs, removeMBKernelArgs)) return 1;

Legend:
Removed from v.1850  
changed lines
  Added in v.1864