23 |
#include <argp.h> |
#include <argp.h> |
24 |
#include <string.h> |
#include <string.h> |
25 |
#include <signal.h> |
#include <signal.h> |
26 |
|
#include <sys/types.h> |
27 |
|
#include <unistd.h> |
28 |
|
|
29 |
#include <grub/mm.h> |
#include <grub/mm.h> |
30 |
#include <grub/setjmp.h> |
#include <grub/setjmp.h> |
97 |
{"device-map", 'm', "FILE", 0, "use FILE as the device map", 0}, |
{"device-map", 'm', "FILE", 0, "use FILE as the device map", 0}, |
98 |
{"directory", 'd', "DIR", 0, "use GRUB files in the directory DIR", 0}, |
{"directory", 'd', "DIR", 0, "use GRUB files in the directory DIR", 0}, |
99 |
{"verbose", 'v', 0 , 0, "print verbose messages", 0}, |
{"verbose", 'v', 0 , 0, "print verbose messages", 0}, |
100 |
|
{"hold", 'H', "SECONDS", OPTION_ARG_OPTIONAL, "wait until a debugger will attach", 0}, |
101 |
{ 0, 0, 0, 0, 0, 0 } |
{ 0, 0, 0, 0, 0, 0 } |
102 |
}; |
}; |
103 |
|
|
106 |
char *root_dev; |
char *root_dev; |
107 |
char *dev_map; |
char *dev_map; |
108 |
char *dir; |
char *dir; |
109 |
|
int hold; |
110 |
}; |
}; |
111 |
|
|
112 |
static error_t |
static error_t |
128 |
case 'v': |
case 'v': |
129 |
verbosity++; |
verbosity++; |
130 |
break; |
break; |
131 |
|
case 'H': |
132 |
|
args->hold = arg ? atoi (arg) : -1; |
133 |
|
break; |
134 |
case ARGP_KEY_END: |
case ARGP_KEY_END: |
135 |
break; |
break; |
136 |
default: |
default: |
150 |
struct arguments args = |
struct arguments args = |
151 |
{ |
{ |
152 |
.dir = DEFAULT_DIRECTORY, |
.dir = DEFAULT_DIRECTORY, |
153 |
.dev_map = DEFAULT_DEVICE_MAP |
.dev_map = DEFAULT_DEVICE_MAP, |
154 |
|
.hold = 0 |
155 |
}; |
}; |
156 |
|
|
157 |
progname = "grub-emu"; |
progname = "grub-emu"; |
158 |
|
|
159 |
argp_parse (&argp, argc, argv, 0, 0, &args); |
argp_parse (&argp, argc, argv, 0, 0, &args); |
160 |
|
|
161 |
|
/* Wait until the ARGS.HOLD variable is cleared by an attached debugger. */ |
162 |
|
if (args.hold && verbosity > 0) |
163 |
|
printf ("Run \"gdb %s %d\", and set ARGS.HOLD to zero.\n", |
164 |
|
progname, (int) getpid ()); |
165 |
|
while (args.hold) |
166 |
|
{ |
167 |
|
if (args.hold > 0) |
168 |
|
args.hold--; |
169 |
|
|
170 |
|
sleep (1); |
171 |
|
} |
172 |
|
|
173 |
/* Make sure that there is a root device. */ |
/* Make sure that there is a root device. */ |
174 |
if (! args.root_dev) |
if (! args.root_dev) |
175 |
{ |
{ |