~darkmuggle-deactivatedaccount/ubuntu/quantal/grub2/fix-872244

« back to all changes in this revision

Viewing changes to util/grub-editenv.c

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson, Colin Watson, Evan Broder, Mario Limonciello
  • Date: 2010-11-24 13:59:55 UTC
  • mfrom: (1.17.6 upstream) (17.6.15 experimental)
  • Revision ID: james.westby@ubuntu.com-20101124135955-r6ii5sepayr7jt53
Tags: 1.99~20101124-1ubuntu1
[ Colin Watson ]
* Resynchronise with Debian experimental.  Remaining changes:
  - Adjust for default Ubuntu boot options ("quiet splash").
  - Default to hiding the menu; holding down Shift at boot will show it.
  - Set a monochromatic theme for Ubuntu.
  - Apply Ubuntu GRUB Legacy changes to legacy update-grub script: title,
    recovery mode, quiet option, tweak how memtest86+ is displayed, and
    use UUIDs where appropriate.
  - Fix backslash-escaping in merge_debconf_into_conf.
  - Remove "GNU/Linux" from default distributor string.
  - Add crashkernel= options if kdump and makedumpfile are available.
  - If other operating systems are installed, then automatically unhide
    the menu.  Otherwise, if GRUB_HIDDEN_TIMEOUT is 0, then use keystatus
    if available to check whether Shift is pressed.  If it is, show the
    menu, otherwise boot immediately.  If keystatus is not available, then
    fall back to a short delay interruptible with Escape.
  - Allow Shift to interrupt 'sleep --interruptible'.
  - Don't display introductory message about line editing unless we're
    actually offering a shell prompt.  Don't clear the screen just before
    booting if we never drew the menu in the first place.
  - Remove some verbose messages printed before reading the configuration
    file.
  - Suppress progress messages as the kernel and initrd load for
    non-recovery kernel menu entries.
  - Change prepare_grub_to_access_device to handle filesystems
    loop-mounted on file images.
  - Ignore devices loop-mounted from files in 10_linux.
  - Show the boot menu if the previous boot failed, that is if it failed
    to get to the end of one of the normal runlevels.
  - Don't generate /boot/grub/device.map during grub-install or
    grub-mkconfig by default.
  - Adjust upgrade version checks for Ubuntu.
  - Don't display "GRUB loading" unless Shift is held down.
  - Adjust versions of grub-doc and grub-legacy-doc conflicts to tolerate
    our backport of the grub-doc split.
  - Fix LVM/RAID probing in the absence of /boot/grub/device.map.
  - Look for .mo files in /usr/share/locale-langpack as well, in
    preference.
  - Make sure GRUB_TIMEOUT isn't quoted unnecessarily.
  - Probe all devices in 'grub-probe --target=drive' if
    /boot/grub/device.map is missing.
  - Build-depend on qemu-kvm rather than qemu-system for grub-pc tests.
  - Use qemu rather than qemu-system-i386.
  - Program vesafb on BIOS systems rather than efifb.
  - Add a grub-rescue-efi-amd64 package containing a rescue CD-ROM image
    for EFI-AMD64.
  - On Wubi, don't ask for an install device, but just update wubildr
    using the diverted grub-install.
  - When embedding the core image in a post-MBR gap, check for and avoid
    sectors matching any of a list of known signatures.
  - Disable video_bochs and video_cirrus on PC BIOS systems, as probing
    PCI space seems to break on some systems.
* Downgrade "ACPI shutdown failed" error to a debug message, since it can
  cause spurious test failures.

[ Evan Broder ]
* Enable lua from grub-extras.
* Incorporate the bitop library into lua.
* Add enum_pci function to grub module in lua.
* Switch back to gfxpayload=keep by default, unless the video hardware
  is known to not support it.

[ Mario Limonciello ]
* Built part_msdos and vfat into bootx64.efi (LP: #677758)

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
#include <config.h>
21
21
#include <grub/types.h>
 
22
#include <grub/emu/misc.h>
22
23
#include <grub/util/misc.h>
23
24
#include <grub/lib/envblk.h>
24
25
#include <grub/i18n.h>
27
28
#include <unistd.h>
28
29
#include <string.h>
29
30
#include <stdlib.h>
30
 
#include <getopt.h>
 
31
#include <argp.h>
31
32
 
32
33
#include "progname.h"
33
34
 
34
35
#define DEFAULT_ENVBLK_SIZE     1024
35
 
 
36
 
void
37
 
grub_refresh (void)
 
36
#define DEFAULT_ENVBLK_PATH DEFAULT_DIRECTORY "/" GRUB_ENVBLK_DEFCFG
 
37
 
 
38
static struct argp_option options[] = {
 
39
  {0,        0, 0, OPTION_DOC, N_("Commands:"), 1},
 
40
  {"create", 0, 0, OPTION_DOC|OPTION_NO_USAGE,
 
41
   N_("Create a blank environment block file."), 0},
 
42
  {"list",   0, 0, OPTION_DOC|OPTION_NO_USAGE,
 
43
   N_("List the current variables."), 0},
 
44
  {"set [name=value ...]", 0, 0, OPTION_DOC|OPTION_NO_USAGE,
 
45
   N_("Set variables."), 0},
 
46
  {"unset [name ....]",    0, 0, OPTION_DOC|OPTION_NO_USAGE,
 
47
   N_("Delete variables."), 0},
 
48
 
 
49
  {0,         0, 0, OPTION_DOC, N_("Options:"), -1},
 
50
  {"verbose", 'v', 0, 0, N_("Print verbose messages."), 0},
 
51
 
 
52
  { 0, 0, 0, 0, 0, 0 }
 
53
};
 
54
 
 
55
/* Print the version information.  */
 
56
static void
 
57
print_version (FILE *stream, struct argp_state *state)
38
58
{
39
 
  fflush (stdout);
 
59
  fprintf (stream, "%s (%s) %s\n", program_name, PACKAGE_NAME, PACKAGE_VERSION);
40
60
}
41
 
 
42
 
int
43
 
grub_getkey (void)
 
61
void (*argp_program_version_hook) (FILE *, struct argp_state *) = print_version;
 
62
 
 
63
/* Set the bug report address */
 
64
const char *argp_program_bug_address = "<"PACKAGE_BUGREPORT">";
 
65
 
 
66
error_t argp_parser (int key, char *arg, struct argp_state *state)
44
67
{
 
68
  switch (key)
 
69
    {
 
70
      case 'v':
 
71
        verbosity++;
 
72
        break;
 
73
 
 
74
      case ARGP_KEY_NO_ARGS:
 
75
        fprintf (stderr, "%s",
 
76
                 _("You need to specify at least one command.\n"));
 
77
        argp_usage (state);
 
78
        break;
 
79
 
 
80
      default:
 
81
        return ARGP_ERR_UNKNOWN;
 
82
    }
 
83
 
45
84
  return 0;
46
85
}
47
86
 
48
 
void 
49
 
grub_xputs_real (const char *str)
50
 
{
51
 
  fputs (str, stdout);
52
 
}
53
 
 
54
 
void (*grub_xputs) (const char *str) = grub_xputs_real;
55
 
 
56
 
char *
57
 
grub_env_get (const char *name __attribute__ ((unused)))
58
 
{
59
 
  return NULL;
60
 
}
61
 
 
62
 
static struct option options[] = {
63
 
  {"help", no_argument, 0, 'h'},
64
 
  {"version", no_argument, 0, 'V'},
65
 
  {"verbose", no_argument, 0, 'v'},
66
 
  {0, 0, 0, 0}
 
87
static char *
 
88
help_filter (int key, const char *text, void *input __attribute__ ((unused)))
 
89
{
 
90
  switch (key)
 
91
    {
 
92
      case ARGP_KEY_HELP_POST_DOC:
 
93
        return xasprintf(text, DEFAULT_ENVBLK_PATH);
 
94
 
 
95
      default:
 
96
        return (char *) text;
 
97
    }
 
98
}
 
99
 
 
100
struct argp argp = {
 
101
  options, argp_parser, N_("FILENAME COMMAND"),
 
102
  "\n"N_("\
 
103
Tool to edit environment block.")
 
104
"\v"N_("\
 
105
If FILENAME is '-', the default value %s is used."),
 
106
  NULL, help_filter, NULL
67
107
};
68
108
 
69
109
static void
70
 
usage (int status)
71
 
{
72
 
  if (status)
73
 
    fprintf (stderr, "Try `%s --help' for more information.\n", program_name);
74
 
  else
75
 
    printf ("\
76
 
Usage: %s [OPTIONS] [FILENAME] COMMAND\n\
77
 
\n\
78
 
Tool to edit environment block.\n\
79
 
\nCommands:\n\
80
 
  create                    create a blank environment block file\n\
81
 
  list                      list the current variables\n\
82
 
  set [name=value ...]      set variables\n\
83
 
  unset [name ....]         delete variables\n\
84
 
\nOptions:\n\
85
 
  -h, --help                display this message and exit\n\
86
 
  -V, --version             print version information and exit\n\
87
 
  -v, --verbose             print verbose messages\n\
88
 
\n\
89
 
If not given explicitly, FILENAME defaults to %s.\n\
90
 
\n\
91
 
Report bugs to <%s>.\n",
92
 
program_name, DEFAULT_DIRECTORY "/" GRUB_ENVBLK_DEFCFG, PACKAGE_BUGREPORT);
93
 
 
94
 
  exit (status);
95
 
}
96
 
 
97
 
static void
98
110
create_envblk_file (const char *name)
99
111
{
100
112
  FILE *fp;
252
264
{
253
265
  char *filename;
254
266
  char *command;
 
267
  int index, arg_count;
255
268
 
256
269
  set_program_name (argv[0]);
257
270
 
258
271
  grub_util_init_nls ();
259
272
 
260
 
  /* Check for options.  */
261
 
  while (1)
262
 
    {
263
 
      int c = getopt_long (argc, argv, "hVv", options, 0);
264
 
 
265
 
      if (c == -1)
266
 
        break;
267
 
      else
268
 
        switch (c)
269
 
          {
270
 
          case 'h':
271
 
            usage (0);
272
 
            break;
273
 
 
274
 
          case 'V':
275
 
            printf ("%s (%s) %s\n", program_name, PACKAGE_NAME, PACKAGE_VERSION);
276
 
            return 0;
277
 
 
278
 
          case 'v':
279
 
            verbosity++;
280
 
            break;
281
 
 
282
 
          default:
283
 
            usage (1);
284
 
            break;
285
 
          }
286
 
    }
287
 
 
288
 
  /* Obtain the filename.  */
289
 
  if (optind >= argc)
290
 
    {
291
 
      fprintf (stderr, "no filename specified\n");
292
 
      usage (1);
293
 
    }
294
 
 
295
 
  if (optind + 1 >= argc)
296
 
    {
297
 
      filename = DEFAULT_DIRECTORY "/" GRUB_ENVBLK_DEFCFG;
298
 
      command = argv[optind];
 
273
  /* Parse our arguments */
 
274
  if (argp_parse (&argp, argc, argv, 0, &index, 0) != 0)
 
275
    {
 
276
      fprintf (stderr, "%s", _("Error in parsing command line arguments\n"));
 
277
      exit(1);
 
278
    }
 
279
 
 
280
  arg_count = argc - index;
 
281
 
 
282
  if (arg_count == 1)
 
283
    {
 
284
      filename = DEFAULT_ENVBLK_PATH;
 
285
      command  = argv[index++];
299
286
    }
300
287
  else
301
288
    {
302
 
      filename = argv[optind];
303
 
      command = argv[optind + 1];
 
289
      filename = argv[index++];
 
290
      if (strcmp (filename, "-") == 0)
 
291
        filename = DEFAULT_ENVBLK_PATH;
 
292
      command  = argv[index++];
304
293
    }
305
294
 
306
295
  if (strcmp (command, "create") == 0)
308
297
  else if (strcmp (command, "list") == 0)
309
298
    list_variables (filename);
310
299
  else if (strcmp (command, "set") == 0)
311
 
    set_variables (filename, argc - optind - 2, argv + optind + 2);
 
300
    set_variables (filename, argc - index, argv + index);
312
301
  else if (strcmp (command, "unset") == 0)
313
 
    unset_variables (filename, argc - optind - 2, argv + optind + 2);
 
302
    unset_variables (filename, argc - index, argv + index);
314
303
  else
315
304
    {
316
 
      fprintf (stderr, "unknown command %s\n", command);
317
 
      usage (1);
 
305
      char *program = xstrdup(program_name);
 
306
      fprintf (stderr, _("Unknown command `%s'.\n"), command);
 
307
      argp_help (&argp, stderr, ARGP_HELP_STD_USAGE, program);
 
308
      free(program);
 
309
      exit(1);
318
310
    }
319
311
 
320
312
  return 0;