static void parse_bootloader_result(libxl_ctx *ctx, libxl_domain_build_info *info, const char *o) { while (*o != '\0') { if (strncmp("kernel ", o, strlen("kernel ")) == 0) { free(info->kernel.path); info->kernel.path = strdup(o + strlen("kernel ")); libxl__file_reference_map(&info->kernel); unlink(info->kernel.path); } else if (strncmp("ramdisk ", o, strlen("ramdisk ")) == 0) { free(info->u.pv.ramdisk.path); info->u.pv.ramdisk.path = strdup(o + strlen("ramdisk ")); libxl__file_reference_map(&info->u.pv.ramdisk); unlink(info->u.pv.ramdisk.path); } else if (strncmp("args ", o, strlen("args ")) == 0) { free(info->u.pv.cmdline); info->u.pv.cmdline = strdup(o + strlen("args ")); } o = o + strlen(o) + 1; } }
static int parse_bootloader_result(libxl__egc *egc, libxl__bootloader_state *bl) { STATE_AO_GC(bl->ao); char buf[PATH_MAX*2]; FILE *f = 0; int rc = ERROR_FAIL; f = fopen(bl->outputpath, "r"); if (!f) { LOGE(ERROR,"open bootloader output file %s", bl->outputpath); goto out; } for (;;) { /* Read a nul-terminated "line" and put the result in * buf, and its length (not including the nul) in l */ int l = 0, c; while ((c = getc(f)) != EOF && c != '\0') { if (l < sizeof(buf)-1) buf[l] = c; l++; } if (c == EOF) { if (ferror(f)) { LOGE(ERROR,"read bootloader output file %s", bl->outputpath); goto out; } if (!l) break; } if (l >= sizeof(buf)) { LOG(WARN,"bootloader output contained" " overly long item `%.150s...'", buf); continue; } buf[l] = 0; const char *rhs; #define COMMAND(s) ((rhs = bootloader_result_command(gc, buf, s, sizeof(s)-1))) if (COMMAND("kernel")) { bl->kernel->path = libxl__strdup(gc, rhs); libxl__file_reference_map(bl->kernel); unlink(bl->kernel->path); } else if (COMMAND("ramdisk")) { bl->ramdisk->path = libxl__strdup(gc, rhs); libxl__file_reference_map(bl->ramdisk); unlink(bl->ramdisk->path); } else if (COMMAND("args")) { bl->cmdline = libxl__strdup(gc, rhs); } else if (l) { LOG(WARN, "unexpected output from bootloader: `%s'", buf); } } rc = 0; out: if (f) fclose(f); return rc; }