s390utils/s390-tools-zipl-Return-numb...

82 lines
2.5 KiB
Diff

From ccc3beeb9920ba2a1087ae828b9c1de1fc5fb135 Mon Sep 17 00:00:00 2001
From: Javier Martinez Canillas <javierm@redhat.com>
Date: Wed, 2 May 2018 12:26:49 +0200
Subject: [PATCH] zipl: Return number of allocated tokens in scan_file()
The function returns 0 on success and a negative number on error but is
useful to know how many tokens were allocated. This will be used by the
BLS parsing code to determine if needs to allocate mor tokens or not to
parse the BLS fragments.
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
---
zipl/src/job.c | 8 ++++----
zipl/src/scan.c | 16 +++++++++-------
2 files changed, 13 insertions(+), 11 deletions(-)
diff --git a/zipl/src/job.c b/zipl/src/job.c
index b06a4824333..9d5f00b6bdc 100644
--- a/zipl/src/job.c
+++ b/zipl/src/job.c
@@ -1732,7 +1732,7 @@ get_job_from_config_file(struct command_line* cmdline, struct job_data* job)
struct scan_token* new_scan;
char* filename;
char* source;
- int rc;
+ int rc, scan_size;
/* Read configuration file */
if (cmdline->config != NULL) {
@@ -1750,10 +1750,10 @@ get_job_from_config_file(struct command_line* cmdline, struct job_data* job)
source = "";
}
printf("Using config file '%s'%s\n", filename, source);
- rc = scan_file(filename, &scan);
- if (rc) {
+ scan_size = scan_file(filename, &scan);
+ if (scan_size <= 0) {
error_text("Config file '%s'", filename);
- return rc;
+ return scan_size;
}
if ((cmdline->menu == NULL) && (cmdline->section == NULL)) {
rc = scan_check_defaultboot(scan);
diff --git a/zipl/src/scan.c b/zipl/src/scan.c
index 7465d6ccb6c..adb288e0626 100644
--- a/zipl/src/scan.c
+++ b/zipl/src/scan.c
@@ -538,9 +538,9 @@ scan_free(struct scan_token* array)
#define INITIAL_ARRAY_LENGTH 40
-/* Scan file FILENAME for tokens. Upon success, return zero and set TOKEN
- * to point to a NULL-terminated array of scan_tokens, i.e. the token id
- * of the last token is 0. Return non-zero otherwise. */
+/* Scan file FILENAME for tokens. Upon success, return the number allocated
+ * tokens and set TOKEN to point to a NULL-terminated array of scan_tokens,
+ * i.e. the token id of the last token is 0. Return non-zero otherwise. */
int
scan_file(const char* filename, struct scan_token** token)
{
@@ -623,11 +623,13 @@ scan_file(const char* filename, struct scan_token** token)
}
}
misc_free_file_buffer(&file);
- if (rc)
+ if (rc) {
scan_free(array);
- else
- *token = array;
- return rc;
+ return rc;
+ }
+
+ *token = array;
+ return size;
}
--
2.17.0