config.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * GRUB -- GRand Unified Bootloader
  3. * Copyright (C) 1999,2000,2001,2002,2003,2004,2006,2007,2008,2009,2010,2011,2012,2013 Free Software Foundation, Inc.
  4. *
  5. * GRUB is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * GRUB is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include <config.h>
  19. #include <config-util.h>
  20. #include <grub/emu/hostfile.h>
  21. #include <grub/emu/config.h>
  22. #include <grub/util/install.h>
  23. #include <grub/util/misc.h>
  24. void
  25. grub_util_load_config (struct grub_util_config *cfg)
  26. {
  27. const char *cfgfile;
  28. FILE *f = NULL;
  29. const char *v;
  30. cfgfile = grub_util_get_config_filename ();
  31. if (!grub_util_is_regular (cfgfile))
  32. return;
  33. memset (cfg, 0, sizeof (*cfg));
  34. v = getenv ("GRUB_ENABLE_CRYPTODISK");
  35. if (v && v[0] == 'y' && v[1] == '\0')
  36. cfg->is_cryptodisk_enabled = 1;
  37. v = getenv ("GRUB_DISTRIBUTOR");
  38. if (v)
  39. cfg->grub_distributor = xstrdup (v);
  40. f = grub_util_fopen (cfgfile, "r");
  41. if (f)
  42. {
  43. grub_util_parse_config (f, cfg, 0);
  44. fclose (f);
  45. }
  46. else
  47. grub_util_warn (_("cannot open configuration file `%s': %s"),
  48. cfgfile, strerror (errno));
  49. }