Browse Source

Remove remaining users of send_procmsg from ckpool.c

master
Con Kolivas 8 years ago
parent
commit
52fc524f07
  1. 59
      src/ckpool.c
  2. 10
      src/connector.c
  3. 1
      src/connector.h

59
src/ckpool.c

@ -346,41 +346,6 @@ static int pid_wait(const pid_t pid, const int ms)
return ret; return ret;
} }
static int _send_procmsg(proc_instance_t *pi, const char *buf, const char *file, const char *func, const int line)
{
char *path = pi->us.path;
int ret = -1;
int sockd;
if (unlikely(!path || !strlen(path))) {
LOGERR("Attempted to send message %s to null path in send_proc from %s %s:%d",
buf ? buf : "", file, func, line);
goto out;
}
if (unlikely(!buf || !strlen(buf))) {
LOGERR("Attempted to send null message to socket %s in send_proc from %s %s:%d",
path, file, func, line);
goto out;
}
sockd = open_unix_client(path);
if (unlikely(sockd < 0)) {
LOGWARNING("Failed to open socket %s in send_procmsg from %s %s:%d",
path, file, func, line);
goto out;
}
if (unlikely(!send_unix_msg(sockd, buf)))
LOGWARNING("Failed to send %s to socket %s from %s %s:%d", buf,
path, file, func, line);
else
ret = sockd;
out:
if (unlikely(ret == -1))
LOGERR("Failure in send_procmsg from %s %s:%d", file, func, line);
return ret;
}
#define send_procmsg(PI, BUF) _send_procmsg(&(PI), BUF, __FILE__, __func__, __LINE__)
static void api_message(ckpool_t *ckp, char **buf, int *sockd) static void api_message(ckpool_t *ckp, char **buf, int *sockd)
{ {
apimsg_t *apimsg = ckalloc(sizeof(apimsg_t)); apimsg_t *apimsg = ckalloc(sizeof(apimsg_t));
@ -438,31 +403,21 @@ retry:
send_unix_msg(sockd, "success"); send_unix_msg(sockd, "success");
} }
} else if (cmdmatch(buf, "getxfd")) { } else if (cmdmatch(buf, "getxfd")) {
int connfd = send_procmsg(ckp->connector, buf); int fdno = -1;
if (connfd > 0) {
int newfd = get_fd(connfd);
if (newfd > 0) { sscanf(buf, "getxfd%d", &fdno);
LOGDEBUG("Sending new fd %d", newfd); connector_send_fd(ckp, fdno, sockd);
send_fd(newfd, sockd);
Close(newfd);
} else
LOGWARNING("Failed to get_fd");
Close(connfd);
} else
LOGWARNING("Failed to send_procmsg to connector");
} else if (cmdmatch(buf, "accept")) { } else if (cmdmatch(buf, "accept")) {
LOGWARNING("Listener received accept message, accepting clients"); LOGWARNING("Listener received accept message, accepting clients");
send_procmsg(ckp->connector, "accept"); send_proc(ckp->connector, "accept");
send_unix_msg(sockd, "accepting"); send_unix_msg(sockd, "accepting");
} else if (cmdmatch(buf, "reject")) { } else if (cmdmatch(buf, "reject")) {
LOGWARNING("Listener received reject message, rejecting clients"); LOGWARNING("Listener received reject message, rejecting clients");
send_procmsg(ckp->connector, "reject"); send_proc(ckp->connector, "reject");
send_unix_msg(sockd, "rejecting"); send_unix_msg(sockd, "rejecting");
} else if (cmdmatch(buf, "reconnect")) { } else if (cmdmatch(buf, "reconnect")) {
LOGWARNING("Listener received request to send reconnect to clients"); LOGWARNING("Listener received request to send reconnect to clients");
send_procmsg(ckp->stratifier, buf); send_proc(ckp->stratifier, buf);
send_unix_msg(sockd, "reconnecting"); send_unix_msg(sockd, "reconnecting");
} else if (cmdmatch(buf, "restart")) { } else if (cmdmatch(buf, "restart")) {
LOGWARNING("Listener received restart message, attempting handover"); LOGWARNING("Listener received restart message, attempting handover");
@ -486,7 +441,7 @@ retry:
dealloc(msg); dealloc(msg);
} else if (cmdmatch(buf, "ckdbflush")) { } else if (cmdmatch(buf, "ckdbflush")) {
LOGWARNING("Received ckdb flush message"); LOGWARNING("Received ckdb flush message");
send_procmsg(ckp->stratifier, buf); send_proc(ckp->stratifier, buf);
send_unix_msg(sockd, "flushing"); send_unix_msg(sockd, "flushing");
} else { } else {
LOGINFO("Listener received unhandled message: %s", buf); LOGINFO("Listener received unhandled message: %s", buf);

10
src/connector.c

@ -1347,6 +1347,16 @@ char *connector_stats(void *data, const int runtime)
return buf; return buf;
} }
void connector_send_fd(ckpool_t *ckp, const int fdno, const int sockd)
{
cdata_t *cdata = ckp->cdata;
if (fdno > -1 && fdno < ckp->serverurls)
send_fd(cdata->serverfd[fdno], sockd);
else
LOGWARNING("Connector asked to send invalid fd %d", fdno);
}
static void connector_loop(proc_instance_t *pi, cdata_t *cdata) static void connector_loop(proc_instance_t *pi, cdata_t *cdata)
{ {
unix_msg_t *umsg = NULL; unix_msg_t *umsg = NULL;

1
src/connector.h

@ -13,6 +13,7 @@
void connector_upstream_msg(ckpool_t *ckp, char *msg); void connector_upstream_msg(ckpool_t *ckp, char *msg);
void connector_add_message(ckpool_t *ckp, json_t *val); void connector_add_message(ckpool_t *ckp, json_t *val);
char *connector_stats(void *data, const int runtime); char *connector_stats(void *data, const int runtime);
void connector_send_fd(ckpool_t *ckp, const int fdno, const int sockd);
void *connector(void *arg); void *connector(void *arg);
#endif /* CONNECTOR_H */ #endif /* CONNECTOR_H */

Loading…
Cancel
Save