~hamo/ubuntu/precise/grub2/grub2.hi_res

« back to all changes in this revision

Viewing changes to normal/handler.c

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson, Colin Watson, Robert Millan, Updated translations
  • Date: 2010-11-22 12:24:56 UTC
  • mfrom: (1.26.4 upstream) (17.3.36 sid)
  • mto: (17.3.43 sid)
  • mto: This revision was merged to the branch mainline in revision 89.
  • Revision ID: james.westby@ubuntu.com-20101122122456-y82z3sfb7k4zfdcc
Tags: 1.99~20101122-1
[ Colin Watson ]
* New Bazaar snapshot.  Too many changes to list in full, but some of the
  more user-visible ones are as follows:
  - GRUB script:
    + Function parameters, "break", "continue", "shift", "setparams",
      "return", and "!".
    + "export" command supports multiple variable names.
    + Multi-line quoted strings support.
    + Wildcard expansion.
  - sendkey support.
  - USB hotunplugging and USB serial support.
  - Rename CD-ROM to cd on BIOS.
  - Add new --boot-directory option to grub-install, grub-reboot, and
    grub-set-default; the old --root-directory option is still accepted
    but was often confusing.
  - Basic btrfs detection/UUID support (but no file reading yet).
  - bash-completion for utilities.
  - If a device is listed in device.map, always assume that it is
    BIOS-visible rather than using extra layers such as LVM or RAID.
  - Add grub-mknetdir script (closes: #550658).
  - Remove deprecated "root" command.
  - Handle RAID devices containing virtio components.
  - GRUB Legacy configuration file support (via grub-menulst2cfg).
  - Keyboard layout support (via grub-mklayout and grub-kbdcomp).
  - Check generated grub.cfg for syntax errors before saving.
  - Pause execution for at most ten seconds if any errors are displayed,
    so that the user has a chance to see them.
  - Support submenus.
  - Write embedding zone using Reed-Solomon, so that it's robust against
    being partially overwritten (closes: #550702, #591416, #593347).
  - GRUB_DISABLE_LINUX_RECOVERY and GRUB_DISABLE_NETBSD_RECOVERY merged
    into a single GRUB_DISABLE_RECOVERY variable.
  - Fix loader memory allocation failure (closes: #551627).
  - Don't call savedefault on recovery entries (closes: #589325).
  - Support triple-indirect blocks on ext2 (closes: #543924).
  - Recognise DDF1 fake RAID (closes: #603354).

[ Robert Millan ]
* Use dpkg architecture wildcards.

[ Updated translations ]
* Slovenian (Vanja Cvelbar).  Closes: #604003
* Dzongkha (dawa pemo via Tenzin Dendup).  Closes: #604102

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* handler.c - support handler loading */
2
 
/*
3
 
 *  GRUB  --  GRand Unified Bootloader
4
 
 *  Copyright (C) 2009  Free Software Foundation, Inc.
5
 
 *
6
 
 *  GRUB is free software: you can redistribute it and/or modify
7
 
 *  it under the terms of the GNU General Public License as published by
8
 
 *  the Free Software Foundation, either version 3 of the License, or
9
 
 *  (at your option) any later version.
10
 
 *
11
 
 *  GRUB is distributed in the hope that it will be useful,
12
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
 *  GNU General Public License for more details.
15
 
 *
16
 
 *  You should have received a copy of the GNU General Public License
17
 
 *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
18
 
 */
19
 
 
20
 
#include <grub/dl.h>
21
 
#include <grub/mm.h>
22
 
#include <grub/err.h>
23
 
#include <grub/env.h>
24
 
#include <grub/misc.h>
25
 
#include <grub/command.h>
26
 
#include <grub/handler.h>
27
 
#include <grub/normal.h>
28
 
 
29
 
struct grub_handler_list
30
 
{
31
 
  struct grub_handler_list *next;
32
 
  char *name;
33
 
  grub_command_t cmd;
34
 
};
35
 
 
36
 
static grub_list_t handler_list;
37
 
 
38
 
static grub_err_t
39
 
grub_handler_cmd (struct grub_command *cmd,
40
 
                  int argc __attribute__ ((unused)),
41
 
                  char **args __attribute__ ((unused)))
42
 
{
43
 
  char *p;
44
 
  grub_handler_class_t class;
45
 
  grub_handler_t handler;
46
 
 
47
 
  p = grub_strchr (cmd->name, '.');
48
 
  if (! p)
49
 
    return grub_error (GRUB_ERR_BAD_ARGUMENT, "invalid command name");
50
 
 
51
 
  if (cmd->data)
52
 
    {
53
 
      if (! grub_dl_get (cmd->data))
54
 
        {
55
 
          grub_dl_t mod;
56
 
 
57
 
          mod = grub_dl_load (cmd->data);
58
 
          if (mod)
59
 
            grub_dl_ref (mod);
60
 
          else
61
 
            return grub_errno;
62
 
        }
63
 
      grub_free (cmd->data);
64
 
      cmd->data = 0;
65
 
    }
66
 
 
67
 
  *p = 0;
68
 
  class = grub_named_list_find (GRUB_AS_NAMED_LIST (grub_handler_class_list),
69
 
                                cmd->name);
70
 
  *p = '.';
71
 
 
72
 
  if (! class)
73
 
    return grub_error (GRUB_ERR_FILE_NOT_FOUND, "class not found");
74
 
 
75
 
 
76
 
  handler = grub_named_list_find (GRUB_AS_NAMED_LIST (class->handler_list),
77
 
                                  p + 1);
78
 
  if (! handler)
79
 
    return grub_error (GRUB_ERR_FILE_NOT_FOUND, "handler not found");
80
 
 
81
 
  grub_handler_set_current (class, handler);
82
 
 
83
 
  return 0;
84
 
}
85
 
 
86
 
static void
87
 
insert_handler (char *name, char *module)
88
 
{
89
 
  struct grub_handler_list *item;
90
 
  char *data;
91
 
 
92
 
  if (grub_command_find (name))
93
 
    return;
94
 
 
95
 
  item = grub_malloc (sizeof (*item));
96
 
  if (! item)
97
 
    return;
98
 
 
99
 
  item->name = grub_strdup (name);
100
 
  if (! item->name)
101
 
    {
102
 
      grub_free (item);
103
 
      return;
104
 
    }
105
 
 
106
 
  if (module)
107
 
    {
108
 
      data = grub_strdup (module);
109
 
      if (! data)
110
 
        {
111
 
          grub_free (item->name);
112
 
          grub_free (item);
113
 
          return;
114
 
        }
115
 
    }
116
 
  else
117
 
    data = 0;
118
 
 
119
 
  item->cmd = grub_register_command (item->name, grub_handler_cmd, 0,
120
 
                                     "Set active handler.");
121
 
  if (! item->cmd)
122
 
    {
123
 
      grub_free (data);
124
 
      grub_free (item->name);
125
 
      grub_free (item);
126
 
      return;
127
 
    }
128
 
 
129
 
  item->cmd->data = data;
130
 
  grub_list_push (&handler_list, GRUB_AS_LIST (item));
131
 
}
132
 
 
133
 
/* Read the file handler.lst for auto-loading.  */
134
 
void
135
 
read_handler_list (void)
136
 
{
137
 
  const char *prefix;
138
 
  static int first_time = 1;
139
 
  const char *class_name;
140
 
 
141
 
  auto int iterate_handler (grub_handler_t handler);
142
 
  int iterate_handler (grub_handler_t handler)
143
 
    {
144
 
      char name[grub_strlen (class_name) + grub_strlen (handler->name) + 2];
145
 
 
146
 
      grub_strcpy (name, class_name);
147
 
      grub_strcat (name, ".");
148
 
      grub_strcat (name, handler->name);
149
 
 
150
 
      insert_handler (name, 0);
151
 
 
152
 
      return 0;
153
 
    }
154
 
 
155
 
  auto int iterate_class (grub_handler_class_t class);
156
 
  int iterate_class (grub_handler_class_t class)
157
 
    {
158
 
      class_name = class->name;
159
 
      grub_list_iterate (GRUB_AS_LIST (class->handler_list),
160
 
                         (grub_list_hook_t) iterate_handler);
161
 
 
162
 
      return 0;
163
 
    }
164
 
 
165
 
  /* Make sure that this function does not get executed twice.  */
166
 
  if (! first_time)
167
 
    return;
168
 
  first_time = 0;
169
 
 
170
 
  prefix = grub_env_get ("prefix");
171
 
  if (prefix)
172
 
    {
173
 
      char *filename;
174
 
 
175
 
      filename = grub_xasprintf ("%s/handler.lst", prefix);
176
 
      if (filename)
177
 
        {
178
 
          grub_file_t file;
179
 
 
180
 
          file = grub_file_open (filename);
181
 
          if (file)
182
 
            {
183
 
              char *buf = NULL;
184
 
              for (;; grub_free (buf))
185
 
                {
186
 
                  char *p;
187
 
 
188
 
                  buf = grub_file_getline (file);
189
 
 
190
 
                  if (! buf)
191
 
                    break;
192
 
 
193
 
                  if (! grub_isgraph (buf[0]))
194
 
                    continue;
195
 
 
196
 
                  p = grub_strchr (buf, ':');
197
 
                  if (! p)
198
 
                    continue;
199
 
 
200
 
                  *p = '\0';
201
 
                  while (*++p == ' ')
202
 
                    ;
203
 
 
204
 
                  insert_handler (buf, p);
205
 
                }
206
 
              grub_file_close (file);
207
 
            }
208
 
          grub_free (filename);
209
 
        }
210
 
    }
211
 
 
212
 
  grub_list_iterate (GRUB_AS_LIST (grub_handler_class_list),
213
 
                     (grub_list_hook_t) iterate_class);
214
 
 
215
 
  /* Ignore errors.  */
216
 
  grub_errno = GRUB_ERR_NONE;
217
 
}
218
 
 
219
 
void
220
 
free_handler_list (void)
221
 
{
222
 
  struct grub_handler_list *item;
223
 
 
224
 
  while ((item = grub_list_pop (&handler_list)) != 0)
225
 
    {
226
 
      grub_free (item->cmd->data);
227
 
      grub_unregister_command (item->cmd);
228
 
      grub_free (item->name);
229
 
      grub_free (item);
230
 
    }
231
 
}