From d71628326d80e623fc9f008fe4ea93edb5592b2e Mon Sep 17 00:00:00 2001 From: Tuan Hoang Date: Fri, 4 Oct 2019 19:37:25 +0200 Subject: [PATCH] zipl: add value of target= as search path for BLS case MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In the BLS files, the 'linux' and 'initrd' fields are relative to the $BOOT directory. If $BOOT is a mount point of boot partition, 'linux' and 'initrd' fields are relative to boot partition. If not, the paths are relative to $BOOT directory of root partition. zipl always starts searching at / regardless of partitions and mount points. This commit extends the semantics of target= field in zipl.conf to make it as a second search path, besides /, for those 2 BLS fields. See issues #69 for more details. Fixes: https://github.com/ibm-s390-tools/s390-tools/issues/69 Closes: https://github.com/ibm-s390-tools/s390-tools/pull/74 Signed-off-by: Tuan Hoang Signed-off-by: Stefan Haberland Signed-off-by: Jan Höppner --- zipl/include/scan.h | 1 + zipl/src/job.c | 6 +++++ zipl/src/scan.c | 58 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+) diff --git a/zipl/include/scan.h b/zipl/include/scan.h index 4dcee0b0..f39e96ef 100644 --- a/zipl/include/scan.h +++ b/zipl/include/scan.h @@ -126,6 +126,7 @@ char* scan_keyword_name(enum scan_keyword_id id); int scan_check_defaultboot(struct scan_token* scan); struct scan_token* scan_build_automenu(struct scan_token* scan); int scan_check(struct scan_token* scan); +int scan_check_bls(struct scan_token *scan); int scan_find_section(struct scan_token* scan, char* name, enum scan_id type, int offset); int scan_check_section_data(char* keyword[], int* line, char* name, diff --git a/zipl/src/job.c b/zipl/src/job.c index ccd9bb0d..7d61c842 100644 --- a/zipl/src/job.c +++ b/zipl/src/job.c @@ -1853,6 +1853,12 @@ get_job_from_config_file(struct command_line* cmdline, struct job_data* job) scan_free(scan); return rc; } + rc = scan_check_bls(scan); + if (rc) { + error_text("BLS parsing '%s'", blsdir); + scan_free(scan); + return rc; + } /* Get job from config file data */ if (cmdline->menu != NULL) rc = get_menu_job(scan, cmdline->menu, job); diff --git a/zipl/src/scan.c b/zipl/src/scan.c index 635d41ef..38fa5454 100644 --- a/zipl/src/scan.c +++ b/zipl/src/scan.c @@ -1564,6 +1564,64 @@ scan_check(struct scan_token* scan) return 0; } +/* + * Check if kernel and initrd image paths provided by BLS files are readable. + * If not, add value of 'scan_keyword_target' into search path and silently + * update scan list. + */ +int +scan_check_bls(struct scan_token *scan) +{ + int i, rc; + char *target_value = NULL; + char *img_value = NULL; + char *buffer = NULL; + /* + * In the BLS case, each BLS section heading inherits a keyword + * assignment target= from zipl.conf, and they are all the same. + * + */ + for (i = 0 ; scan[i].id != scan_id_empty; i++) { + if (scan[i].id == scan_id_keyword_assignment && + scan[i].content.keyword.keyword == scan_keyword_target) { + target_value = scan[i].content.keyword.value; + break; + } + } + if (!target_value) + return -1; + for (i = 0 ; scan[i].id != scan_id_empty; i++) { + if (scan[i].id != scan_id_keyword_assignment) + continue; + if (scan[i].content.keyword.keyword == scan_keyword_image || + scan[i].content.keyword.keyword == scan_keyword_ramdisk) { + + rc = misc_check_readable_file( + scan[i].content.keyword.value); + if (rc) { + misc_asprintf(&img_value, "%s%s", + target_value, + scan[i].content.keyword.value); + rc = misc_check_readable_file(img_value); + if (rc) { + error_text( + "Image file '%s' is not accessible", + scan[i].content.keyword.value); + return rc; + } + buffer = (char *) + misc_malloc(strlen(img_value) + 1); + if (buffer == NULL) + return -1; + memcpy(buffer, img_value, strlen(img_value)); + buffer[strlen(img_value)] = 0; + free(scan[i].content.keyword.value); + scan[i].content.keyword.value = buffer; + } + } + } + return 0; +} static int scan_get_defaultboot_type(char* keyword[], int line[], int section_line,