summaryrefslogtreecommitdiff
path: root/main.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 /main.c
parente11014c0443ea687ad65a14b9124aa366da7984a (diff)
Make logging messages consistent in adding a newline for all messages
Diffstat (limited to 'main.c')
-rw-r--r--main.c86
1 files changed, 43 insertions, 43 deletions
diff --git a/main.c b/main.c
index 749d1e8..0bd5bb0 100644
--- a/main.c
+++ b/main.c
@@ -162,7 +162,7 @@ __die(const char *fmt, ...)
va_start(ap, fmt);
msg(DBG_ERROR, fmt, ap);
va_end(ap);
- sd_notifyf(0, "STATUS=Error, shutting down\n");
+ sd_notifyf(0, "STATUS=Error, shutting down");
exit(EXIT_FAILURE);
};
@@ -171,7 +171,7 @@ cfg_free(struct uring_task *task)
{
struct cfg *cfg = container_of(task, struct cfg, task);
- debug(DBG_SIG, "called\n");
+ debug(DBG_SIG, "called");
systemd_delete(cfg);
xfree(cfg->igmp_iface);
cfg->igmp_iface = NULL;
@@ -224,12 +224,12 @@ cfg_read(struct cfg *cfg)
if (errno == ENOENT && !cfg->cfg_path)
return;
else if (errno == ENOENT)
- die("main config file (%s) missing\n", path);
+ die("main config file (%s) missing", path);
else
- perrordie("fopen");
+ die("fopen(%s): %m", path);
}
- debug(DBG_CFG, "opened main config file (%s)\n", path);
+ debug(DBG_CFG, "opened main config file (%s)", path);
while (rd < sizeof(buf)) {
r = fread(pos, 1, sizeof(buf) - rd - 1, cfgfile);
@@ -240,17 +240,17 @@ cfg_read(struct cfg *cfg)
}
if (rd == 0)
- die("main config file (%s) invalid\n", path);
+ die("main config file (%s) zero size", path);
if (rd >= sizeof(buf))
- die("main config file (%s) too large\n", path);
+ die("main config file (%s) too large", path);
fclose(cfgfile);
*pos = '\0';
pos = buf;
if (!config_parse_header(cfg, path, "mcproxy", &pos))
- die("main config file (%s) invalid\n", path);
+ die("main config file (%s) invalid", path);
while (true) {
int key;
@@ -262,9 +262,9 @@ cfg_read(struct cfg *cfg)
break;
if (key == MCFG_KEY_INVALID)
- die("main config file (%s) invalid\n", path);
+ die("main config file (%s) invalid", path);
- debug(DBG_CFG, "main cfg: key %s\n", keyname);
+ debug(DBG_CFG, "main cfg: key %s", keyname);
switch (key) {
@@ -275,13 +275,13 @@ cfg_read(struct cfg *cfg)
case MCFG_KEY_IGMP_IFACE:
cfg->igmp_iface = xstrdup(value.str);
if (!cfg->igmp_iface)
- perrordie("xstrdup");
+ die("xstrdup: %m");
break;
case MCFG_KEY_INVALID:
default:
- die("main config file (%s) invalid\n", path);
+ die("main config file (%s) invalid", path);
}
}
}
@@ -339,7 +339,7 @@ __attribute__((noreturn)) static void
usage(int argc, char **argv, bool invalid)
{
if (invalid)
- info("Invalid option(s)\n");
+ info("Invalid option(s)");
info("Usage: %s [OPTIONS]\n"
"\n"
@@ -367,7 +367,7 @@ cfg_init(int argc, char **argv)
cfg = zmalloc(sizeof(*cfg));
if (!cfg)
- perrordie("malloc");
+ die("malloc: %m");
cfg->uid = geteuid();
cfg->gid = getegid();
@@ -423,7 +423,7 @@ cfg_init(int argc, char **argv)
die("failed to find user %s (%m)", optarg);
}
- debug(DBG_CFG, "asked to execute with uid %ji gid %ji\n",
+ debug(DBG_CFG, "asked to execute with uid %ji gid %ji",
(intmax_t)pwd->pw_uid,
(intmax_t)pwd->pw_gid);
cfg->uid = pwd->pw_uid;
@@ -436,10 +436,10 @@ cfg_init(int argc, char **argv)
debug_mask = ~0;
break;
} else if (!strcasecmp(optarg, "list")) {
- error("Debug categories:\n");
- error(" * all\n");
+ error("Debug categories:");
+ error(" * all");
for (i = 0; debug_category_str[i].name; i++)
- error(" * %s\n", debug_category_str[i].name);
+ error(" * %s", debug_category_str[i].name);
exit(EXIT_FAILURE);
}
@@ -449,7 +449,7 @@ cfg_init(int argc, char **argv)
}
if (!debug_category_str[i].name)
- die("invalid debug category");
+ usage(argc, argv, true);
debug_mask |= debug_category_str[i].val;
break;
@@ -515,13 +515,13 @@ cfg_apply(struct cfg *cfg)
* accessing a directory we should have permissions to.
*/
if (chdir(cfg->homedir))
- perrordie("chdir(%s)", cfg->homedir);
+ die("chdir(%s): %m", cfg->homedir);
if (debug_enabled(DBG_VERBOSE)) {
char *wd;
wd = get_current_dir_name();
- verbose("Homedir: %s\n", wd ? wd : "<unknown>");
+ verbose("Homedir: %s", wd ? wd : "<unknown>");
free(wd);
}
}
@@ -538,7 +538,7 @@ signalfd_free(struct uring_task *task)
{
struct signalfd_ev *sev = container_of(task, struct signalfd_ev, task);
- debug(DBG_SIG, "called\n");
+ debug(DBG_SIG, "called");
sev->cfg->sev = NULL;
xfree(sev);
}
@@ -551,9 +551,9 @@ dump_tree(struct cfg *cfg)
if (!debug_enabled(DBG_REF))
return;
- debug(DBG_REF, "\n\n\n\n");
- debug(DBG_REF, "Dumping Tree\n");
- debug(DBG_REF, "============\n");
+ debug(DBG_REF, "\n\n");
+ debug(DBG_REF, "Dumping Tree");
+ debug(DBG_REF, "============");
uring_task_refdump(&cfg->task);
uring_refdump(cfg->uev);
if (cfg->sev)
@@ -564,8 +564,8 @@ dump_tree(struct cfg *cfg)
cfgdir_refdump(cfg->iev);
list_for_each_entry(server, &cfg->servers, list)
server_refdump(server);
- debug(DBG_REF, "============\n");
- debug(DBG_REF, "\n\n\n\n");
+ debug(DBG_REF, "============");
+ debug(DBG_REF, "\n\n");
}
static struct dns_async *hack_dns = NULL;
@@ -582,11 +582,11 @@ signalfd_read(struct cfg *cfg, struct uring_task *task, int res)
die("error in signalfd (%i)", res);
if (sev->buf < 1000) {
- verbose("got a signal to quit\n");
+ verbose("got a signal to quit");
sd_notifyf(0, "STOPPING=1\nSTATUS=Received signal, exiting");
exit(EXIT_SUCCESS);
} else if (sev->buf < 10000) {
- verbose("got a signal to dump tree\n");
+ verbose("got a signal to dump tree");
sd_notifyf(0, "STOPPING=1\nSTATUS=Received signal, exiting");
dump_tree(cfg);
uring_task_put(cfg, &sev->task);
@@ -598,12 +598,12 @@ signalfd_read(struct cfg *cfg, struct uring_task *task, int res)
uring_delete(cfg);
return;
} else {
- debug(DBG_DNS, "DNS lookup complete, dns: %p, dns->cb: %p\n",
+ debug(DBG_DNS, "DNS lookup complete, dns: %p, dns->cb: %p",
hack_dns,
hack_dns ? hack_dns->cb : NULL);
if (!hack_dns || !hack_dns->cb) {
- error("DNS callback not set\n");
+ error("DNS callback not set");
goto out;
}
@@ -623,29 +623,29 @@ hack_handler(int signum, siginfo_t *info, void *ucontext)
switch (signum) {
case SIGUSR1:
- debug(DBG_SIG, "Got a SIGUSR1\n");
+ debug(DBG_SIG, "Got a SIGUSR1");
if (info->si_code != SI_ASYNCNL || info->si_signo != SIGUSR1 || !info->si_ptr) {
- debug(DBG_SIG, "unexpected values in siginfo\n");
+ debug(DBG_SIG, "unexpected values in siginfo");
return;
}
- debug(DBG_SIG, "SIGUSR1 struct dns_async: %p\n", info->si_ptr);
+ debug(DBG_SIG, "SIGUSR1 struct dns_async: %p", info->si_ptr);
hack_dns = info->si_ptr;
val = 10000;
break;
case SIGINT:
- debug(DBG_SIG, "Got a SIGINT\n");
+ debug(DBG_SIG, "Got a SIGINT");
val = 1000;
break;
case SIGHUP:
- debug(DBG_SIG, "Got a SIGHUP\n");
+ debug(DBG_SIG, "Got a SIGHUP");
val = 1000;
break;
case SIGTERM:
- debug(DBG_SIG, "Got a SIGTERM\n");
+ debug(DBG_SIG, "Got a SIGTERM");
val = 1;
break;
default:
- error("Got an unknown sig (%i)\n", signum);
+ error("Got an unknown sig (%i)", signum);
val = 1;
break;
}
@@ -662,7 +662,7 @@ signalfd_init(struct cfg *cfg)
sev = zmalloc(sizeof(*sev));
if (!sev)
- perrordie("malloc");
+ die("malloc: %m");
/*
sigfillset(&mask);
@@ -690,9 +690,9 @@ signalfd_init(struct cfg *cfg)
sfd = eventfd(0, EFD_CLOEXEC);
if (sfd < 0)
- perrordie("eventfd");
+ die("eventfd: %m");
- debug(DBG_SIG, "using fd %i\n", sfd);
+ debug(DBG_SIG, "using fd %i", sfd);
uring_task_init(&sev->task, "sev", uring_parent(cfg), signalfd_free);
uring_task_set_fd(&sev->task, sfd);
cfg->sev = sev;
@@ -753,12 +753,12 @@ main(int argc, char **argv)
server_count,
(unsigned long)getpid());
- info("mcproxy started, %u server configurations loaded\n",
+ info("mcproxy started, %u server configurations loaded",
server_count);
uring_event_loop(cfg);
- verbose("Exiting\n");
+ verbose("Exiting");
xfree(cfg);