]> git.ozlabs.org Git - petitboot/commitdiff
discover: Don't rely on ctx->conf_url side-effect in user_event_parse_conf_url
authorJeremy Kerr <jk@ozlabs.org>
Fri, 17 Jan 2014 06:50:54 +0000 (14:50 +0800)
committerJeremy Kerr <jk@ozlabs.org>
Fri, 17 Jan 2014 08:13:33 +0000 (16:13 +0800)
Currently, user_event_parse_conf_url sets dc->conf_url if it detects we
have a full URL (rather than a base URL). This is a little too subtle,
so replace it with an explicit output parameter.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
discover/pxe-parser.c
discover/user-event.c
discover/user-event.h

index 2fc261ba9a9089bf3a7841bf10077842829d2acc..e245f1b82b10536f6fb549237dc0627fc18fbb91 100644 (file)
@@ -101,6 +101,7 @@ static int pxe_parse(struct discover_context *dc)
        char **pxe_conf_files, **filename;
        struct pb_url *conf_url, *url;
        struct conf_context *conf;
        char **pxe_conf_files, **filename;
        struct pb_url *conf_url, *url;
        struct conf_context *conf;
+       bool complete_url;
        int len, rc;
        char *buf;
 
        int len, rc;
        char *buf;
 
@@ -121,11 +122,13 @@ static int pxe_parse(struct discover_context *dc)
        parser_info = talloc_zero(conf, struct pxe_parser_info);
        conf->parser_info = parser_info;
 
        parser_info = talloc_zero(conf, struct pxe_parser_info);
        conf->parser_info = parser_info;
 
-       conf_url = user_event_parse_conf_url(dc, dc->event);
+       conf_url = user_event_parse_conf_url(dc, dc->event, &complete_url);
        if (!conf_url)
                goto out_conf;
 
        if (!conf_url)
                goto out_conf;
 
-       if (dc->conf_url) {
+       if (complete_url) {
+               /* we have a complete URL; use this and we're done. */
+               dc->conf_url = conf_url;
                rc = parser_request_url(dc, dc->conf_url, &buf, &len);
                if (rc)
                        goto out_conf;
                rc = parser_request_url(dc, dc->conf_url, &buf, &len);
                if (rc)
                        goto out_conf;
index 69e6f7df1eb442aef7f9fb92216d1161744b272e..11a54df39f2fb6b966cd863f0b9ac431f6a235dc 100644 (file)
@@ -230,7 +230,7 @@ static char *parse_ip_addr(struct discover_context *ctx, const char *ip)
 }
 
 struct pb_url *user_event_parse_conf_url(struct discover_context *ctx,
 }
 
 struct pb_url *user_event_parse_conf_url(struct discover_context *ctx,
-               struct event *event)
+               struct event *event, bool *is_complete)
 {
        const char *conffile, *host, *bootfile;
        char *p, *basedir, *url_str;
 {
        const char *conffile, *host, *bootfile;
        char *p, *basedir, *url_str;
@@ -255,7 +255,7 @@ struct pb_url *user_event_parse_conf_url(struct discover_context *ctx,
                        talloc_free(url_str);
                }
 
                        talloc_free(url_str);
                }
 
-               ctx->conf_url = url;
+               *is_complete = true;
        } else {
                host = parse_host_addr(event);
                if (!host) {
        } else {
                host = parse_host_addr(event);
                if (!host) {
@@ -284,6 +284,7 @@ struct pb_url *user_event_parse_conf_url(struct discover_context *ctx,
 
                talloc_free(url_str);
                talloc_free(basedir);
 
                talloc_free(url_str);
                talloc_free(basedir);
+               *is_complete = false;
        }
 
        return url;
        }
 
        return url;
index 976c25761c810fc63aeaadc6ca7979889330cb59..b892c9a4c44627b4e74257e88ad6a817daac7530 100644 (file)
@@ -19,6 +19,8 @@
 #if !defined(_PB_DISCOVER_USER_EVENT_H)
 #define _PB_DISCOVER_USER_EVENT_H
 
 #if !defined(_PB_DISCOVER_USER_EVENT_H)
 #define _PB_DISCOVER_USER_EVENT_H
 
+#include <stdbool.h>
+
 #include "device-handler.h"
 
 #define PBOOT_USER_EVENT_SOCKET "/tmp/petitboot.ev"
 #include "device-handler.h"
 
 #define PBOOT_USER_EVENT_SOCKET "/tmp/petitboot.ev"
@@ -28,7 +30,7 @@ struct user_event;
 struct waitset;
 
 struct pb_url *user_event_parse_conf_url(struct discover_context *ctx,
 struct waitset;
 
 struct pb_url *user_event_parse_conf_url(struct discover_context *ctx,
-               struct event *event);
+               struct event *event, bool *complete_url);
 char **user_event_parse_conf_filenames(
                struct discover_context *ctx, struct event *event);
 struct user_event *user_event_init(struct waitset *waitset,
 char **user_event_parse_conf_filenames(
                struct discover_context *ctx, struct event *event);
 struct user_event *user_event_init(struct waitset *waitset,