summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Härdeman <david@hardeman.nu>2020-06-16 14:11:58 +0200
committerDavid Härdeman <david@hardeman.nu>2020-06-16 14:11:58 +0200
commit8856becf34868c2ebaefff9baa294c21462f281b (patch)
tree18759a42f8eb7ff4541d1ffa36bed425d7a647a3
parent2aea45f0c9ffc0dcc9857478f086142ccf7811f0 (diff)
Convert most of main.c to use debugging
-rw-r--r--announce.c2
-rw-r--r--main.c41
-rw-r--r--main.h1
-rw-r--r--utils.c4
4 files changed, 26 insertions, 22 deletions
diff --git a/announce.c b/announce.c
index 9578b0c..87ae91a 100644
--- a/announce.c
+++ b/announce.c
@@ -72,8 +72,6 @@ announce_cb(struct cfg *cfg, struct uring_task *task, int res)
{
struct announce *aev = container_of(task, struct announce, task);
- debug(DBG_ANN, "res %i\n", res);
-
if (task->dead) {
debug(DBG_ANN, "task is dead\n");
return;
diff --git a/main.c b/main.c
index f7023c4..e47848c 100644
--- a/main.c
+++ b/main.c
@@ -55,9 +55,8 @@ cfg_free(struct uring_task *task)
{
struct cfg *cfg = container_of(task, struct cfg, task);
- fprintf(stderr, "%s: called\n", __func__);
+ debug(DBG_SIG, "called\n");
systemd_delete(cfg);
- fprintf(stderr, "All resources free, exiting\n");
exiting = true;
/* The cfg struct is free:d in main() */
}
@@ -75,7 +74,7 @@ cfg_read(struct cfg *cfg)
perrordie("fopen");
}
- printf("Opened config file\n");
+ debug(DBG_CFG, "opened config file\n");
fclose(cfgfile);
}
@@ -96,6 +95,9 @@ const struct {
.name = "announce",
.val = DBG_ANN
},{
+ .name = "signals",
+ .val = DBG_SIG
+ },{
.name = NULL,
.val = 0
}
@@ -190,7 +192,7 @@ signalfd_free(struct uring_task *task)
{
struct signalfd_ev *sev = container_of(task, struct signalfd_ev, task);
- fprintf(stderr, "%s: called\n", __func__);
+ debug(DBG_SIG, "called\n");
sev->cfg->sev = NULL;
xfree(sev);
}
@@ -225,23 +227,25 @@ signalfd_read(struct cfg *cfg, struct uring_task *task, int res)
static int count = 0;
if (task->dead) {
- fprintf(stderr, "%s: task dead\n", __func__);
+ debug(DBG_SIG, "task dead\n");
return;
}
count++;
- if (count > 5)
+ if (count > 5) {
+ error("Max signal count exceeded, force quitting\n");
exit(EXIT_FAILURE);
+ }
if (res != sizeof(sev->buf))
die("error in signalfd (%i)", res);
if (sev->buf < 1000) {
- fprintf(stderr, "Got a signal to quit\n");
+ info("Got a signal to quit\n");
sd_notifyf(0, "STOPPING=1\nSTATUS=Received signal, exiting");
exit(EXIT_SUCCESS);
} else {
- fprintf(stderr, "Got a signal to dump tree\n");
+ info(stderr, "Got a signal to dump tree\n");
sd_notifyf(0, "STOPPING=1\nSTATUS=Received signal, exiting");
dump_tree(cfg);
uring_task_put(cfg, &sev->task);
@@ -250,7 +254,6 @@ signalfd_read(struct cfg *cfg, struct uring_task *task, int res)
cfgdir_delete(cfg);
list_for_each_entry_safe(server, stmp, &cfg->servers, list)
server_delete(cfg, server);
- fprintf(stderr, "%s: putting sev task 0x%p\n", __func__, &sev->task);
uring_delete(cfg);
return;
}
@@ -268,27 +271,29 @@ hack_handler(int signum)
switch (signum) {
case SIGINT:
- fprintf(stderr, "Got a SIGINT\n");
+ debug(DBG_SIG, "Got a SIGINT\n");
val = 1000;
if (count > 3)
dump_tree(cfghack);
break;
case SIGHUP:
- fprintf(stderr, "Got a SIGHUP\n");
+ debug(DBG_SIG, "Got a SIGHUP\n");
val = 1000;
break;
case SIGTERM:
- fprintf(stderr, "Got a SIGTERM\n");
+ debug(DBG_SIG, "Got a SIGTERM\n");
val = 1;
break;
default:
- fprintf(stderr, "Got an unknown sig (%i)\n", signum);
+ error("Got an unknown sig (%i)\n", signum);
val = 1;
break;
}
- if (count > 5)
+ if (count > 5) {
+ error("Max signal count exceeded, force quitting\n");
exit(EXIT_FAILURE);
+ }
write(hack_efd, &val, sizeof(val));
count++;
@@ -331,7 +336,7 @@ signalfd_init(struct cfg *cfg)
if (sfd < 0)
perrordie("eventfd");
- fprintf(stderr, "signalfd init: %i\n", sfd);
+ debug(DBG_SIG, "using fd %i\n", sfd);
uring_task_init(&sev->task, "sev", uring_parent(cfg), signalfd_free);
uring_task_set_fd(&sev->task, sfd);
cfg->sev = sev;
@@ -377,12 +382,12 @@ main(int argc, char **argv)
server_count,
(unsigned long)getpid());
- fprintf(stderr, "%s: started, %u server configurations loaded\n",
- argv[0], server_count);
+ info(stderr, "%s: started, %u server configurations loaded\n",
+ argv[0], server_count);
uring_event_loop(cfg);
- fprintf(stderr, "Event loop exited\n");
+ info("Exiting\n");
xfree(cfg);
diff --git a/main.h b/main.h
index 9710d23..5d34042 100644
--- a/main.h
+++ b/main.h
@@ -20,6 +20,7 @@ enum debug_category {
DBG_REF = (0x1 << 5),
DBG_MALLOC = (0x1 << 6),
DBG_ANN = (0x1 << 7),
+ DBG_SIG = (0x1 << 7),
};
static inline bool
diff --git a/utils.c b/utils.c
index 20c4802..5830dfc 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, "%s:%i %s(%zu) = %p\n",
+ debug(DBG_MALLOC, "called from %s:%i - %s(%zu) = %p\n",
callerfn, line, allocfn, size, ptr);
a->allocfn = allocfn;
@@ -99,7 +99,7 @@ __xfree(const char *fn, int line, void *ptr)
free(ptr);
malloc_count--;
- debug(DBG_MALLOC, "%s:%i %p\n", fn, line, ptr);
+ debug(DBG_MALLOC, "called from %s:%i - %p\n", fn, line, ptr);
list_for_each_entry_safe(a, tmp, &malloc_list, list) {
if (a->ptr == ptr) {