Browse Source

Create the main read parse loop for the generator and send it a test message

master
Con Kolivas 11 years ago
parent
commit
6f679e1cf4
  1. 18
      src/ckpool.c
  2. 39
      src/generator.c

18
src/ckpool.c

@ -124,6 +124,7 @@ static void launch_process(proc_instance_t *pi)
{ {
pid_t pid; pid_t pid;
create_process_unixsock(pi);
pid = fork(); pid = fork();
if (pid < 0) if (pid < 0)
quit(1, "Failed to fork %s in launch_process", pi->processname); quit(1, "Failed to fork %s in launch_process", pi->processname);
@ -132,7 +133,6 @@ static void launch_process(proc_instance_t *pi)
rename_proc(pi->processname); rename_proc(pi->processname);
write_namepid(pi); write_namepid(pi);
create_process_unixsock(pi);
ret = pi->process(pi); ret = pi->process(pi);
close_unix_socket(pi->us.sockd, pi->us.path); close_unix_socket(pi->us.sockd, pi->us.path);
rm_namepid(pi); rm_namepid(pi);
@ -194,6 +194,20 @@ static void parse_config(ckpool_t *ckp)
json_decref(json_conf); json_decref(json_conf);
} }
static void test_functions(ckpool_t *ckp)
{
char *path = ckp->generator.us.path;
int genfd;
genfd = open_unix_client(ckp->generator.us.path);
if (genfd < 0) {
LOGWARNING("Failed to open generator socket %s", path);
return;
}
send_unix_msg(genfd, "shutdown");
close(genfd);
}
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
struct sigaction handler; struct sigaction handler;
@ -261,6 +275,8 @@ int main(int argc, char **argv)
sigaction(SIGTERM, &handler, NULL); sigaction(SIGTERM, &handler, NULL);
sigaction(SIGINT, &handler, NULL); sigaction(SIGINT, &handler, NULL);
test_functions(&ckp);
/* Shutdown from here */ /* Shutdown from here */
join_pthread(pth_listener); join_pthread(pth_listener);

39
src/generator.c

@ -9,13 +9,50 @@
#include "config.h" #include "config.h"
#include <sys/socket.h>
#include <string.h> #include <string.h>
#include <unistd.h>
#include "ckpool.h" #include "ckpool.h"
#include "libckpool.h" #include "libckpool.h"
#include "generator.h" #include "generator.h"
#include "bitcoin.h" #include "bitcoin.h"
static int gen_loop(proc_instance_t *pi)
{
unixsock_t *us = &pi->us;
int sockd, ret = 0;
gbtbase_t gbt;
char *buf;
memset(&gbt, 0, sizeof(gbt));
retry:
sockd = accept(us->sockd, NULL, NULL);
if (sockd < 0) {
if (interrupted())
goto retry;
LOGERR("Failed to accept on generator socket");
ret = 1;
goto out;
}
buf = recv_unix_msg(sockd);
if (!buf) {
LOGWARNING("Failed to get message in gen_loop");
close(sockd);
goto retry;
}
LOGDEBUG("Generator received request: %s", buf);
if (!strncmp(buf, "shutdown", 8))
goto out;
dealloc(buf);
close(sockd);
goto retry;
out:
return ret;
}
int generator(proc_instance_t *pi) int generator(proc_instance_t *pi)
{ {
ckpool_t *ckp = pi->ckp; ckpool_t *ckp = pi->ckp;
@ -64,6 +101,8 @@ int generator(proc_instance_t *pi)
goto out; goto out;
} }
clear_gbtbase(&gbt); clear_gbtbase(&gbt);
ret = gen_loop(pi);
out: out:
/* Clean up here */ /* Clean up here */
dealloc(cs.url); dealloc(cs.url);

Loading…
Cancel
Save