Browse Source

Create the beginnings of a separate tool to talk to ckpool sockets

master
Con Kolivas 11 years ago
parent
commit
ed341c9502
  1. 5
      src/Makefile.am
  2. 52
      src/ckpmsg.c
  3. 7
      src/ckpool.c
  4. 9
      src/libckpool.c
  5. 2
      src/libckpool.h

5
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@

52
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 <string.h>
#include <unistd.h>
#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;
}

7
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);

9
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;

2
src/libckpool.h

@ -19,6 +19,7 @@
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <syslog.h>
#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);

Loading…
Cancel
Save