From 8fac1e425eca9487dda5465b74de84a2df8edddd Mon Sep 17 00:00:00 2001 From: Sebastian Schmelzer Date: Thu, 1 Sep 2011 19:27:46 +0200 Subject: fix message loss --- customdhcpcd/src/logwriter.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'customdhcpcd/src/logwriter.c') diff --git a/customdhcpcd/src/logwriter.c b/customdhcpcd/src/logwriter.c index 378d805..6a04821 100644 --- a/customdhcpcd/src/logwriter.c +++ b/customdhcpcd/src/logwriter.c @@ -18,6 +18,8 @@ #include "logwriter.h" #include "status.h" +#include "../../common/fbgui.h" // for constants + /*sockets for the logger and the qt-reader */ int sockfd, ns; int retval = -1; @@ -80,9 +82,11 @@ void logToQt(char * status, char * substatus, char * msg) { void sendToQt(log_msg * msg) { int n = -1; int t; + int ret; const char *tpl = "%s;%d;%d;%s\n"; - char *outbuf; - char ack[8]; + char outbuf[DHCP_MESSAGE_SIZE]; + char ack[ACK_SIZE]; + /* size_t outbuf_size = sizeof(char) * 4 + // ";" *3 + newline sizeof(int) * 2 + // status, substatus sizeof(msg->device) + // devicename @@ -92,10 +96,18 @@ void sendToQt(log_msg * msg) { snprintf(outbuf, sizeof(char) * 3 + sizeof(int) * 2 + sizeof(msg->device) + sizeof(msg->msg), tpl, msg->device, msg->status, msg->substatus, msg->msg); + */ + memset(outbuf, '\0', DHCP_MESSAGE_SIZE); + ret = snprintf(outbuf, DHCP_MESSAGE_SIZE, tpl, msg->device, msg->status, msg->substatus, + msg->msg); + if (ret < 1) { + syslog(LOG_INFO, "[fbgui] ERROR filling message buffer"); + return; + } if (outbuf != NULL) { - n = send(sockfd, outbuf, outbuf_size, 0); + n = send(sockfd, outbuf, DHCP_MESSAGE_SIZE, 0); } - free(outbuf); + //free(outbuf); syslog(LOG_INFO, "[fbgui] INFO writing to socket: [%d:%d] %s (%s)", msg->status, msg->substatus, msg->msg, msg->device); // fflush(sockfd); @@ -104,8 +116,8 @@ void sendToQt(log_msg * msg) { msg->status, msg->substatus, msg->msg, msg->device); // fprintf(stdout, "ERROR writing to socket: %s", msg); } - memset(ack,0,sizeof(ack)); - if ((t = recv(sockfd, ack, sizeof(ack), 0)) > 0) { + memset(ack,0,ACK_SIZE); + if ((t = recv(sockfd, ack, ACK_SIZE, 0)) > 0) { syslog(LOG_ERR, "[fbgui] recv ack echo> %s", ack); printf("received: %s\n", ack); } else { -- cgit v1.2.3-55-g7522