From a4e76b58a5086e1339dea53b72437ed179e6025a Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Fri, 15 Aug 2014 16:11:45 +1000 Subject: [PATCH] ctdb-util: Add extra max_size argument to file_lines_load() This is part of a migration to Samba's lib/util. CTDB always passes 0 (i.e. no max_size) so use a simple assert() to enforce this, rather than changing a lot of code that will be discarded anyway. Signed-off-by: Martin Schwenke Reviewed-by: Amitay Isaacs --- ctdb/include/internal/includes.h | 2 +- ctdb/lib/util/util_file.c | 6 +++++- ctdb/server/ctdb_server.c | 2 +- ctdb/server/ctdb_takeover.c | 2 +- ctdb/tools/ctdb.c | 2 +- 5 files changed, 9 insertions(+), 5 deletions(-) diff --git a/ctdb/include/internal/includes.h b/ctdb/include/internal/includes.h index 396965f8866..951726a3961 100644 --- a/ctdb/include/internal/includes.h +++ b/ctdb/include/internal/includes.h @@ -64,7 +64,7 @@ struct timeval timeval_until(const struct timeval *tv1, _PUBLIC_ struct timeval timeval_current_ofs(uint32_t secs, uint32_t usecs); double timeval_elapsed(struct timeval *tv); double timeval_delta(struct timeval *tv2, struct timeval *tv); -char **file_lines_load(const char *fname, int *numlines, TALLOC_CTX *mem_ctx); +char **file_lines_load(const char *fname, int *numlines, size_t maxsize, TALLOC_CTX *mem_ctx); char *hex_encode_talloc(TALLOC_CTX *mem_ctx, const unsigned char *buff_in, size_t len); _PUBLIC_ int set_blocking(int fd, bool set); diff --git a/ctdb/lib/util/util_file.c b/ctdb/lib/util/util_file.c index 21d64b20e3d..5db00720618 100644 --- a/ctdb/lib/util/util_file.c +++ b/ctdb/lib/util/util_file.c @@ -3,6 +3,8 @@ not intended to remain part of ctdb */ +#include + #include "includes.h" #include "system/filesys.h" @@ -91,11 +93,13 @@ static char **file_lines_parse(char *p, size_t size, int *numlines, TALLOC_CTX * load a file into memory and return an array of pointers to lines in the file must be freed with talloc_free(). **/ -_PUBLIC_ char **file_lines_load(const char *fname, int *numlines, TALLOC_CTX *mem_ctx) +_PUBLIC_ char **file_lines_load(const char *fname, int *numlines, size_t maxsize, TALLOC_CTX *mem_ctx) { char *p; size_t size; + assert(maxsize == 0); + p = file_load(fname, &size, mem_ctx); if (!p) return NULL; diff --git a/ctdb/server/ctdb_server.c b/ctdb/server/ctdb_server.c index c45f4cb5ffd..1e3fde497f6 100644 --- a/ctdb/server/ctdb_server.c +++ b/ctdb/server/ctdb_server.c @@ -171,7 +171,7 @@ static int ctdb_set_nlist(struct ctdb_context *ctdb, const char *nlist) ctdb->nodes = NULL; ctdb->num_nodes = 0; - lines = file_lines_load(nlist, &nlines, ctdb); + lines = file_lines_load(nlist, &nlines, 0, ctdb); if (lines == NULL) { ctdb_set_error(ctdb, "Failed to load nlist '%s'\n", nlist); return -1; diff --git a/ctdb/server/ctdb_takeover.c b/ctdb/server/ctdb_takeover.c index a3b95926892..7603fbc7e4d 100644 --- a/ctdb/server/ctdb_takeover.c +++ b/ctdb/server/ctdb_takeover.c @@ -1205,7 +1205,7 @@ int ctdb_set_public_addresses(struct ctdb_context *ctdb, bool check_addresses) int nlines; int i; - lines = file_lines_load(ctdb->public_addresses_file, &nlines, ctdb); + lines = file_lines_load(ctdb->public_addresses_file, &nlines, 0, ctdb); if (lines == NULL) { ctdb_set_error(ctdb, "Failed to load public address list '%s'\n", ctdb->public_addresses_file); return -1; diff --git a/ctdb/tools/ctdb.c b/ctdb/tools/ctdb.c index ca79363d173..19a2fb150be 100644 --- a/ctdb/tools/ctdb.c +++ b/ctdb/tools/ctdb.c @@ -826,7 +826,7 @@ static struct pnn_node *read_pnn_node_file(TALLOC_CTX *mem_ctx, struct pnn_node *pnn_nodes = NULL; struct pnn_node *pnn_node; - lines = file_lines_load(file, &nlines, mem_ctx); + lines = file_lines_load(file, &nlines, 0, mem_ctx); if (lines == NULL) { return NULL; } -- 2.11.4.GIT