diff options
author | Amitay Isaacs <amitay@gmail.com> | 2014-06-10 14:52:19 +1000 |
---|---|---|
committer | Martin Schwenke <martins@samba.org> | 2014-06-12 05:40:10 +0200 |
commit | 27d1137e26703d7fa5fba638e56961384a140eb2 (patch) | |
tree | 50d1c8a5e03e9c68f25b3071bd81c1113bb958b0 /ctdb/common | |
parent | 49e34651a95a336c9e410e4b52a8cfd491ca0a67 (diff) | |
download | samba-27d1137e26703d7fa5fba638e56961384a140eb2.tar.gz |
ctdb-logging: Split ringbuffer handling code from ctdb_collect_log
Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>
Diffstat (limited to 'ctdb/common')
-rw-r--r-- | ctdb/common/ctdb_logging.c | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/ctdb/common/ctdb_logging.c b/ctdb/common/ctdb_logging.c index baaf7007993..03ac2689581 100644 --- a/ctdb/common/ctdb_logging.c +++ b/ctdb/common/ctdb_logging.c @@ -103,7 +103,8 @@ void ctdb_log_ringbuffer_free(void) log_ringbuf_size = 0; } -void ctdb_collect_log(struct ctdb_context *ctdb, struct ctdb_get_log_addr *log_addr) +TDB_DATA ctdb_log_ringbuffer_collect_log(TALLOC_CTX *mem_ctx, + enum debug_level max_level) { TDB_DATA data; FILE *f; @@ -118,14 +119,15 @@ void ctdb_collect_log(struct ctdb_context *ctdb, struct ctdb_get_log_addr *log_a /* dump to a file, then send the file as a blob */ f = tmpfile(); if (f == NULL) { - DEBUG(DEBUG_ERR,(__location__ " Unable to open tmpfile - %s\n", strerror(errno))); - return; + DEBUG(DEBUG_ERR,(__location__ " Unable to open tmpfile - %s\n", + strerror(errno))); + return tdb_null; } for (i=0; i<ringbuf_count; i++) { tmp_entry = (first_entry + i) % log_ringbuf_size; - if (log_entries[tmp_entry].level > log_addr->level) { + if (log_entries[tmp_entry].level > max_level) { continue; } @@ -143,23 +145,35 @@ void ctdb_collect_log(struct ctdb_context *ctdb, struct ctdb_get_log_addr *log_a if (fsize < 0) { fclose(f); DEBUG(DEBUG_ERR, ("Cannot get file size for log entries\n")); - return; + return tdb_null; } rewind(f); data.dptr = talloc_size(NULL, fsize); if (data.dptr == NULL) { fclose(f); - CTDB_NO_MEMORY_VOID(ctdb, data.dptr); + DEBUG(DEBUG_ERR, (__location__ " Memory allocation error\n")); + return tdb_null; } data.dsize = fread(data.dptr, 1, fsize, f); fclose(f); DEBUG(DEBUG_ERR,("Marshalling log entries into a blob of %d bytes\n", (int)data.dsize)); + return data; +} + +void ctdb_collect_log(struct ctdb_context *ctdb, struct ctdb_get_log_addr *log_addr) +{ + TDB_DATA data; + + data = ctdb_log_ringbuffer_collect_log(ctdb, log_addr->level); + DEBUG(DEBUG_ERR,("Send log to %d:%d\n", (int)log_addr->pnn, (int)log_addr->srvid)); ctdb_client_send_message(ctdb, log_addr->pnn, log_addr->srvid, data); - talloc_free(data.dptr); + if (data.dptr) { + talloc_free(data.dptr); + } } int32_t ctdb_control_get_log(struct ctdb_context *ctdb, TDB_DATA addr) |