From: Tom Balzer Date: Tue, 26 Jun 2018 11:25:35 +0000 (-0500) Subject: Changed print statements to a macro to avoid prepending [tomd] X-Git-Url: http://git.hcoop.net/tlb/tomd.git/commitdiff_plain/57c826149f1250aa6fd92b47ef8adb958b7a7432 Changed print statements to a macro to avoid prepending [tomd] --- diff --git a/include/macros.h b/include/macros.h new file mode 100644 index 0000000..073768d --- /dev/null +++ b/include/macros.h @@ -0,0 +1,6 @@ +#ifndef _MACROS_H +#define _MACROS_H + +#define tomd_p(...) {printf("[tomd] "); printf(__VA_ARGS__); printf("\n");} + +#endif diff --git a/src/tomd/main.c b/src/tomd/main.c index 1b97524..a8cd25b 100644 --- a/src/tomd/main.c +++ b/src/tomd/main.c @@ -25,10 +25,13 @@ #include #include +#include "../../include/macros.h" +#include "../../include/manifest.h" + static void header(void) { - printf("[tomd] Tom's Daemon, Copyright (C) 2018 Thomas Balzer\n"); - printf("[tomd] GPL v3 or later license.\n"); + tomd_p("Tom's Daemon, Copyright (C) 2018 Thomas Balzer"); + tomd_p("GPL v3 or later license."); } static int sfd; @@ -46,7 +49,7 @@ static void gen_socket_filename(void) "/run/user/%d/tomd/socket", this_user_id); - printf("[tomd] making dir '%s'\n", socket_dirname); + tomd_p("making dir '%s'", socket_dirname); /* lazy way */ char buf[100]; sprintf(buf, "mkdir -p %s", socket_dirname); @@ -56,10 +59,10 @@ static void gen_socket_filename(void) /* exit(EXIT_FAILURE); */ /* } */ - printf("[tomd] removing file '%s'\n", socket_filename); + tomd_p("removing file '%s'", socket_filename); if(unlink(socket_filename) != 0){ if(errno == ENOENT){ - printf("[tomd] socket file doesn't exist\n"); + tomd_p("socket file doesn't exist"); }else{ perror("[tomd] socket unlink"); exit(EXIT_FAILURE); @@ -67,7 +70,7 @@ static void gen_socket_filename(void) } } -static void init(void) +static void socket_init(void) { gen_socket_filename(); @@ -92,7 +95,7 @@ static void init(void) sizeof(name.sun_path)); size = SUN_LEN(&name); - printf("[tomd] attempting to bind to '%s'\n", + tomd_p("attempting to bind to '%s'", socket_filename); if(bind(sfd, (struct sockaddr *) &name, @@ -101,7 +104,13 @@ static void init(void) exit(EXIT_FAILURE); } - printf("[tomd] initialized tomd socket connections\n"); + tomd_p("initialized tomd socket connections"); +} + +static void init(void) +{ + socket_init(); + load_jobs(); } /* These defines are here to improve the local readability */ @@ -150,13 +159,13 @@ static void run(void) /* addr, */ /* size); */ - printf("[tomd] accepted socket connection from '%s'\n", + tomd_p("accepted socket connection from '%s'", ((struct sockaddr_un *) &addr)->sun_path); char accept_buf[100] = {}; read(accept_sfd, accept_buf, 100); - printf("[tomd] got message '%s'\n, accept_buf"); + tomd_p("got message '%s', accept_buf"); close(accept_sfd); } } @@ -172,8 +181,8 @@ int main(int argc, char **argv) { header(); init(); - daemonize(); - run(); + /* daemonize(); */ + /* run(); */ cleanup(); return EXIT_SUCCESS;