Log: remove trailing \n, added log description

This commit is contained in:
Olof hagsand 2024-05-09 16:59:31 +02:00
parent 9738345f82
commit 488a532dec
3 changed files with 66 additions and 59 deletions

View file

@ -1912,8 +1912,9 @@ from_client_msg(clixon_handle h,
return retval;// -1 here terminates backend return retval;// -1 here terminates backend
} }
/*! An internal clicon message has arrived from a client. Receive and dispatch. /*! Internal clixon message has arrived from a client. Receive and dispatch.
* *
* Internal clixon is NETCONF 1.1 chunked encoding
* @param[in] s Socket where message arrived. read from this. * @param[in] s Socket where message arrived. read from this.
* @param[in] arg Client entry (from). * @param[in] arg Client entry (from).
* @retval 0 OK * @retval 0 OK
@ -1938,7 +1939,7 @@ from_client(int s,
} }
if (ce_client_descr(ce, &cbce) < 0) if (ce_client_descr(ce, &cbce) < 0)
goto done; goto done;
if (clixon_msg_rcv11(s, NULL, 0, &cb, &eof) < 0) if (clixon_msg_rcv11(s, cbuf_get(cbce), 0, &cb, &eof) < 0) /* XXX why not descr here? */
goto done; goto done;
if (eof){ if (eof){
backend_client_rm(h, ce); backend_client_rm(h, ce);

View file

@ -1,4 +1,4 @@
/* /*
* *
***** BEGIN LICENSE BLOCK ***** ***** BEGIN LICENSE BLOCK *****
@ -299,6 +299,9 @@ int
clixon_log_str(int level, clixon_log_str(int level,
char *msg) char *msg)
{ {
/* Remove trailing CR if any */
if (strlen(msg) && msg[strlen(msg)-1] == '\n')
msg[strlen(msg)-1] = '\0';
if (_log_flags & CLIXON_LOG_SYSLOG) if (_log_flags & CLIXON_LOG_SYSLOG)
syslog(LOG_MAKEPRI(LOG_USER, level), "%s", msg); // XXX this may block syslog(LOG_MAKEPRI(LOG_USER, level), "%s", msg); // XXX this may block
/* syslog makes own filtering, we do it here: /* syslog makes own filtering, we do it here:

View file

@ -395,24 +395,8 @@ clixon_msg_rcv10(int s,
*eof = 0; *eof = 0;
memset(buf, 0, sizeof(buf)); memset(buf, 0, sizeof(buf));
while (1){ while (1){
#if 1
if ((len = netconf_input_read2(s, buf, sizeof(buf), eof)) < 0) if ((len = netconf_input_read2(s, buf, sizeof(buf), eof)) < 0)
goto done; goto done;
#else
if ((len = read(s, buf, sizeof(buf))) < 0){
if (errno == ECONNRESET)
len = 0; /* emulate EOF */
else{
clixon_log(NULL, LOG_ERR, "%s: read: %s errno:%d", __FUNCTION__, strerror(errno), errno);
goto done;
}
} /* read */
if (len == 0){ /* EOF */
*eof = 1;
close(s);
goto ok;
}
#endif
for (i=0; i<len; i++){ for (i=0; i<len; i++){
if (buf[i] == 0) if (buf[i] == 0)
continue; /* Skip NULL chars (eg from terminals) */ continue; /* Skip NULL chars (eg from terminals) */
@ -433,10 +417,18 @@ clixon_msg_rcv10(int s,
break; /* No data to read */ break; /* No data to read */
} /* while */ } /* while */
ok: ok:
if (*eof){
if (descr)
clixon_debug(CLIXON_DBG_MSG, "Recv [%s]: EOF", descr);
else
clixon_debug(CLIXON_DBG_MSG, "Recv: EOF");
}
else {
if (descr) if (descr)
clixon_debug(CLIXON_DBG_MSG, "Recv [%s]: %s", descr, cbuf_get(cb)); clixon_debug(CLIXON_DBG_MSG, "Recv [%s]: %s", descr, cbuf_get(cb));
else else
clixon_debug(CLIXON_DBG_MSG, "Recv: %s", cbuf_get(cb)); clixon_debug(CLIXON_DBG_MSG, "Recv: %s", cbuf_get(cb));
}
retval = 0; retval = 0;
done: done:
clixon_debug(CLIXON_DBG_MSG | CLIXON_DBG_DETAIL, "done"); clixon_debug(CLIXON_DBG_MSG | CLIXON_DBG_DETAIL, "done");
@ -537,7 +529,7 @@ atomicio_sig_handler(int arg)
* @retval 0 OK (check eof) * @retval 0 OK (check eof)
* @retval -1 Error * @retval -1 Error
* @see netconf_input_cb() * @see netconf_input_cb()
* @note only NETCONF version 1.0 EOM framing * @see clixon_msg_rcv10 For EOM framing
*/ */
int int
clixon_msg_rcv11(int s, clixon_msg_rcv11(int s,
@ -596,7 +588,18 @@ clixon_msg_rcv11(int s,
continue; continue;
} }
} }
if (*eof ){
if (descr)
clixon_debug(CLIXON_DBG_MSG, "Recv [%s]: EOF", descr);
else
clixon_debug(CLIXON_DBG_MSG, "Recv: EOF");
}
else {
if (descr)
clixon_debug(CLIXON_DBG_MSG, "Recv [%s]: %s", descr, cbuf_get(cbmsg));
else
clixon_debug(CLIXON_DBG_MSG, "Recv: %s", cbuf_get(cbmsg)); clixon_debug(CLIXON_DBG_MSG, "Recv: %s", cbuf_get(cbmsg));
}
if (cb){ if (cb){
*cb = cbmsg; *cb = cbmsg;
cbmsg = NULL; cbmsg = NULL;