ring_tx: handle EINTR from sendto
[netsniff-ng-new.git] / cookie.c
blob567f5398deb11fa484ba4dbc7d75a0d96c30bd8e
1 #define _GNU_SOURCE
2 #include <stdio.h>
3 #include <string.h>
4 #include <syslog.h>
5 #include <sys/types.h>
7 #include "cookie.h"
9 static char const *priov[] = {
10 [LOG_EMERG] = "EMERG:",
11 [LOG_ALERT] = "ALERT:",
12 [LOG_CRIT] = "CRIT:",
13 [LOG_ERR] = "ERR:",
14 [LOG_WARNING] = "WARNING:",
15 [LOG_NOTICE] = "NOTICE:",
16 [LOG_INFO] = "INFO:",
17 [LOG_DEBUG] = "DEBUG:",
20 static ssize_t cookie_writer(void *cookie, char const *data, size_t leng)
22 int prio = LOG_DEBUG, len;
24 do {
25 len = strlen(priov[prio]);
26 } while (memcmp(data, priov[prio], len) && --prio >= 0);
28 if (prio < 0) {
29 prio = LOG_INFO;
30 } else {
31 data += len;
32 leng -= len;
35 while (*data == ' ') {
36 ++data;
37 --leng;
40 syslog(prio, "%.*s", (int) leng, data);
42 return leng;
45 static cookie_io_functions_t cookie_log = {
46 .write = cookie_writer,
49 void to_std_log(FILE **fp)
51 setvbuf(*fp = fopencookie(NULL, "w", cookie_log), NULL, _IOLBF, 0);