introduce test-mode (netstring codec disabled) for debugging during development
This commit is contained in:
parent
7d82f677f5
commit
d383a66530
@ -76,6 +76,7 @@
|
|||||||
#define CFG_SECTION_GLOBAL "global"
|
#define CFG_SECTION_GLOBAL "global"
|
||||||
#define CFG_NAME_ADDRESS "address"
|
#define CFG_NAME_ADDRESS "address"
|
||||||
#define CFG_NAME_PORT "port"
|
#define CFG_NAME_PORT "port"
|
||||||
|
#define CFG_NETSTRING_DISABLED "netstring_disabled"
|
||||||
|
|
||||||
#define DEFAULT_PORT "8888"
|
#define DEFAULT_PORT "8888"
|
||||||
|
|
||||||
@ -108,6 +109,8 @@ count_t thread_counter;
|
|||||||
|
|
||||||
cfg_t *cfg;
|
cfg_t *cfg;
|
||||||
|
|
||||||
|
int netstring_disabled = 0;
|
||||||
|
|
||||||
#if ENABLE_STATS==1
|
#if ENABLE_STATS==1
|
||||||
void * statser(void * arg) {
|
void * statser(void * arg) {
|
||||||
int stdout_nice = atoi(findcfgx(cfg, "stats", "stdout_nice", "0"));
|
int stdout_nice = atoi(findcfgx(cfg, "stats", "stdout_nice", "0"));
|
||||||
@ -190,22 +193,29 @@ void * networker(void * arg) {
|
|||||||
else
|
else
|
||||||
buffer[cnt] = '\0';
|
buffer[cnt] = '\0';
|
||||||
|
|
||||||
len = strtol(buffer, &input, 10);
|
dispatcher_result = 0;
|
||||||
if ((0 == len) && (buffer == input)) {
|
if (netstring_disabled) {
|
||||||
syslog(LOG_DEBUG, "networker: netstring unparsable, no length found: %s", buffer);
|
input = buffer;
|
||||||
dispatcher_result = SMM_NETSTRING_UNPARSABLE;
|
|
||||||
} else if (*input++ != ':') {
|
|
||||||
syslog(LOG_DEBUG, "networker: netstring unparsable, no colon found: %s", buffer);
|
|
||||||
dispatcher_result = SMM_NETSTRING_UNPARSABLE;
|
|
||||||
} else if (strlen(input)-1 != len) {
|
|
||||||
syslog(LOG_DEBUG, "networker: netstring unparsable, length does not match: %s", buffer);
|
|
||||||
dispatcher_result = SMM_NETSTRING_UNPARSABLE;
|
|
||||||
} else if (input[strlen(input)-1] != ',') {
|
|
||||||
syslog(LOG_DEBUG, "networker: netstring unparsable, no terminating comma: %s", buffer);
|
|
||||||
dispatcher_result = SMM_NETSTRING_UNPARSABLE;
|
|
||||||
} else {
|
} else {
|
||||||
input[strlen(input)-1] = '\0'; /* strip off the comma */
|
len = strtol(buffer, &input, 10);
|
||||||
|
if ((0 == len) && (buffer == input)) {
|
||||||
|
syslog(LOG_DEBUG, "networker: netstring unparsable, no length found: %s", buffer);
|
||||||
|
dispatcher_result = SMM_NETSTRING_UNPARSABLE;
|
||||||
|
} else if (*input++ != ':') {
|
||||||
|
syslog(LOG_DEBUG, "networker: netstring unparsable, no colon found: %s", buffer);
|
||||||
|
dispatcher_result = SMM_NETSTRING_UNPARSABLE;
|
||||||
|
} else if (strlen(input)-1 != len) {
|
||||||
|
syslog(LOG_DEBUG, "networker: netstring unparsable, length does not match: %s", buffer);
|
||||||
|
dispatcher_result = SMM_NETSTRING_UNPARSABLE;
|
||||||
|
} else if (input[strlen(input)-1] != ',') {
|
||||||
|
syslog(LOG_DEBUG, "networker: netstring unparsable, no terminating comma: %s", buffer);
|
||||||
|
dispatcher_result = SMM_NETSTRING_UNPARSABLE;
|
||||||
|
} else {
|
||||||
|
input[strlen(input)-1] = '\0'; /* strip off the comma */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!dispatcher_result) {
|
||||||
answer[0] = '\0';
|
answer[0] = '\0';
|
||||||
dispatcher_result = containers_dispatcher(container_handle, input, answer);
|
dispatcher_result = containers_dispatcher(container_handle, input, answer);
|
||||||
syslog(LOG_DEBUG, "networker: dispatcher result: %d, answer: %s", dispatcher_result, answer);
|
syslog(LOG_DEBUG, "networker: dispatcher result: %d, answer: %s", dispatcher_result, answer);
|
||||||
@ -224,11 +234,15 @@ void * networker(void * arg) {
|
|||||||
if (NULL == answer_ptr)
|
if (NULL == answer_ptr)
|
||||||
answer_ptr = answer;
|
answer_ptr = answer;
|
||||||
|
|
||||||
snprintf(output, OUTPUT_BUFSIZE, "%d:%s%s%s,",
|
if (netstring_disabled) {
|
||||||
strlen(result_text) + strlen(answer_ptr) + ((strlen(answer_ptr) > 0) ? 1 : 0),
|
snprintf(output, OUTPUT_BUFSIZE, "%s\n", answer_ptr);
|
||||||
result_text,
|
} else {
|
||||||
(strlen(answer_ptr) > 0) ? " " : "",
|
snprintf(output, OUTPUT_BUFSIZE, "%d:%s%s%s,",
|
||||||
answer_ptr);
|
strlen(result_text) + strlen(answer_ptr) + ((strlen(answer_ptr) > 0) ? 1 : 0),
|
||||||
|
result_text,
|
||||||
|
(strlen(answer_ptr) > 0) ? " " : "",
|
||||||
|
answer_ptr);
|
||||||
|
}
|
||||||
|
|
||||||
safe_write(thread->clientSock, output, strlen(output));
|
safe_write(thread->clientSock, output, strlen(output));
|
||||||
}
|
}
|
||||||
@ -259,6 +273,9 @@ int server() {
|
|||||||
|
|
||||||
char *cfg_address, *cfg_port;
|
char *cfg_address, *cfg_port;
|
||||||
|
|
||||||
|
netstring_disabled = atoi(findcfgx(cfg, CFG_SECTION_GLOBAL, CFG_NETSTRING_DISABLED, "0"));
|
||||||
|
|
||||||
|
|
||||||
serverSock = socket(AF_INET, SOCK_STREAM, 0);
|
serverSock = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
if (-1 == serverSock) {
|
if (-1 == serverSock) {
|
||||||
syslog(LOG_ERR, "server: failure when creating server socket");
|
syslog(LOG_ERR, "server: failure when creating server socket");
|
||||||
|
@ -9,6 +9,10 @@ plugins = verifier
|
|||||||
enable_stats = 0
|
enable_stats = 0
|
||||||
enable_snmp = 1
|
enable_snmp = 1
|
||||||
|
|
||||||
|
; disables the netstring codec, only for debugging in the development
|
||||||
|
; phase, sendmail is unable to talk to smmapd if the codec is disabled
|
||||||
|
; netstring_disabled = 1
|
||||||
|
|
||||||
[snmp]
|
[snmp]
|
||||||
agentx_socket = /var/agentx/master
|
agentx_socket = /var/agentx/master
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user