#include <sys/stat.h>
#include <sys/socket.h>
+#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;
"/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);
/* 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);
}
}
-static void init(void)
+static void socket_init(void)
{
gen_socket_filename();
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,
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 */
/* 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);
}
}
{
header();
init();
- daemonize();
- run();
+ /* daemonize(); */
+ /* run(); */
cleanup();
return EXIT_SUCCESS;