From ed341c95024d34190033240d7d790b9bd1d7b0f7 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Tue, 3 Jun 2014 14:55:30 +1000 Subject: [PATCH] Create the beginnings of a separate tool to talk to ckpool sockets --- src/Makefile.am | 5 ++++- src/ckpmsg.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++ src/ckpool.c | 7 ++----- src/libckpool.c | 9 +++++++++ src/libckpool.h | 2 ++ 5 files changed, 69 insertions(+), 6 deletions(-) create mode 100644 src/ckpmsg.c diff --git a/src/Makefile.am b/src/Makefile.am index 0512b9e3..3cce0b8c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -6,8 +6,11 @@ lib_LTLIBRARIES = libckpool.la libckpool_la_SOURCES = libckpool.c libckpool.h sha2.c sha2.h libckpool_la_LIBADD = @PTHREAD_LIBS@ @MATH_LIBS@ @RT_LIBS@ -bin_PROGRAMS = ckpool +bin_PROGRAMS = ckpool ckpmsg ckpool_SOURCES = ckpool.c ckpool.h generator.c generator.h bitcoin.c bitcoin.h \ stratifier.c stratifier.h connector.c connector.h uthash.h \ utlist.h ckpool_LDADD = libckpool.la @JANSSON_LIBS@ + +ckpmsg_SOURCES = ckpmsg.c +ckpmsg_LDADD = libckpool.la @JANSSON_LIBS@ diff --git a/src/ckpmsg.c b/src/ckpmsg.c new file mode 100644 index 00000000..6799da94 --- /dev/null +++ b/src/ckpmsg.c @@ -0,0 +1,52 @@ +/* + * Copyright 2014 Con Kolivas + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) + * any later version. See COPYING for more details. + */ + +#include "config.h" + +#include +#include + +#include "libckpool.h" + +int main(int argc, char **argv) +{ + char *name = NULL, *socket_dir = NULL; + bool proxy = false; + int c; + + while ((c = getopt(argc, argv, "n:s:p")) != -1) { + switch(c) { + case 'n': + name = strdup(optarg); + break; + case 's': + socket_dir = strdup(optarg); + break; + case 'p': + proxy = true; + break; + } + } + if (!socket_dir) + socket_dir = strdup("/tmp"); + trail_slash(&socket_dir); + if (!name) { + if (proxy) + name = strdup("ckproxy"); + else + name = strdup("ckpool"); + } + realloc_strcat(&socket_dir, name); + free(name); + trail_slash(&socket_dir); + realloc_strcat(&socket_dir, "listener"); + + free(socket_dir); + return 0; +} diff --git a/src/ckpool.c b/src/ckpool.c index 3af586fe..6a91289d 100644 --- a/src/ckpool.c +++ b/src/ckpool.c @@ -481,7 +481,6 @@ int main(int argc, char **argv) case 's': ckp.socket_dir = strdup(optarg); break; - break; } } @@ -504,8 +503,7 @@ int main(int argc, char **argv) realloc_strcat(&ckp.socket_dir, ckp.name); } len = strlen(ckp.socket_dir); - if (memcmp(&ckp.socket_dir[len], "/", 1)) - realloc_strcat(&ckp.socket_dir, "/"); + trail_slash(&ckp.socket_dir); /* Ignore sigpipe */ signal(SIGPIPE, SIG_IGN); @@ -550,8 +548,7 @@ int main(int argc, char **argv) /* Create the log directory */ len = strlen(ckp.logdir); - if (memcmp(&ckp.logdir[len], "/", 1)) - realloc_strcat(&ckp.logdir, "/"); + trail_slash(&ckp.logdir); ret = mkdir(ckp.logdir, 0700); if (ret && errno != EEXIST) quit(1, "Failed to make log directory %s", ckp.logdir); diff --git a/src/libckpool.c b/src/libckpool.c index 6cc3078c..d74db825 100644 --- a/src/libckpool.c +++ b/src/libckpool.c @@ -1034,6 +1034,15 @@ void realloc_strcat(char **ptr, const char *s) sprintf(ofs, "%s", s); } +void trail_slash(char **buf) +{ + int ofs; + + ofs = strlen(*buf) - 1; + if (memcmp(*buf + ofs, "/", 1)) + realloc_strcat(buf, "/"); +} + void *_ckalloc(size_t len, const char *file, const char *func, const int line) { void *ptr; diff --git a/src/libckpool.h b/src/libckpool.h index c3fe75ab..b5c06a95 100644 --- a/src/libckpool.h +++ b/src/libckpool.h @@ -19,6 +19,7 @@ #include #include #include +#include #include #if HAVE_BYTESWAP_H @@ -339,6 +340,7 @@ json_t *json_rpc_call(connsock_t *cs, const char *rpc_req); void align_len(size_t *len); void realloc_strcat(char **ptr, const char *s); +void trail_slash(char **buf); void *_ckalloc(size_t len, const char *file, const char *func, const int line); void *_ckzalloc(size_t len, const char *file, const char *func, const int line); void _dealloc(void **ptr);