1 12 files changed, 96 insertions(+), 40 deletions(-)
3 diff --git a/discover/kboot-parser.c b/discover/kboot-parser.c
4 index 23d48a4..7c7cb5d 100644
5 --- a/discover/kboot-parser.c
6 +++ b/discover/kboot-parser.c
7 @@ -133,7 +133,7 @@ static int kboot_parse(struct discover_context *dc)
8 conf = talloc_zero(dc, struct conf_context);
15 conf->global_options = kboot_global_options,
16 diff --git a/discover/parser.c b/discover/parser.c
17 index 2b4ddd2..8f2735c 100644
18 --- a/discover/parser.c
19 +++ b/discover/parser.c
20 @@ -13,16 +13,16 @@ extern struct parser __start_parsers[], __stop_parsers[];
21 void iterate_parsers(struct discover_context *ctx)
23 struct parser *parser;
24 + unsigned int count = 0;
26 pb_log("trying parsers for %s\n", ctx->device_path);
28 for (parser = __start_parsers; parser < __stop_parsers; parser++) {
29 pb_log("\ttrying parser '%s'\n", parser->name);
30 - /* just use a dummy device path for now */
31 - if (parser->parse(ctx))
33 + count += parser->parse(ctx);
35 - pb_log("\tno boot_options found\n");
37 + pb_log("\tno boot_options found\n");
40 static int compare_parsers(const void *a, const void *b)
41 diff --git a/discover/yaboot-parser.c b/discover/yaboot-parser.c
42 index 1000505..6101cd8 100644
43 --- a/discover/yaboot-parser.c
44 +++ b/discover/yaboot-parser.c
45 @@ -295,7 +295,7 @@ static int yaboot_parse(struct discover_context *dc)
46 conf = talloc_zero(dc, struct conf_context);
53 conf->global_options = yaboot_global_options,
54 diff --git a/lib/log/log.h b/lib/log/log.h
55 index 2a5d375..6f44bea 100644
62 -void pb_log(const char *fmt, ...);
63 +void __attribute__ ((format (printf, 1, 2))) pb_log(const char *fmt, ...);
64 void pb_log_set_stream(FILE *stream);
65 FILE * pb_log_get_stream(void);
66 void pb_log_always_flush(int state);
67 diff --git a/lib/system/system.c b/lib/system/system.c
68 index 65bd6bf..7371445 100644
69 --- a/lib/system/system.c
70 +++ b/lib/system/system.c
71 @@ -20,6 +20,7 @@ const struct pb_system_apps pb_system_apps = {
73 .kexec = "/sbin/kexec",
74 .mount = "/bin/mount",
75 + .shutdown = "/sbin/shutdown",
76 .sftp = "/usr/bin/sftp",
77 .tftp = "/usr/bin/tftp",
78 .umount = "/bin/umount",
79 diff --git a/lib/system/system.h b/lib/system/system.h
80 index 47c7c02..1918309 100644
81 --- a/lib/system/system.h
82 +++ b/lib/system/system.h
83 @@ -5,6 +5,7 @@ struct pb_system_apps {
87 + const char *shutdown;
91 diff --git a/ui/common/discover-client.c b/ui/common/discover-client.c
92 index e8ce4dd..5b42b6c 100644
93 --- a/ui/common/discover-client.c
94 +++ b/ui/common/discover-client.c
95 @@ -46,7 +46,7 @@ struct discover_client* discover_client_init(
96 client->ops.cb_arg = cb_arg;
98 client->fd = socket(AF_UNIX, SOCK_STREAM, 0);
99 - if (!client->fd < 0) {
100 + if (client->fd < 0) {
101 pb_log("%s: socket: %s\n", __func__, strerror(errno));
104 diff --git a/ui/common/loader.c b/ui/common/loader.c
105 index 0fe62a0..5c69533 100644
106 --- a/ui/common/loader.c
107 +++ b/ui/common/loader.c
108 @@ -263,16 +263,22 @@ fail:
110 * pb_load_file - Loads a remote file and returns the local file path.
111 * @ctx: The talloc context to associate with the returned string.
112 + * @remote: The remote file URL.
113 + * @tempfile: An optional variable pointer to be set when a temporary local
116 * Returns the local file path in a talloc'ed character string on success,
120 -char *pb_load_file(void *ctx, const char *remote)
121 +char *pb_load_file(void *ctx, const char *remote, unsigned int *tempfile)
124 struct pb_url *url = pb_url_parse(NULL, remote);
132 @@ -280,19 +286,28 @@ char *pb_load_file(void *ctx, const char *remote)
135 local = pb_load_wget(ctx, url, 0);
136 + if (tempfile && local)
140 - local = pb_load_wget(ctx, url,
141 - wget_no_check_certificate);
142 + local = pb_load_wget(ctx, url, wget_no_check_certificate);
143 + if (tempfile && local)
147 local = pb_load_nfs(ctx, url);
148 + if (tempfile && local)
152 local = pb_load_sftp(ctx, url);
153 + if (tempfile && local)
157 local = pb_load_tftp(ctx, url);
158 + if (tempfile && local)
162 local = talloc_strdup(ctx, url->full);
163 diff --git a/ui/common/loader.h b/ui/common/loader.h
164 index b06bb43..42d4d4b 100644
165 --- a/ui/common/loader.h
166 +++ b/ui/common/loader.h
168 #if !defined(_PB_FILE_LOADER_H)
169 #define _PB_FILE_LOADER_H
171 -char *pb_load_file(void *ctx, const char *remote);
172 +char *pb_load_file(void *ctx, const char *remote, unsigned int *tempfile);
175 diff --git a/ui/common/ps3.c b/ui/common/ps3.c
176 index cb1c8d1..c62a10d 100644
177 --- a/ui/common/ps3.c
178 +++ b/ui/common/ps3.c
179 @@ -87,7 +87,7 @@ static int ps3_flash_open(struct ps3_flash_ctx *fc, const char *mode)
180 result = os_area_fixed_read(&fc->header, &fc->params, fc->dev);
183 - pb_log("%s: os_area_fixed_read failed: %s\n", __func__);
184 + pb_log("%s: os_area_fixed_read failed\n", __func__);
188 @@ -114,7 +114,7 @@ int ps3_flash_get_values(struct ps3_flash_values *values)
189 result = ps3_flash_open(&fc, "r");
195 result = os_area_db_read(&fc.db, &fc.header, fc.dev);
197 @@ -123,7 +123,7 @@ int ps3_flash_get_values(struct ps3_flash_values *values)
199 pb_log("%s: os_area_db_read failed: %s\n", __func__,
205 sum = result = os_area_db_get(&fc.db, &id_default_item, &tmp);
206 @@ -141,14 +141,13 @@ int ps3_flash_get_values(struct ps3_flash_values *values)
208 values->video_mode = (uint16_t)tmp;
211 pb_log("%s: default_item: %x\n", __func__,
212 (unsigned int)values->default_item);
213 pb_log("%s: timeout: %u\n", __func__,
214 (unsigned int)values->timeout);
215 pb_log("%s: video_mode: %u\n", __func__,
216 (unsigned int)values->video_mode);
219 return (result || sum) ? -1 : 0;
222 diff --git a/ui/common/ui-system.c b/ui/common/ui-system.c
223 index bd6dd31..0140f0e 100644
224 --- a/ui/common/ui-system.c
225 +++ b/ui/common/ui-system.c
227 #include "ui-system.h"
230 - * run_kexec_local - Final kexec helper.
231 + * kexec_load - kexec load helper.
232 * @l_image: The local image file for kexec to execute.
233 * @l_initrd: Optional local initrd file for kexec --initrd, can be NULL.
234 * @args: Optional command line args for kexec --append, can be NULL.
237 -static int run_kexec_local(const char *l_image, const char *l_initrd,
238 +static int kexec_load(const char *l_image, const char *l_initrd,
242 @@ -49,34 +49,64 @@ static int run_kexec_local(const char *l_image, const char *l_initrd,
246 - *p++ = pb_system_apps.kexec; /* 1 */
247 + *p++ = pb_system_apps.kexec; /* 1 */
248 + *p++ = "-l"; /* 2 */
251 s_initrd = talloc_asprintf(NULL, "--initrd=%s", l_initrd);
253 - *p++ = s_initrd; /* 2 */
254 + *p++ = s_initrd; /* 3 */
258 s_args = talloc_asprintf(NULL, "--append=%s", args);
260 - *p++ = s_args; /* 3 */
261 + *p++ = s_args; /* 4 */
264 - /* First try by telling kexec to run shutdown */
265 + *p++ = l_image; /* 5 */
266 + *p++ = NULL; /* 6 */
268 - *(p + 0) = l_image;
270 + result = pb_run_cmd(argv);
273 + pb_log("%s: failed: (%d)\n", __func__, result);
275 + talloc_free(s_initrd);
276 + talloc_free(s_args);
282 + * kexec_reboot - Helper to boot the new kernel.
284 + * Must only be called after a successful call to kexec_load().
287 +static int kexec_reboot(void)
290 + const char *argv[4];
293 + /* First try running shutdown. Init scripts should run 'exec -e' */
296 + *p++ = pb_system_apps.shutdown; /* 1 */
297 + *p++ = "-r"; /* 2 */
298 + *p++ = "now"; /* 3 */
299 + *p++ = NULL; /* 4 */
301 result = pb_run_cmd(argv);
303 - /* kexec will return zero on success */
304 - /* On error, force a kexec with the -f option */
305 + /* On error, force a kexec with the -e option */
308 - *(p + 0) = "-f"; /* 4 */
309 - *(p + 1) = l_image; /* 5 */
310 - *(p + 2) = NULL; /* 6 */
312 + *p++ = pb_system_apps.kexec; /* 1 */
313 + *p++ = "-e"; /* 2 */
314 + *p++ = NULL; /* 3 */
316 result = pb_run_cmd(argv);
318 @@ -84,9 +114,6 @@ static int run_kexec_local(const char *l_image, const char *l_initrd,
320 pb_log("%s: failed: (%d)\n", __func__, result);
322 - talloc_free(s_initrd);
323 - talloc_free(s_args);
328 @@ -99,31 +126,44 @@ int pb_run_kexec(const struct pb_kexec_data *kd)
330 char *l_image = NULL;
331 char *l_initrd = NULL;
332 + unsigned int clean_image = 0;
333 + unsigned int clean_initrd = 0;
335 pb_log("%s: image: '%s'\n", __func__, kd->image);
336 pb_log("%s: initrd: '%s'\n", __func__, kd->initrd);
337 pb_log("%s: args: '%s'\n", __func__, kd->args);
342 - l_image = pb_load_file(NULL, kd->image);
343 + l_image = pb_load_file(NULL, kd->image, &clean_image);
350 - l_initrd = pb_load_file(NULL, kd->initrd);
351 + l_initrd = pb_load_file(NULL, kd->initrd, &clean_initrd);
357 if (!l_image && !l_initrd)
361 + result = kexec_load(l_image, l_initrd, kd->args);
363 - result = run_kexec_local(l_image, l_initrd, kd->args);
370 talloc_free(l_image);
371 talloc_free(l_initrd);
374 + result = kexec_reboot();
379 diff --git a/ui/common/url.c b/ui/common/url.c
380 index 0de0f58..544eee2 100644
381 --- a/ui/common/url.c
382 +++ b/ui/common/url.c
383 @@ -140,7 +140,7 @@ struct pb_url *pb_url_parse(void *ctx, const char *url_str)
384 path = strchr(p, '/');
387 - pb_log("%s: parse path failed '%s'\n", p);
388 + pb_log("%s: parse path failed '%s'\n", __func__ , p);