ubox/logd: free ubus context on exit
[project/ubox.git] / log / syslog.c
index d0b528d..ac4f1ae 100644 (file)
@@ -30,8 +30,6 @@
 #include <libubox/usock.h>
 #include <libubox/ustream.h>
 
-#include <ubusmsg.h>
-
 #include "syslog.h"
 
 #define LOG_DEFAULT_SIZE       (16 * 1024)
@@ -68,7 +66,7 @@ log_add(char *buf, int size, int source)
 
        /* bounce out if we don't have init'ed yet (regmatch etc will blow) */
        if (!log) {
-               fprintf(stderr, buf);
+               fprintf(stderr, "%s", buf);
                return;
        }
 
@@ -205,7 +203,7 @@ syslog_open(void)
        int fd;
 
        unlink(log_dev);
-       fd = usock(USOCK_UNIX | USOCK_UDP |  USOCK_SERVER | USOCK_NONBLOCK, log_dev, NULL);
+       fd = usock(USOCK_UNIX | USOCK_UDP | USOCK_SERVER | USOCK_NONBLOCK, log_dev, NULL);
        if (fd < 0) {
                fprintf(stderr,"Failed to open %s\n", log_dev);
                return -1;
@@ -281,10 +279,6 @@ log_init(int _log_size)
        if (_log_size > 0)
                log_size = _log_size;
 
-       /* reserve 512 bytes for protocol overhead */
-       if (log_size > (UBUS_MAX_MSGLEN -  512))
-               log_size = UBUS_MAX_MSGLEN - 512;
-
        regcomp(&pat_prio, "^<([0-9]*)>(.*)", REG_EXTENDED);
        regcomp(&pat_tstamp, "^\[[ 0]*([0-9]*).([0-9]*)] (.*)", REG_EXTENDED);
 
@@ -305,4 +299,7 @@ log_shutdown(void)
        ustream_free(&klog.stream);
        close(slog.fd.fd);
        close(klog.fd.fd);
+       free(log);
+       regfree(&pat_prio);
+       regfree(&pat_tstamp);
 }