|
|
38852f |
---
|
|
|
38852f |
libmultipath/parser.c | 103 +++-----------------------------------------------
|
|
|
38852f |
libmultipath/parser.h | 6 --
|
|
|
38852f |
2 files changed, 8 insertions(+), 101 deletions(-)
|
|
|
38852f |
|
|
|
38852f |
Index: multipath-tools-130222/libmultipath/parser.c
|
|
|
38852f |
===================================================================
|
|
|
38852f |
--- multipath-tools-130222.orig/libmultipath/parser.c
|
|
|
38852f |
+++ multipath-tools-130222/libmultipath/parser.c
|
|
|
38852f |
@@ -280,8 +280,8 @@ out:
|
|
|
38852f |
return NULL;
|
|
|
38852f |
}
|
|
|
38852f |
|
|
|
38852f |
-int
|
|
|
38852f |
-read_line(char *buf, int size)
|
|
|
38852f |
+static int
|
|
|
38852f |
+read_line(FILE *stream, char *buf, int size)
|
|
|
38852f |
{
|
|
|
38852f |
int ch;
|
|
|
38852f |
int count = 0;
|
|
|
38852f |
@@ -297,95 +297,6 @@ read_line(char *buf, int size)
|
|
|
38852f |
return (ch == EOF) ? 0 : 1;
|
|
|
38852f |
}
|
|
|
38852f |
|
|
|
38852f |
-vector
|
|
|
38852f |
-read_value_block(void)
|
|
|
38852f |
-{
|
|
|
38852f |
- char *buf;
|
|
|
38852f |
- int i;
|
|
|
38852f |
- char *str = NULL;
|
|
|
38852f |
- char *dup;
|
|
|
38852f |
- vector vec = NULL;
|
|
|
38852f |
- vector elements = vector_alloc();
|
|
|
38852f |
-
|
|
|
38852f |
- if (!elements)
|
|
|
38852f |
- return NULL;
|
|
|
38852f |
-
|
|
|
38852f |
- buf = (char *) MALLOC(MAXBUF);
|
|
|
38852f |
-
|
|
|
38852f |
- if (!buf) {
|
|
|
38852f |
- vector_free(elements);
|
|
|
38852f |
- return NULL;
|
|
|
38852f |
- }
|
|
|
38852f |
-
|
|
|
38852f |
- while (read_line(buf, MAXBUF)) {
|
|
|
38852f |
- vec = alloc_strvec(buf);
|
|
|
38852f |
- if (vec) {
|
|
|
38852f |
- str = VECTOR_SLOT(vec, 0);
|
|
|
38852f |
- if (!strcmp(str, EOB)) {
|
|
|
38852f |
- free_strvec(vec);
|
|
|
38852f |
- break;
|
|
|
38852f |
- }
|
|
|
38852f |
-
|
|
|
38852f |
- for (i = 0; i < VECTOR_SIZE(vec); i++) {
|
|
|
38852f |
- str = VECTOR_SLOT(vec, i);
|
|
|
38852f |
- dup = (char *) MALLOC(strlen(str) + 1);
|
|
|
38852f |
- if (!dup)
|
|
|
38852f |
- goto out;
|
|
|
38852f |
- memcpy(dup, str, strlen(str));
|
|
|
38852f |
-
|
|
|
38852f |
- if (!vector_alloc_slot(elements)) {
|
|
|
38852f |
- free_strvec(vec);
|
|
|
38852f |
- goto out1;
|
|
|
38852f |
- }
|
|
|
38852f |
-
|
|
|
38852f |
- vector_set_slot(elements, dup);
|
|
|
38852f |
- }
|
|
|
38852f |
- free_strvec(vec);
|
|
|
38852f |
- }
|
|
|
38852f |
- memset(buf, 0, MAXBUF);
|
|
|
38852f |
- }
|
|
|
38852f |
- FREE(buf);
|
|
|
38852f |
- return elements;
|
|
|
38852f |
-out1:
|
|
|
38852f |
- FREE(dup);
|
|
|
38852f |
-out:
|
|
|
38852f |
- FREE(buf);
|
|
|
38852f |
- vector_free(elements);
|
|
|
38852f |
- return NULL;
|
|
|
38852f |
-}
|
|
|
38852f |
-
|
|
|
38852f |
-int
|
|
|
38852f |
-alloc_value_block(vector strvec, void (*alloc_func) (vector))
|
|
|
38852f |
-{
|
|
|
38852f |
- char *buf;
|
|
|
38852f |
- char *str = NULL;
|
|
|
38852f |
- vector vec = NULL;
|
|
|
38852f |
-
|
|
|
38852f |
- buf = (char *) MALLOC(MAXBUF);
|
|
|
38852f |
-
|
|
|
38852f |
- if (!buf)
|
|
|
38852f |
- return 1;
|
|
|
38852f |
-
|
|
|
38852f |
- while (read_line(buf, MAXBUF)) {
|
|
|
38852f |
- vec = alloc_strvec(buf);
|
|
|
38852f |
- if (vec) {
|
|
|
38852f |
- str = VECTOR_SLOT(vec, 0);
|
|
|
38852f |
- if (!strcmp(str, EOB)) {
|
|
|
38852f |
- free_strvec(vec);
|
|
|
38852f |
- break;
|
|
|
38852f |
- }
|
|
|
38852f |
-
|
|
|
38852f |
- if (VECTOR_SIZE(vec))
|
|
|
38852f |
- (*alloc_func) (vec);
|
|
|
38852f |
-
|
|
|
38852f |
- free_strvec(vec);
|
|
|
38852f |
- }
|
|
|
38852f |
- memset(buf, 0, MAXBUF);
|
|
|
38852f |
- }
|
|
|
38852f |
- FREE(buf);
|
|
|
38852f |
- return 0;
|
|
|
38852f |
-}
|
|
|
38852f |
-
|
|
|
38852f |
void *
|
|
|
38852f |
set_value(vector strvec)
|
|
|
38852f |
{
|
|
|
38852f |
@@ -561,7 +472,7 @@ validate_config_strvec(vector strvec, ch
|
|
|
38852f |
}
|
|
|
38852f |
|
|
|
38852f |
static int
|
|
|
38852f |
-process_stream(vector keywords, char *file)
|
|
|
38852f |
+process_stream(FILE *stream, vector keywords, char *file)
|
|
|
38852f |
{
|
|
|
38852f |
int i;
|
|
|
38852f |
int r = 0;
|
|
|
38852f |
@@ -582,7 +493,7 @@ process_stream(vector keywords, char *fi
|
|
|
38852f |
return 1;
|
|
|
38852f |
}
|
|
|
38852f |
|
|
|
38852f |
- while (read_line(buf, MAXBUF)) {
|
|
|
38852f |
+ while (read_line(stream, buf, MAXBUF)) {
|
|
|
38852f |
line_nr++;
|
|
|
38852f |
strvec = alloc_strvec(buf);
|
|
|
38852f |
memset(buf,0, MAXBUF);
|
|
|
38852f |
@@ -621,7 +532,8 @@ process_stream(vector keywords, char *fi
|
|
|
38852f |
|
|
|
38852f |
if (keyword->sub) {
|
|
|
38852f |
kw_level++;
|
|
|
38852f |
- r += process_stream(keyword->sub, file);
|
|
|
38852f |
+ r += process_stream(stream,
|
|
|
38852f |
+ keyword->sub, file);
|
|
|
38852f |
kw_level--;
|
|
|
38852f |
}
|
|
|
38852f |
break;
|
|
|
38852f |
@@ -656,6 +568,7 @@ int
|
|
|
38852f |
process_file(char *file)
|
|
|
38852f |
{
|
|
|
38852f |
int r;
|
|
|
38852f |
+ FILE *stream;
|
|
|
38852f |
|
|
|
38852f |
if (!keywords) {
|
|
|
38852f |
condlog(0, "No keywords alocated");
|
|
|
38852f |
@@ -670,7 +583,7 @@ process_file(char *file)
|
|
|
38852f |
|
|
|
38852f |
/* Stream handling */
|
|
|
38852f |
line_nr = 0;
|
|
|
38852f |
- r = process_stream(keywords, file);
|
|
|
38852f |
+ r = process_stream(stream, keywords, file);
|
|
|
38852f |
fclose(stream);
|
|
|
38852f |
//free_keywords(keywords);
|
|
|
38852f |
|
|
|
38852f |
Index: multipath-tools-130222/libmultipath/parser.h
|
|
|
38852f |
===================================================================
|
|
|
38852f |
--- multipath-tools-130222.orig/libmultipath/parser.h
|
|
|
38852f |
+++ multipath-tools-130222/libmultipath/parser.h
|
|
|
38852f |
@@ -47,9 +47,6 @@ struct keyword {
|
|
|
38852f |
int unique;
|
|
|
38852f |
};
|
|
|
38852f |
|
|
|
38852f |
-/* global var exported */
|
|
|
38852f |
-FILE *stream;
|
|
|
38852f |
-
|
|
|
38852f |
/* Reloading helpers */
|
|
|
38852f |
#define SET_RELOAD (reload = 1)
|
|
|
38852f |
#define UNSET_RELOAD (reload = 0)
|
|
|
38852f |
@@ -72,9 +69,6 @@ extern int _install_keyword(char *string
|
|
|
38852f |
extern void dump_keywords(vector keydump, int level);
|
|
|
38852f |
extern void free_keywords(vector keywords);
|
|
|
38852f |
extern vector alloc_strvec(char *string);
|
|
|
38852f |
-extern int read_line(char *buf, int size);
|
|
|
38852f |
-extern vector read_value_block(void);
|
|
|
38852f |
-extern int alloc_value_block(vector strvec, void (*alloc_func) (vector));
|
|
|
38852f |
extern void *set_value(vector strvec);
|
|
|
38852f |
extern int alloc_keywords(void);
|
|
|
38852f |
extern int process_file(char *conf_file);
|