]> git.ozlabs.org Git - petitboot/blobdiff - discover/paths.c
discover/paths: Cleanup res after getaddrinfo
[petitboot] / discover / paths.c
index 24e978b4e2c1c4b5cfc6092f40adcb6b7cecc8e8..e30f0320c1f19d5e9e6d5b436ae48ee008f794d4 100644 (file)
@@ -3,11 +3,13 @@
 #endif
 
 #include <assert.h>
+#include <netdb.h>
 #include <string.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <sys/types.h>
+#include <sys/socket.h>
 #include <sys/stat.h>
+#include <sys/types.h>
 
 #include <talloc/talloc.h>
 #include <system/system.h>
@@ -41,15 +43,6 @@ struct load_task {
        void                    *async_data;
 };
 
-static inline bool have_busybox(void)
-{
-#ifdef WITH_BUSYBOX
-       return true;
-#else
-       return false;
-#endif
-}
-
 const char *mount_base(void)
 {
        return DEVICE_MOUNT_BASE;
@@ -71,6 +64,12 @@ char *join_paths(void *alloc_ctx, const char *a, const char *b)
 
 #ifndef PETITBOOT_TEST
 
+#ifdef WITH_BUSYBOX
+static inline bool have_busybox(void) { return true; }
+#else
+static inline bool have_busybox(void) { return false; }
+#endif
+
 static char *local_name(void *ctx)
 {
        char *ret, tmp[] = "/tmp/pb-XXXXXX";
@@ -119,6 +118,8 @@ static void load_url_process_exit(struct process *process)
        } else {
                result->status = LOAD_ERROR;
                load_url_result_cleanup_local(result);
+               pb_debug("Download client stdout buffer:\n%s\n",
+                               process->stdout_buf);
        }
 
        if (result->status == LOAD_OK && process->stdout_data)
@@ -185,8 +186,10 @@ static int busybox_progress_cb(void *arg)
                                }
        }
 
-       if (rc != 3)
+       if (rc != 3) {
                percentage = size = 0;
+               suffix = ' ';
+       }
 
        device_handler_status_download(handler, procinfo,
                        percentage, size, suffix);
@@ -550,6 +553,7 @@ struct load_url_result *load_url_async(void *ctx, struct pb_url *url,
 {
        struct load_url_result *result;
        struct load_task *task;
+       struct addrinfo *res;
        int flags = 0;
 
        if (!url)
@@ -582,11 +586,14 @@ struct load_url_result *load_url_async(void *ctx, struct pb_url *url,
 
        /* If the url is remote but network is not yet available queue up this
         * load for later */
-       if (!system_info_network_available() && url->scheme != pb_url_file) {
-               pb_log("load task for %s queued pending network\n", url->full);
-               pending_network_jobs_add(task, flags);
-               task->result->status = LOAD_ASYNC;
-               return task->result;
+       if (url->scheme != pb_url_file) {
+               if (getaddrinfo(url->host, NULL, NULL, &res) != 0) {
+                       pb_log("load task for %s queued pending network\n", url->full);
+                       pending_network_jobs_add(task, flags);
+                       task->result->status = LOAD_ASYNC;
+                       return task->result;
+               }
+               freeaddrinfo(res);
        }
 
        switch (url->scheme) {