From 77f9be38d7469eefb0fac3adf43261b4d84315d2 Mon Sep 17 00:00:00 2001 From: David Härdeman Date: Sat, 20 Jun 2020 14:55:54 +0200 Subject: Make logging messages consistent in adding a newline for all messages --- utils.c | 38 ++++++++++++++++---------------------- 1 file changed, 16 insertions(+), 22 deletions(-) (limited to 'utils.c') diff --git a/utils.c b/utils.c index b07fdff..0ddaa28 100644 --- a/utils.c +++ b/utils.c @@ -36,7 +36,7 @@ add_allocation(const char *allocfn, const char *callerfn, int line, void *ptr, s { struct allocation *a = malloc(sizeof(*a)); - debug(DBG_MALLOC, "called from %s:%i - %s(%zu) = %p\n", + debug(DBG_MALLOC, "called from %s:%i - %s(%zu) = %p", callerfn, line, allocfn, size, ptr); a->allocfn = allocfn; @@ -57,8 +57,6 @@ __zmalloc(const char *fn, int line, size_t size) ptr = calloc(1, size); if (ptr) add_allocation("zmalloc", fn, line, ptr, size); - else - perrordie("zmalloc"); return ptr; } @@ -70,8 +68,6 @@ __xstrdup(const char *fn, int line, const char *s) ptr = strdup(s); if (ptr) add_allocation("xstrdup", fn, line, ptr, strlen(s) + 1); - else - perrordie("strdup"); return ptr; } @@ -83,8 +79,6 @@ __xstrndup(const char *fn, int line, const char *s, size_t n) ptr = strndup(s, n); if (ptr) add_allocation("xstrndup", fn, line, ptr, n); - else - perrordie("strndup"); return ptr; } @@ -99,7 +93,7 @@ __xfree(const char *fn, int line, void *ptr) free(ptr); malloc_count--; - debug(DBG_MALLOC, "called from %s:%i - %p\n", fn, line, ptr); + debug(DBG_MALLOC, "called from %s:%i - %p", fn, line, ptr); list_for_each_entry_safe(a, tmp, &malloc_list, list) { if (a->ptr == ptr) { @@ -110,7 +104,7 @@ __xfree(const char *fn, int line, void *ptr) } if (delete_count != 1) { - error("Delete count is %u for ptr 0x%p\n", delete_count, ptr); + error("Delete count is %u for ptr 0x%p", delete_count, ptr); exit(EXIT_FAILURE); } } @@ -125,21 +119,21 @@ debug_resource_usage() ssize_t r; unsigned file_count = 0; - debug(DBG_MALLOC, "Still malloced %i (total %u)\n", + debug(DBG_MALLOC, "Still malloced %i (total %u)", malloc_count, total_malloc_count); list_for_each_entry(a, &malloc_list, list) { - debug(DBG_MALLOC, "* Lost allocation - %s:%i - ptr: %p, size: %zu\n", + debug(DBG_MALLOC, "* Lost allocation - %s:%i - ptr: %p, size: %zu", a->callerfn, a->line, a->ptr, a->size); } dir = opendir("/proc/self/fd"); if (!dir) { - error("failed to open fd dir\n"); + error("failed to open fd dir"); return; } - debug(DBG_MALLOC, "Open files:\n"); + debug(DBG_MALLOC, "Open files:"); while ((dent = readdir(dir)) != NULL) { if (!strcmp(dent->d_name, ".") || !strcmp(dent->d_name, "..")) @@ -147,19 +141,19 @@ debug_resource_usage() r = readlinkat(dirfd(dir), dent->d_name, buf, sizeof(buf)); if (r < 0) { - debug(DBG_MALLOC, "Failed to readlink %s\n", dent->d_name); + debug(DBG_MALLOC, "Failed to readlink %s", dent->d_name); continue; } buf[r] = '\0'; - debug(DBG_MALLOC, " * %s -> %s\n", dent->d_name, buf); + debug(DBG_MALLOC, " * %s -> %s", dent->d_name, buf); file_count++; } closedir(dir); if (file_count > 4) - debug(DBG_MALLOC, "Lost file descriptor(s)\n"); + debug(DBG_MALLOC, "Lost file descriptor(s)"); - debug(DBG_MALLOC, "CQEs used: %" PRIu64 ", SQEs used: %" PRIu64 "\n", + debug(DBG_MALLOC, "CQEs used: %" PRIu64 ", SQEs used: %" PRIu64, cqe_count, sqe_count); } @@ -214,7 +208,7 @@ connect_cb(struct cfg *cfg, struct uring_task *task, int res) struct connection *conn = task->priv; if (res < 0) { - debug(DBG_UR, "%s: connection to %s failed\n", + debug(DBG_UR, "%s: connection to %s failed", task->name, conn->remote.addrstr); uring_task_close_fd(cfg, task); connect_next(cfg, task, conn); @@ -223,7 +217,7 @@ connect_cb(struct cfg *cfg, struct uring_task *task, int res) connection_set_local(cfg, conn, task->fd); - debug(DBG_UR, "%s: connection established %s -> %s\n", + debug(DBG_UR, "%s: connection established %s -> %s", task->name, conn->local.addrstr, conn->remote.addrstr); conn->callback(cfg, conn, true); @@ -250,14 +244,14 @@ again: } if (!remote) { - debug(DBG_UR, "%s: no more remote addresses to attempt\n", + debug(DBG_UR, "%s: no more remote addresses to attempt", task->name); goto out; } conn->next_addr++; connection_set_remote(cfg, conn, remote); - debug(DBG_MALLOC, "%s: attempting to connect to %s\n", + debug(DBG_MALLOC, "%s: attempting to connect to %s", task->name, conn->remote.addrstr); sfd = socket(conn->remote.storage.ss_family, SOCK_STREAM | SOCK_CLOEXEC, 0); @@ -283,7 +277,7 @@ connect_any(struct cfg *cfg, struct uring_task *task, void (*callback)(struct cfg *, struct connection *, bool res)) { if (!cfg || !task || !addrs || !conn || !callback) { - error("invalid arguments\n"); + error("invalid arguments"); return; } -- cgit v1.2.3