]> git.ozlabs.org Git - petitboot/commitdiff
discover: Add helpers for status reporting
authorJeremy Kerr <jk@ozlabs.org>
Thu, 8 Dec 2016 02:08:15 +0000 (13:08 +1100)
committerSamuel Mendoza-Jonas <sam@mendozajonas.com>
Tue, 20 Dec 2016 04:04:29 +0000 (15:04 +1100)
This change adds a couple of helpers for the status reporting API,
allowing callers to provide just a set of printf-style arguments, rather
than having to build up a struct status.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
discover/device-handler.c
discover/device-handler.h
discover/pxe-parser.c

index 81bdedbbb98b0c1c75ec3cb591d537571f2147b1..b8825ce7ab868a0e095bee5a413a5c60bda1d312 100644 (file)
@@ -416,6 +416,39 @@ void device_handler_status(struct device_handler *handler,
        discover_server_notify_boot_status(handler->server, status);
 }
 
        discover_server_notify_boot_status(handler->server, status);
 }
 
+static void _device_handler_vstatus(struct device_handler *handler,
+               enum status_type type, const char *fmt, va_list ap)
+{
+       struct status status;
+
+       status.type = type;
+       status.message = talloc_vasprintf(handler, fmt, ap);
+
+       device_handler_status(handler, &status);
+
+       talloc_free(status.message);
+}
+
+void device_handler_status_info(struct device_handler *handler,
+               const char *fmt, ...)
+{
+       va_list ap;
+
+       va_start(ap, fmt);
+       _device_handler_vstatus(handler, STATUS_INFO, fmt, ap);
+       va_end(ap);
+}
+
+void device_handler_status_err(struct device_handler *handler,
+               const char *fmt, ...)
+{
+       va_list ap;
+
+       va_start(ap, fmt);
+       _device_handler_vstatus(handler, STATUS_ERROR, fmt, ap);
+       va_end(ap);
+}
+
 static void device_handler_boot_status_cb(void *arg, struct status *status)
 {
        device_handler_status(arg, status);
 static void device_handler_boot_status_cb(void *arg, struct status *status)
 {
        device_handler_status(arg, status);
index 89ca87a823805940c8ae97023a684a8e72f23679..f4022e764d2d57cf60ae282aabbe44155e6e05e6 100644 (file)
@@ -98,6 +98,10 @@ void device_handler_remove(struct device_handler *handler,
 
 void device_handler_status(struct device_handler *handler,
                struct status *status);
 
 void device_handler_status(struct device_handler *handler,
                struct status *status);
+void device_handler_status_info(struct device_handler *handler,
+               const char *fmt, ...);
+void device_handler_status_err(struct device_handler *handler,
+               const char *fmt, ...);
 
 struct discover_context *device_handler_discover_context_create(
                struct device_handler *handler,
 
 struct discover_context *device_handler_discover_context_create(
                struct device_handler *handler,
index a0442152c0c949849b4de7a4d54b944520c0ed9c..5ac6990a876ecb9bc1873648e7601416ae40a7a7 100644 (file)
@@ -241,7 +241,6 @@ static void pxe_conf_parse_cb(struct load_url_result *result, void *data)
 {
        struct conf_context *conf = data;
        struct device_handler *handler;
 {
        struct conf_context *conf = data;
        struct device_handler *handler;
-       struct status status = {0};
        struct pxe_parser_info *info;
        char *buf = NULL;
        int len, rc = 0;
        struct pxe_parser_info *info;
        char *buf = NULL;
        int len, rc = 0;
@@ -279,14 +278,12 @@ static void pxe_conf_parse_cb(struct load_url_result *result, void *data)
        handler = talloc_parent(conf);
        device_handler_discover_context_commit(handler, conf->dc);
 
        handler = talloc_parent(conf);
        device_handler_discover_context_commit(handler, conf->dc);
 
-       status.type = STATUS_INFO;
        /*
         * TRANSLATORS: the format specifier in this string in an IP address,
         * eg. 192.168.1.1
         */
        /*
         * TRANSLATORS: the format specifier in this string in an IP address,
         * eg. 192.168.1.1
         */
-       status.message = talloc_asprintf(conf, _("pxe: parsed config for %s"),
+       device_handler_status_info(handler, _("pxe: parsed config for %s"),
                                        conf->dc->conf_url->host);
                                        conf->dc->conf_url->host);
-       device_handler_status(handler, &status);
 
        talloc_free(buf);
 out_clean:
 
        talloc_free(buf);
 out_clean: