summaryrefslogtreecommitdiff
path: root/idle.c
diff options
context:
space:
mode:
authorDavid Härdeman <david@hardeman.nu>2020-06-20 14:55:54 +0200
committerDavid Härdeman <david@hardeman.nu>2020-06-20 14:55:54 +0200
commit77f9be38d7469eefb0fac3adf43261b4d84315d2 (patch)
tree70c42ec4864e850e15b0c31b9493646ead42a05b /idle.c
parente11014c0443ea687ad65a14b9124aa366da7984a (diff)
Make logging messages consistent in adding a newline for all messages
Diffstat (limited to 'idle.c')
-rw-r--r--idle.c63
1 files changed, 31 insertions, 32 deletions
diff --git a/idle.c b/idle.c
index 3be8974..4bd0656 100644
--- a/idle.c
+++ b/idle.c
@@ -30,7 +30,7 @@ idle_check_free(struct uring_task *task)
{
struct idle *idle = container_of(task, struct idle, idlecheck);
- debug(DBG_IDLE, "task %p, idle %p\n", task, idle);
+ debug(DBG_IDLE, "task %p, idle %p", task, idle);
}
static inline void
@@ -128,22 +128,22 @@ idle_check_handshake_complete(struct cfg *cfg, struct uring_task *task, int res)
r = read_varint(&pos, &remain, &mclen);
if (r < 0) {
- error("failed to parse message length\n");
+ error("failed to parse message length");
return -EINVAL;
} else if (r == 0) {
return 0;
} else if (mclen < 2) {
- error("short MC message\n");
+ error("short MC message");
return -EINVAL;
}
if (mclen < remain) {
- debug(DBG_IDLE, "short MC message - len: %" PRIi32 ", remain: %zu\n",
+ debug(DBG_IDLE, "short MC message - len: %" PRIi32 ", remain: %zu",
mclen, remain);
return 0;
}
- debug(DBG_IDLE, "Complete message\n");
+ debug(DBG_IDLE, "Complete message");
return 1;
}
@@ -165,7 +165,7 @@ get_player_count(struct cfg *cfg, const char *pos, size_t remain)
online = memmem(pos, remain, ONLINE_NEEDLE, strlen(ONLINE_NEEDLE));
if (!online) {
- error("could not find online count in JSON\n");
+ error("could not find online count in JSON");
return -1;
}
@@ -173,13 +173,13 @@ get_player_count(struct cfg *cfg, const char *pos, size_t remain)
end = memchr(online, '}', remain);
if (!end) {
- error("could not parse JSON (no end)\n");
+ error("could not parse JSON (no end)");
return -1;
}
*end = '\0';
if (sscanf(online, ONLINE_NEEDLE " : %u", &count) != 1) {
- error("could not parse JSON (online count)\n");
+ error("could not parse JSON (online count)");
return -1;
}
@@ -199,15 +199,15 @@ idle_check_handshake_reply(struct cfg *cfg, struct uring_task *task, int res)
assert_task_alive(DBG_IDLE, task);
- debug(DBG_IDLE, "res: %i\n", res);
+ debug(DBG_IDLE, "res: %i", res);
if (res < 0)
goto out;
/*
- fprintf(stderr, "Received MC message (%i bytes):\n", res);
+ fprintf(stderr, "Received MC message (%i bytes):", res);
for (int i = 0; i < res; i++)
fprintf(stderr, "0x%02hhx ", idle->remotebuf[i]);
- fprintf(stderr, "\n");
+ fprintf(stderr, "n");
*/
remain = idle->tbuf.len;
@@ -216,15 +216,15 @@ idle_check_handshake_reply(struct cfg *cfg, struct uring_task *task, int res)
r = read_varint(&pos, &remain, &mclen);
if (r <= 0 || mclen < 2 || mclen < remain) {
/* Should not happen since the msg has been checked already */
- error("invalid message\n");
+ error("invalid message");
goto out;
}
- debug(DBG_IDLE, "MC message - len: %" PRIi32 ", remain: %zu\n",
+ debug(DBG_IDLE, "MC message - len: %" PRIi32 ", remain: %zu",
mclen, remain);
if (*pos != MC_STATUS_REPLY) {
- error("unknown server reply (0x%02hhx)\n", *pos);
+ error("unknown server reply (0x%02hhx)", *pos);
goto out;
}
@@ -233,15 +233,15 @@ idle_check_handshake_reply(struct cfg *cfg, struct uring_task *task, int res)
r = read_varint(&pos, &remain, &jsonlen);
if (r <= 0) {
- error("could not read JSON length\n");
+ error("could not read JSON length");
goto out;
}
- debug(DBG_IDLE, "MC - json len: %" PRIi32 ", remain: %zu\n",
+ debug(DBG_IDLE, "MC - json len: %" PRIi32 ", remain: %zu",
jsonlen, remain);
if (jsonlen < remain) {
- error("invalid JSON length\n");
+ error("invalid JSON length");
goto out;
}
@@ -249,7 +249,6 @@ idle_check_handshake_reply(struct cfg *cfg, struct uring_task *task, int res)
fprintf(stderr, "JSON: ");
for (int i = 0; i < jsonlen; i++)
fprintf(stderr, "%c", pos[i]);
- fprintf(stderr, "\n");
*/
player_count = get_player_count(cfg, pos, remain);
@@ -258,7 +257,7 @@ idle_check_handshake_reply(struct cfg *cfg, struct uring_task *task, int res)
idle->server->state = SERVER_STATE_RUNNING;
- debug(DBG_IDLE, "%s: currently %i active players\n",
+ debug(DBG_IDLE, "%s: currently %i active players",
idle->server->name, player_count);
if (player_count > 0)
@@ -267,7 +266,7 @@ idle_check_handshake_reply(struct cfg *cfg, struct uring_task *task, int res)
idle->server->idle_count++;
if (idle->server->idle_count > idle->server->idle_timeout) {
- verbose("stopping idle server %s\n", idle->server->name);
+ verbose("stopping idle server %s", idle->server->name);
server_stop(cfg, idle->server);
}
@@ -283,7 +282,7 @@ idle_check_handshake_sent(struct cfg *cfg, struct uring_task *task, int res)
assert_task_alive(DBG_IDLE, task);
- debug(DBG_IDLE, "sent %i bytes\n", res);
+ debug(DBG_IDLE, "sent %i bytes", res);
if (res < 0) {
uring_task_close_fd(cfg, task);
return;
@@ -308,14 +307,14 @@ idle_check_connected_cb(struct cfg *cfg, struct connection *conn, bool connected
if (!connected) {
debug(DBG_IDLE,
- "idle check connection to remote server (%s) failed\n",
+ "idle check connection to remote server (%s) failed",
idle->server->name);
idle->server->idle_count = 0;
idle->server->state = SERVER_STATE_STOPPED;
return;
}
- debug(DBG_IDLE, "connected to remote %s\n", idle->conn.remote.addrstr);
+ debug(DBG_IDLE, "connected to remote %s", idle->conn.remote.addrstr);
port = saddr_port(&conn->remote);
saddr_addr(&conn->remote, hostname, sizeof(hostname));
@@ -335,7 +334,7 @@ idle_check_connected_cb(struct cfg *cfg, struct connection *conn, bool connected
write_cmd(&cmdbuf, buf, pos);
idle->tbuf.len = (cmdbuf - idle->tbuf.buf);
- debug(DBG_IDLE, "sending MC message (%zu bytes)\n", idle->tbuf.len);
+ debug(DBG_IDLE, "sending MC message (%zu bytes)", idle->tbuf.len);
uring_tbuf_write(cfg, &idle->idlecheck, idle_check_handshake_sent);
}
@@ -348,11 +347,11 @@ idle_cb(struct cfg *cfg, struct uring_task *task, int res)
assert_task_alive(DBG_IDLE, task);
if (res != sizeof(idle->value)) {
- error("timerfd_read returned %i\n", res);
- perrordie("timerfd_read");
+ error("timerfd_read: %i", res);
+ return;
}
- debug(DBG_IDLE, "timer fired (value: %" PRIu64 ")\n", idle->value);
+ debug(DBG_IDLE, "timer fired (value: %" PRIu64 ")", idle->value);
if (!list_empty(&idle->server->proxys))
idle->server->idle_count = 0;
@@ -368,7 +367,7 @@ idle_free(struct uring_task *task)
{
struct idle *idle = container_of(task, struct idle, task);
- debug(DBG_IDLE, "task %p, idle %p\n", task, idle);
+ debug(DBG_IDLE, "task %p, idle %p", task, idle);
xfree(idle);
}
@@ -390,7 +389,7 @@ idle_delete(struct cfg *cfg, struct server *server)
if (!idle)
return;
- debug(DBG_IDLE, "closing fd %i\n", idle->task.fd);
+ debug(DBG_IDLE, "closing fd %i", idle->task.fd);
uring_task_destroy(cfg, &idle->idlecheck);
uring_task_destroy(cfg, &idle->task);
server->idle = NULL;
@@ -421,14 +420,14 @@ idle_init(struct cfg *cfg, struct server *server)
idle = zmalloc(sizeof(*idle));
if (!idle)
- perrordie("malloc");
+ die("malloc: %m");
ifd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC);
if (ifd < 0)
- perrordie("timerfd_create");
+ die("timerfd_create: %m");
if (timerfd_settime(ifd, 0, &tspec, NULL) != 0)
- perrordie("timerfd_settime");
+ die("timerfd_settime: %m");
uring_task_init(&idle->task, "idle", &server->task, idle_free);
uring_task_set_fd(&idle->task, ifd);