summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cookie.c51
-rw-r--r--cookie.h6
-rw-r--r--curvetun.c1
-rw-r--r--curvetun/Makefile1
-rw-r--r--xio.c45
-rw-r--r--xio.h1
6 files changed, 59 insertions, 46 deletions
diff --git a/cookie.c b/cookie.c
new file mode 100644
index 0000000..9ee1ac6
--- /dev/null
+++ b/cookie.c
@@ -0,0 +1,51 @@
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <string.h>
+#include <syslog.h>
+
+#include "cookie.h"
+
+static char const *priov[] = {
+ [LOG_EMERG] = "EMERG:",
+ [LOG_ALERT] = "ALERT:",
+ [LOG_CRIT] = "CRIT:",
+ [LOG_ERR] = "ERR:",
+ [LOG_WARNING] = "WARNING:",
+ [LOG_NOTICE] = "NOTICE:",
+ [LOG_INFO] = "INFO:",
+ [LOG_DEBUG] = "DEBUG:",
+};
+
+static ssize_t cookie_writer(void *cookie, char const *data, size_t leng)
+{
+ int prio = LOG_DEBUG, len;
+
+ do {
+ len = strlen(priov[prio]);
+ } while (memcmp(data, priov[prio], len) && --prio >= 0);
+
+ if (prio < 0) {
+ prio = LOG_INFO;
+ } else {
+ data += len;
+ leng -= len;
+ }
+
+ while (*data == ' ') {
+ ++data;
+ --leng;
+ }
+
+ syslog(prio, "%.*s", (int) leng, data);
+
+ return leng;
+}
+
+static cookie_io_functions_t cookie_log = {
+ .write = cookie_writer,
+};
+
+void to_std_log(FILE **fp)
+{
+ setvbuf(*fp = fopencookie(NULL, "w", cookie_log), NULL, _IOLBF, 0);
+}
diff --git a/cookie.h b/cookie.h
new file mode 100644
index 0000000..14f1801
--- /dev/null
+++ b/cookie.h
@@ -0,0 +1,6 @@
+#ifndef COOKIE_H
+#define COOKIE_H
+
+extern void to_std_log(FILE **fp);
+
+#endif /* COOKIE_H */
diff --git a/curvetun.c b/curvetun.c
index b2cc9b5..d85e6ad 100644
--- a/curvetun.c
+++ b/curvetun.c
@@ -28,6 +28,7 @@
#include "xutils.h"
#include "die.h"
#include "str.h"
+#include "cookie.h"
#include "xmalloc.h"
#include "curvetun.h"
#include "curve.h"
diff --git a/curvetun/Makefile b/curvetun/Makefile
index ce91dc2..62f7a51 100644
--- a/curvetun/Makefile
+++ b/curvetun/Makefile
@@ -12,6 +12,7 @@ curvetun-objs = xmalloc.o \
hash.o \
rnd.o \
curve.o \
+ cookie.o \
cpusched.o \
ct_usermgmt.o \
ct_servmgmt.o \
diff --git a/xio.c b/xio.c
index da17206..efc4ed4 100644
--- a/xio.c
+++ b/xio.c
@@ -157,48 +157,3 @@ ssize_t write_exact(int fd, void *buf, size_t len, int mayexit)
return num;
}
-
-static char const *priov[] = {
- [LOG_EMERG] = "EMERG:",
- [LOG_ALERT] = "ALERT:",
- [LOG_CRIT] = "CRIT:",
- [LOG_ERR] = "ERR:",
- [LOG_WARNING] = "WARNING:",
- [LOG_NOTICE] = "NOTICE:",
- [LOG_INFO] = "INFO:",
- [LOG_DEBUG] = "DEBUG:",
-};
-
-static ssize_t cookie_writer(void *cookie, char const *data, size_t leng)
-{
- int prio = LOG_DEBUG, len;
-
- do {
- len = strlen(priov[prio]);
- } while (memcmp(data, priov[prio], len) && --prio >= 0);
-
- if (prio < 0) {
- prio = LOG_INFO;
- } else {
- data += len;
- leng -= len;
- }
-
- while (*data == ' ') {
- ++data;
- --leng;
- }
-
- syslog(prio, "%.*s", (int) leng, data);
-
- return leng;
-}
-
-static cookie_io_functions_t cookie_log = {
- .write = cookie_writer,
-};
-
-void to_std_log(FILE **fp)
-{
- setvbuf(*fp = fopencookie(NULL, "w", cookie_log), NULL, _IOLBF, 0);
-}
diff --git a/xio.h b/xio.h
index b02e7a9..8a8f58a 100644
--- a/xio.h
+++ b/xio.h
@@ -16,6 +16,5 @@ extern ssize_t read_or_die(int fd, void *buf, size_t count);
extern ssize_t write_or_die(int fd, const void *buf, size_t count);
extern ssize_t read_exact(int fd, void *buf, size_t len, int mayexit);
extern ssize_t write_exact(int fd, void *buf, size_t len, int mayexit);
-extern void to_std_log(FILE **fp);
#endif /* XIO_H */