kanoi 11 years ago
parent
commit
e8740d6eaa
  1. 49
      src/ckpool.c
  2. 7
      src/ckpool.h

49
src/ckpool.c

@ -278,7 +278,7 @@ char *_send_recv_proc(proc_instance_t *pi, const char *msg, const char *file, co
} }
sockd = open_unix_client(path); sockd = open_unix_client(path);
if (unlikely(sockd < 0)) { if (unlikely(sockd < 0)) {
LOGWARNING("Failed to open socket %s", path); LOGWARNING("Failed to open socket %s in send_recv_proc", path);
goto out; goto out;
} }
if (unlikely(!send_unix_msg(sockd, msg))) if (unlikely(!send_unix_msg(sockd, msg)))
@ -292,6 +292,36 @@ out:
return buf; return buf;
} }
/* As send_recv_proc but only to ckdb */
char *_send_recv_ckdb(const char *path, const char *msg, const char *file, const char *func, const int line)
{
char *buf = NULL;
int sockd;
if (unlikely(!path || !strlen(path))) {
LOGERR("Attempted to send message %s to null path in send_recv_ckdb", msg ? msg : "");
goto out;
}
if (unlikely(!msg || !strlen(msg))) {
LOGERR("Attempted to send null message to ckdb in send_recv_ckdb");
goto out;
}
sockd = open_unix_client(path);
if (unlikely(sockd < 0)) {
LOGWARNING("Failed to open socket %s in send_recv_ckdb", path);
goto out;
}
if (unlikely(!send_unix_msg(sockd, msg)))
LOGWARNING("Failed to send %s to ckdb", msg);
else
buf = recv_unix_msg(sockd);
close(sockd);
out:
if (unlikely(!buf))
LOGERR("Failure in send_recv_ckdb from %s %s:%d", file, func, line);
return buf;
}
json_t *json_rpc_call(connsock_t *cs, const char *rpc_req) json_t *json_rpc_call(connsock_t *cs, const char *rpc_req)
{ {
@ -750,11 +780,14 @@ int main(int argc, char **argv)
memset(&ckp, 0, sizeof(ckp)); memset(&ckp, 0, sizeof(ckp));
ckp.loglevel = LOG_NOTICE; ckp.loglevel = LOG_NOTICE;
while ((c = getopt(argc, argv, "c:g:kl:n:ps:")) != -1) { while ((c = getopt(argc, argv, "c:d:g:kl:n:pS:s:")) != -1) {
switch (c) { switch (c) {
case 'c': case 'c':
ckp.config = optarg; ckp.config = optarg;
break; break;
case 'd':
ckp.ckdb_name = optarg;
break;
case 'g': case 'g':
ckp.grpnam = optarg; ckp.grpnam = optarg;
break; break;
@ -774,6 +807,8 @@ int main(int argc, char **argv)
case 'p': case 'p':
ckp.proxy = true; ckp.proxy = true;
break; break;
case 'S':
ckp.ckdb_sockdir = strdup(optarg);
case 's': case 's':
ckp.socket_dir = strdup(optarg); ckp.socket_dir = strdup(optarg);
break; break;
@ -809,6 +844,16 @@ int main(int argc, char **argv)
} }
trail_slash(&ckp.socket_dir); trail_slash(&ckp.socket_dir);
if (!ckp.ckdb_name)
ckp.ckdb_name = "ckdb";
if (!ckp.ckdb_sockdir) {
ckp.ckdb_sockdir = strdup("/opt/");
realloc_strcat(&ckp.ckdb_sockdir, ckp.ckdb_name);
}
trail_slash(&ckp.ckdb_sockdir);
ckp.ckdb_sockname = ckp.ckdb_sockdir;
realloc_strcat(&ckp.ckdb_sockdir, "listener");
/* Ignore sigpipe */ /* Ignore sigpipe */
signal(SIGPIPE, SIG_IGN); signal(SIGPIPE, SIG_IGN);

7
src/ckpool.h

@ -67,6 +67,11 @@ struct ckpool_instance {
char *name; char *name;
/* Directory where sockets are created */ /* Directory where sockets are created */
char *socket_dir; char *socket_dir;
/* Directory where ckdb sockets are */
char *ckdb_sockdir;
/* Name of the ckdb process */
char *ckdb_name;
char *ckdb_sockname;
/* Group ID for unix sockets */ /* Group ID for unix sockets */
char *grpnam; char *grpnam;
gid_t gr_gid; gid_t gr_gid;
@ -129,6 +134,8 @@ bool _send_proc(proc_instance_t *pi, const char *msg, const char *file, const ch
#define send_proc(pi, msg) _send_proc(pi, msg, __FILE__, __func__, __LINE__) #define send_proc(pi, msg) _send_proc(pi, msg, __FILE__, __func__, __LINE__)
char *_send_recv_proc(proc_instance_t *pi, const char *msg, const char *file, const char *func, const int line); char *_send_recv_proc(proc_instance_t *pi, const char *msg, const char *file, const char *func, const int line);
#define send_recv_proc(pi, msg) _send_recv_proc(pi, msg, __FILE__, __func__, __LINE__) #define send_recv_proc(pi, msg) _send_recv_proc(pi, msg, __FILE__, __func__, __LINE__)
char *_send_recv_ckdb(const char *path, const char *msg, const char *file, const char *func, const int line);
#define send_recv_ckdb(path, msg) _send_recv_ckdb(path, msg, __FILE__, __func__, __LINE__)
json_t *json_rpc_call(connsock_t *cs, const char *rpc_req); json_t *json_rpc_call(connsock_t *cs, const char *rpc_req);

Loading…
Cancel
Save