auc: fix several issues
authorDaniel Golle <daniel@makrotopia.org>
Sun, 13 Jun 2021 18:41:57 +0000 (19:41 +0100)
committerDaniel Golle <daniel@makrotopia.org>
Sun, 13 Jun 2021 21:39:14 +0000 (22:39 +0100)
 * don't segfault if server reply is incomplete
 * always request 'generic' image on x86/generic and x86/64
 * make SNAPSHOT branches sticky, eg. stay on 21.02-SNAPSHOT and do
   not 'upgrade' to 21.02.0-rc2.
 * output requested server URL when debugging

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
utils/auc/src/auc.c

index ba3fdfa5f32e825395c6e2192cd7c091795eb298..221b0b6ee5a97746a179cc78bb79feb1e4a727c1 100644 (file)
@@ -532,12 +532,6 @@ static void board_cb(struct ubus_request *req, int type, struct blob_attr *msg)
 
        blobmsg_parse(board_policy, __BOARD_MAX, tb, blob_data(msg), blob_len(msg));
 
-       if (!tb[BOARD_BOARD_NAME]) {
-               fprintf(stderr, "No board name received\n");
-               rc=-ENODATA;
-               return;
-       }
-       board_name = strdup(blobmsg_get_string(tb[BOARD_BOARD_NAME]));
 
        if (!tb[BOARD_RELEASE]) {
                fprintf(stderr, "No release received\n");
@@ -562,6 +556,21 @@ static void board_cb(struct ubus_request *req, int type, struct blob_attr *msg)
        version = strdup(blobmsg_get_string(rel[RELEASE_VERSION]));
        revision = strdup(blobmsg_get_string(rel[RELEASE_REVISION]));
 
+       if (!strcmp(target, "x86/64") || !strcmp(target, "x86/generic")) {
+               /*
+                * ugly work-around ahead:
+                * ignore board name on generic x86 targets, as image name is always 'generic'
+                */
+               board_name = strdup("generic");
+       } else {
+               if (!tb[BOARD_BOARD_NAME]) {
+                       fprintf(stderr, "No board name received\n");
+                       rc=-ENODATA;
+                       return;
+               }
+               board_name = strdup(blobmsg_get_string(tb[BOARD_BOARD_NAME]));
+       }
+
        blobmsg_add_string(buf, "distro", distribution);
        blobmsg_add_string(buf, "target", target);
        blobmsg_add_string(buf, "version", version);
@@ -856,6 +865,11 @@ static int server_request(const char *url, struct blob_buf *inbuf, struct blob_b
        out_bytes = 0;
        out_len = 0;
 
+#ifdef AUC_DEBUG
+       if (debug)
+               fprintf(stderr, "Requesting URL: %s\n", url);
+#endif
+
        if (outbuf) {
                jsb = malloc(sizeof(struct jsonblobber));
                jsb->outbuf = outbuf;
@@ -1191,8 +1205,16 @@ static struct branch *select_branch(char *name, char *select_version)
                                break;
                        }
                } else {
-                       if (!abr || (strcmp(br->version, abr->version) > 0))
-                               abr = br;
+                       /* if we are on a snapshot branch, stay there */
+                       if (strcasestr(version, "snapshot")) {
+                               if (strcasestr(br->version, "snapshot")) {
+                                       abr = br;
+                                       break;
+                               }
+                       } else {
+                               if (!abr || (verrevcmp(br->version, abr->version) > 0))
+                                       abr = br;
+                       }
                }
        }
 
@@ -1393,7 +1415,7 @@ int main(int args, char *argv[]) {
        char url[256];
        char *sanetized_board_name, *image_name, *image_sha256, *tmp;
        struct blob_attr *tbr[__REPLY_MAX];
-       struct blob_attr *tb[__TARGET_MAX];
+       struct blob_attr *tb[__TARGET_MAX] = {}; /* make sure tb is NULL initialized even if blobmsg_parse isn't called */
        struct stat imgstat;
        int check_only = 0;
        int retry_delay = 0;