revert breaks some stupid old compilers
[oscam.git] / oscam-log.c
blob246170ce1580a885f0474549b4ec0e7ba17d544e
1 #include "globals.h"
2 #include <syslog.h>
3 #include "module-anticasc.h"
4 #include "module-monitor.h"
5 #include "oscam-client.h"
6 #include "oscam-garbage.h"
7 #include "oscam-lock.h"
8 #include "oscam-log.h"
9 #include "oscam-net.h"
10 #include "oscam-string.h"
11 #include "oscam-time.h"
13 // Do not allow log_list to grow bigger than that many entries
14 #define MAX_LOG_LIST_BACKLOG 10000
16 extern char *syslog_ident;
17 extern int32_t exit_oscam;
19 char *LOG_LIST = "log_list";
20 int8_t logStarted = 0;
22 static FILE *fp;
23 static FILE *fps;
24 static LLIST *log_list;
25 static bool log_running;
26 static int log_list_queued;
27 static pthread_t log_thread;
28 static pthread_cond_t log_thread_sleep_cond;
29 static pthread_mutex_t log_thread_sleep_cond_mutex;
30 static int32_t syslog_socket = -1;
31 static struct sockaddr_in syslog_addr;
34 struct s_log
36 char *txt;
37 uint8_t header_len;
38 uint8_t header_logcount_offset;
39 uint8_t header_date_offset;
40 uint8_t header_time_offset;
41 uint8_t header_info_offset;
42 int8_t direct_log;
43 int8_t cl_typ;
44 char *cl_usr;
45 char *cl_text;
48 #define LOG_BUF_SIZE 512
50 static void switch_log(char *file, FILE **f, int32_t (*pfinit)(void))
52 if(cfg.max_log_size && file) //only 1 thread needs to switch the log; even if anticasc, statistics and normal log are running
53 //at the same time, it is ok to have the other logs switching 1 entry later
55 if(*f != NULL && ftell(*f) >= cfg.max_log_size * 1024)
57 int32_t rc;
58 char prev_log[strlen(file) + 6];
59 snprintf(prev_log, sizeof(prev_log), "%s-prev", file);
60 fprintf(*f, "switch log file\n");
61 fflush(*f);
62 fclose(*f);
63 *f = (FILE *)0;
64 rc = rename(file, prev_log);
65 if(rc != 0)
67 fprintf(stderr, "rename(%s, %s) failed (errno=%d %s)\n", file, prev_log, errno, strerror(errno));
69 else if(pfinit())
71 fprintf(stderr, "Initialisation of log file failed, continuing without logging thread %8lX. Log will be output to stdout!", (unsigned long)pthread_self());
72 cfg.logtostdout = 1;
78 void cs_reopen_log(void)
80 if(cfg.logfile)
82 if(fp)
84 fprintf(fp, "flush and re-open log file\n");
85 fflush(fp);
86 fclose(fp);
87 fp = NULL;
89 if(cs_open_logfiles())
91 fprintf(stderr, "Initialisation of log file failed, continuing without logging thread %8luX. Log will be output to stdout!", (unsigned long)pthread_self());
92 cfg.logtostdout = 1;
95 if(cfg.usrfile)
97 if(fps)
99 fprintf(fps, "flush and re-open user log file\n");
100 fflush(fps);
101 fclose(fps);
102 fps = NULL;
104 if(cs_init_statistics())
106 fprintf(stderr, "Initialisation of user log file failed, continuing without logging thread %8luX.", (unsigned long)pthread_self());
111 static void cs_write_log(char *txt, int8_t do_flush, uint8_t hdr_date_offset, uint8_t hdr_time_offset)
113 // filter out entries with leading 's' and forward to statistics
114 if(txt[hdr_date_offset] == 's')
116 if(fps)
118 switch_log(cfg.usrfile, &fps, cs_init_statistics);
119 if(fps)
121 fputs(txt + hdr_date_offset + 1, fps); // remove the leading 's' and write to file
122 if(do_flush) { fflush(fps); }
126 else
128 if(!cfg.disablelog)
130 if(fp)
132 switch_log(cfg.logfile, &fp, cs_open_logfiles); // only call the switch code if lock = 1 is specified as otherwise we are calling it internally
133 if(fp)
135 fputs(txt + hdr_date_offset, fp);
136 if(do_flush) { fflush(fp); }
139 if(cfg.logtostdout)
141 fputs(txt + hdr_time_offset, stdout);
142 if(do_flush) { fflush(stdout); }
148 static void log_list_flush(void)
150 if(logStarted == 0)
151 { return; }
153 SAFE_COND_SIGNAL_NOLOG(&log_thread_sleep_cond);
154 int32_t i = 0;
155 while(ll_count(log_list) > 0 && i < 200)
157 cs_sleepms(5);
158 ++i;
162 static void log_list_add(struct s_log *log)
164 if(logStarted == 0)
165 { return; }
167 int32_t count = ll_count(log_list);
168 log_list_queued++;
169 if(count < MAX_LOG_LIST_BACKLOG)
171 ll_append(log_list, log);
173 else // We have too much backlog
175 NULLFREE(log->txt);
176 NULLFREE(log);
177 cs_write_log("-------------> Too much data in log_list, dropping log message.\n", 1, 0, 0);
179 SAFE_COND_SIGNAL_NOLOG(&log_thread_sleep_cond);
182 static void cs_write_log_int(char *txt)
184 if(exit_oscam == 1)
186 cs_write_log(txt, 1, 0, 0);
188 else
190 char *newtxt = cs_strdup(txt);
191 if(!newtxt)
192 { return; }
193 struct s_log *log;
194 if(!cs_malloc(&log, sizeof(struct s_log)))
196 NULLFREE(newtxt);
197 return;
199 log->txt = newtxt;
200 log->header_len = 0;
201 log->direct_log = 1;
202 log_list_add(log);
206 int32_t cs_open_logfiles(void)
208 char *starttext;
209 if(logStarted) { starttext = "log switched"; }
210 else { starttext = "started"; }
211 if(!fp && cfg.logfile) //log to file
213 if((fp = fopen(cfg.logfile, "a+")) <= (FILE *)0)
215 fp = (FILE *)0;
216 fprintf(stderr, "couldn't open logfile: %s (errno %d %s)\n", cfg.logfile, errno, strerror(errno));
218 else
220 char line[80];
221 memset(line, '-', sizeof(line));
222 line[(sizeof(line) / sizeof(char)) - 1] = '\0';
223 time_t walltime = cs_time();
224 if(!cfg.disablelog)
226 char buf[28];
227 cs_ctime_r(&walltime, buf);
228 fprintf(fp, "\n%s\n>> OSCam << cardserver %s at %s%s\n", line, starttext, buf, line);
232 // according to syslog docu: calling closelog is not necessary and calling openlog multiple times is safe
233 // We use openlog to set the default syslog settings so that it's possible to allow switching syslog on and off
234 openlog(syslog_ident, LOG_NDELAY | LOG_PID, LOG_DAEMON);
235 cs_log(">> OSCam << cardserver %s, version " CS_VERSION ", build r" CS_SVN_VERSION " (" CS_TARGET ")", starttext);
237 return (fp <= (FILE *)0);
240 #if defined(WEBIF) || defined(MODULE_MONITOR)
242 static uint64_t counter = 0;
243 LLIST *log_history = NULL;
246 This function allows to reinit the in-memory loghistory with a new size.
248 void cs_reinit_loghist(uint32_t size)
250 if(cfg.loghistorylines != size)
252 cfg.loghistorylines = size;
255 #endif
257 static struct timeb log_ts;
259 static uint8_t get_log_header(char *txt, int32_t txt_size, uint8_t* hdr_logcount_offset,
260 uint8_t* hdr_date_offset, uint8_t* hdr_time_offset, uint8_t* hdr_info_offset)
262 struct s_client *cl = cur_client();
263 struct tm lt;
264 int32_t tmp;
266 cs_ftime(&log_ts);
267 time_t walltime = cs_walltime(&log_ts);
268 localtime_r(&walltime, &lt);
270 tmp = snprintf(txt, txt_size, "[LOG000]%04d/%02d/%02d %02d:%02d:%02d %08X %c ",
271 lt.tm_year + 1900,
272 lt.tm_mon + 1,
273 lt.tm_mday,
274 lt.tm_hour,
275 lt.tm_min,
276 lt.tm_sec,
277 cl ? cl->tid : 0,
278 cl ? cl->typ : ' '
281 if(tmp == 39)
283 if(hdr_logcount_offset != NULL)
285 // depends on snprintf(...) format
286 (*hdr_logcount_offset) = 4;
288 if(hdr_date_offset != NULL)
290 // depends on snprintf(...) format
291 (*hdr_date_offset) = *hdr_logcount_offset + 4;
293 if(hdr_time_offset != NULL)
295 // depends on snprintf(...) format
296 (*hdr_time_offset) = *hdr_date_offset + 11;
298 if(hdr_info_offset != NULL)
300 // depends on snprintf(...) format
301 (*hdr_info_offset) = *hdr_time_offset + 9;
304 return (uint8_t)tmp;
307 if(hdr_logcount_offset != NULL)
309 (*hdr_logcount_offset) = 0;
311 if(hdr_date_offset != NULL)
313 (*hdr_date_offset) = 0;
315 if(hdr_time_offset != NULL)
317 (*hdr_time_offset) = 0;
319 if(hdr_info_offset != NULL)
321 (*hdr_info_offset) = 0;
324 return 0;
327 static void write_to_log(char *txt, struct s_log *log, int8_t do_flush)
329 if(logStarted == 0)
330 { return; }
332 (void)log; // Prevent warning when WEBIF, MODULE_MONITOR and CS_ANTICASC are disabled
334 // anticascading messages go to their own log
335 if (!anticasc_logging(txt + log->header_date_offset))
337 if(cfg.logtosyslog)
339 syslog(LOG_INFO, "%s", txt + log->header_info_offset);
342 if (cfg.sysloghost != NULL && syslog_socket != -1)
344 char tmp[128+LOG_BUF_SIZE];
345 static char hostname[64];
346 static uint8_t have_hostname = 0;
347 time_t walltime;
348 struct tm lt;
349 char timebuf[32];
351 if(!have_hostname)
353 if(gethostname(hostname, 64) != 0)
355 cs_strncpy(hostname, "unknown", 64);
358 have_hostname = 1;
361 walltime = cs_time();
362 localtime_r(&walltime, &lt);
364 if(strftime(timebuf, 32, "%b %d %H:%M:%S", &lt) == 0)
366 cs_strncpy(timebuf, "unknown", 32);
369 snprintf(tmp, sizeof(tmp), "%s %s oscam[%u]: %s", timebuf, hostname, getpid(), txt + log->header_info_offset);
370 sendto(syslog_socket, tmp, strlen(tmp), 0, (struct sockaddr*) &syslog_addr, sizeof(syslog_addr));
374 strcat(txt, "\n");
375 cs_write_log(txt, do_flush, log->header_date_offset, log->header_time_offset);
377 #if defined(WEBIF) || defined(MODULE_MONITOR)
378 if(!exit_oscam && cfg.loghistorylines && log_history)
380 struct s_log_history *hist;
382 while((uint32_t)ll_count(log_history) >= cfg.loghistorylines)
384 hist = ll_remove_first(log_history);
385 if(hist)
387 add_garbage(hist->txt);
388 add_garbage(hist);
389 hist = NULL;
393 if(cs_malloc(&hist, sizeof(struct s_log_history)))
395 int32_t target_len = strlen(log->cl_text) + strlen(txt+log->header_date_offset) + 1;
397 if(cs_malloc(&hist->txt, sizeof(char) * (target_len + 1)))
399 hist->counter = counter++;
400 snprintf(hist->txt, target_len + 1, "%s\t%s", log->cl_text, txt + log->header_date_offset);
402 ll_append(log_history, hist);
404 else
406 NULLFREE(hist);
410 #endif
412 #if defined(MODULE_MONITOR)
413 char sbuf[16];
414 struct s_client *cl;
415 for(cl = first_client; cl ; cl = cl->next)
417 if((cl->typ == 'm') && (cl->monlvl > 0) && cl->log) //this variable is only initialized for cl->typ = 'm'
419 if(cl->monlvl < 2)
421 if(log->cl_typ != 'c' && log->cl_typ != 'm')
422 { continue; }
423 if(log->cl_usr && cl->account && strcmp(log->cl_usr, cl->account->usr))
424 { continue; }
427 if(log->header_len > 0)
429 snprintf(sbuf, sizeof(sbuf), "%03d", cl->logcounter);
430 cl->logcounter = (cl->logcounter + 1) % 1000;
431 memcpy(txt + log->header_logcount_offset, sbuf, 3);
432 monitor_send_idx(cl, txt);
434 else
436 char tmp_log[8+LOG_BUF_SIZE];
437 snprintf(tmp_log, sizeof(tmp_log), "[LOG%03d]%s", cl->logcounter, txt);
438 cl->logcounter = (cl->logcounter + 1) % 1000;
439 monitor_send_idx(cl, tmp_log);
443 #endif
446 static void write_to_log_int(char *txt, uint8_t header_len, uint8_t hdr_logcount_offset, uint8_t hdr_date_offset, uint8_t hdr_time_offset, uint8_t hdr_info_offset)
448 #if !defined(WEBIF) && !defined(MODULE_MONITOR)
449 if(cfg.disablelog) { return; }
450 #endif
451 char *newtxt = cs_strdup(txt);
452 if(!newtxt)
453 { return; }
454 struct s_log *log;
455 if(!cs_malloc(&log, sizeof(struct s_log)))
457 NULLFREE(newtxt);
458 return;
460 log->txt = newtxt;
461 log->header_len = header_len;
462 log->header_logcount_offset = hdr_logcount_offset;
463 log->header_date_offset = hdr_date_offset;
464 log->header_time_offset = hdr_time_offset;
465 log->header_info_offset = hdr_info_offset;
466 log->direct_log = 0;
467 struct s_client *cl = cur_client();
468 log->cl_usr = "";
469 if(!cl)
471 log->cl_text = "undef";
472 log->cl_typ = ' ';
474 else
476 switch(cl->typ)
478 case 'c':
479 case 'm':
480 if(cl->account)
482 log->cl_text = cl->account->usr;
483 log->cl_usr = cl->account->usr;
485 else { log->cl_text = ""; }
486 break;
487 case 'p':
488 case 'r':
489 log->cl_text = cl->reader ? cl->reader->label : "";
490 break;
491 default:
492 log->cl_text = "server";
493 break;
495 log->cl_typ = cl->typ;
498 if(exit_oscam == 1 || cfg.disablelog) //Exit or log disabled. if disabled, just display on webif/monitor
500 char buf[LOG_BUF_SIZE];
501 cs_strncpy(buf, log->txt, LOG_BUF_SIZE);
502 write_to_log(buf, log, 1);
503 NULLFREE(log->txt);
504 NULLFREE(log);
506 else
507 { log_list_add(log); }
510 static pthread_mutex_t log_mutex;
511 static char log_txt[LOG_BUF_SIZE];
512 static char dupl[LOG_BUF_SIZE / 4];
513 static char last_log_txt[LOG_BUF_SIZE];
514 static struct timeb last_log_ts;
515 static unsigned int last_log_duplicates;
517 static void __cs_log_check_duplicates(uint8_t hdr_len, uint8_t hdr_logcount_offset, uint8_t hdr_date_offset, uint8_t hdr_time_offset, uint8_t hdr_info_offset)
519 bool repeated_line = strcmp(last_log_txt, log_txt + hdr_len) == 0;
520 if (last_log_duplicates > 0)
522 if (!cs_valid_time(&last_log_ts)) // Must be initialized once
523 last_log_ts = log_ts;
524 // Report duplicated lines when the new log line is different
525 // than the old or 60 seconds have passed.
526 int64_t gone = comp_timeb(&log_ts, &last_log_ts);
527 if (!repeated_line || gone >= 60*1000)
529 uint8_t dupl_hdr_logcount_offset = 0, dupl_hdr_date_offset = 0, dupl_hdr_time_offset = 0, dupl_hdr_info_offset = 0;
530 uint8_t dupl_header_len = get_log_header(dupl, sizeof(dupl), &dupl_hdr_logcount_offset, &dupl_hdr_date_offset, &dupl_hdr_time_offset, &dupl_hdr_info_offset);
531 snprintf(dupl + dupl_header_len - 1, sizeof(dupl) - dupl_header_len, " (-) -- Skipped %u duplicated log lines --", last_log_duplicates);
532 write_to_log_int(dupl, dupl_header_len, dupl_hdr_logcount_offset, dupl_hdr_date_offset, dupl_hdr_time_offset, dupl_hdr_info_offset);
533 last_log_duplicates = 0;
534 last_log_ts = log_ts;
537 if (!repeated_line)
539 memcpy(last_log_txt, log_txt + hdr_len, LOG_BUF_SIZE - hdr_len);
540 write_to_log_int(log_txt, hdr_len, hdr_logcount_offset, hdr_date_offset, hdr_time_offset, hdr_info_offset);
541 } else {
542 last_log_duplicates++;
546 #define __init_log_prefix(fmt) \
547 uint8_t hdr_logcount_offset = 0, hdr_date_offset = 0, hdr_time_offset = 0, hdr_info_offset = 0; \
548 uint8_t hdr_len = get_log_header(log_txt, sizeof(log_txt), &hdr_logcount_offset, &hdr_date_offset, &hdr_time_offset, &hdr_info_offset); \
549 int32_t log_prefix_len = 0; \
550 do { \
551 if (log_prefix) { \
552 char _lp[16]; \
553 snprintf(_lp, sizeof(_lp), "(%s)", log_prefix); \
554 log_prefix_len = snprintf(log_txt + hdr_len, sizeof(log_txt) - hdr_len, fmt, _lp); \
556 } while(0)
558 #define __do_log() \
559 do { \
560 va_list params; \
561 va_start(params, fmt); \
562 __init_log_prefix("%10s "); \
563 vsnprintf(log_txt + hdr_len + log_prefix_len, sizeof(log_txt) - (hdr_len + log_prefix_len), fmt, params); \
564 va_end(params); \
565 if (cfg.logduplicatelines) \
567 memcpy(last_log_txt, log_txt + hdr_len, LOG_BUF_SIZE - hdr_len); \
568 write_to_log_int(log_txt, hdr_len, hdr_logcount_offset, hdr_date_offset, hdr_time_offset, hdr_info_offset); \
569 } else { \
570 __cs_log_check_duplicates(hdr_len, hdr_logcount_offset, hdr_date_offset, hdr_time_offset, hdr_info_offset); \
572 } while(0)
574 void cs_log_txt(const char *log_prefix, const char *fmt, ...)
576 if(logStarted == 0)
577 { return; }
579 SAFE_MUTEX_LOCK_NOLOG(&log_mutex);
580 __do_log();
581 SAFE_MUTEX_UNLOCK_NOLOG(&log_mutex);
584 void cs_log_hex(const char *log_prefix, const uint8_t *buf, int32_t n, const char *fmt, ...)
586 if(logStarted == 0)
587 { return; }
589 SAFE_MUTEX_LOCK_NOLOG(&log_mutex);
590 __do_log();
591 if(buf)
593 int32_t i;
594 __init_log_prefix("%10s ");
595 for(i = 0; i < n; i += 16)
597 cs_hexdump(1, buf + i, (n - i > 16) ? 16 : n - i, log_txt + hdr_len + log_prefix_len, sizeof(log_txt) - (hdr_len + log_prefix_len));
598 write_to_log_int(log_txt, hdr_len, hdr_logcount_offset, hdr_date_offset, hdr_time_offset, hdr_info_offset);
601 SAFE_MUTEX_UNLOCK_NOLOG(&log_mutex);
604 static void cs_close_log(void)
606 log_list_flush();
607 if(fp)
609 fclose(fp);
610 fp = (FILE *)0;
614 int32_t cs_init_statistics(void)
616 if((!fps) && (cfg.usrfile != NULL))
618 if((fps = fopen(cfg.usrfile, "a+")) <= (FILE *)0)
620 fps = (FILE *)0;
621 cs_log("couldn't open statistics file: %s", cfg.usrfile);
624 return (fps <= (FILE *)0);
627 void cs_statistics(struct s_client *client)
629 if(!cfg.disableuserfile)
631 struct tm lt;
632 char buf[LOG_BUF_SIZE];
634 float cwps;
636 time_t walltime = cs_time();
637 localtime_r(&walltime, &lt);
638 if(client->cwfound + client->cwnot > 0)
640 cwps = client->last - client->login;
641 cwps /= client->cwfound + client->cwnot;
643 else
644 { cwps = 0; }
646 char channame[CS_SERVICENAME_SIZE];
647 get_servicename(client, client->last_srvid, client->last_provid, client->last_caid, channame, sizeof(channame));
649 int32_t lsec;
650 if((client->last_caid == NO_CAID_VALUE) && (client->last_srvid == NO_SRVID_VALUE))
651 { lsec = client->last - client->login; } //client leave calc total duration
652 else
653 { lsec = client->last - client->lastswitch; }
655 int32_t secs = 0, fullmins = 0, mins = 0, fullhours = 0;
657 if((lsec > 0) && (lsec < 1000000))
659 secs = lsec % 60;
660 if(lsec > 60)
662 fullmins = lsec / 60;
663 mins = fullmins % 60;
664 if(fullmins > 60)
666 fullhours = fullmins / 60;
671 /* statistics entry start with 's' to filter it out on other end of pipe
672 * so we can use the same Pipe as Log
674 snprintf(buf, sizeof(buf), "s%02d.%02d.%02d %02d:%02d:%02d %3.1f %s %s %d %d %d %d %d %d %d %ld %ld %02d:%02d:%02d %s %04X@%06X:%04X %s\n",
675 lt.tm_mday, lt.tm_mon + 1, lt.tm_year % 100,
676 lt.tm_hour, lt.tm_min, lt.tm_sec, cwps,
677 client->account->usr,
678 cs_inet_ntoa(client->ip),
679 client->port,
680 client->cwfound,
681 client->cwcache,
682 client->cwnot,
683 client->cwignored,
684 client->cwtout,
685 client->cwtun,
686 client->login,
687 client->last,
688 fullhours, mins, secs,
689 get_module(client)->desc,
690 client->last_caid,
691 client->last_provid,
692 client->last_srvid,
693 channame);
695 cs_write_log_int(buf);
699 void log_list_thread(void)
701 char buf[LOG_BUF_SIZE];
702 log_running = 1;
703 set_thread_name(__func__);
706 log_list_queued = 0;
707 LL_ITER it = ll_iter_create(log_list);
708 struct s_log *log;
709 while((log = ll_iter_next_remove(&it)))
711 int8_t do_flush = ll_count(log_list) == 0; //flush on writing last element
713 cs_strncpy(buf, log->txt, LOG_BUF_SIZE);
714 if(log->direct_log)
715 { cs_write_log(buf, do_flush, log->header_date_offset, log->header_time_offset); }
716 else
717 { write_to_log(buf, log, do_flush); }
718 NULLFREE(log->txt);
719 NULLFREE(log);
721 if(!log_list_queued) // The list is empty, sleep until new data comes in and we are woken up
722 sleepms_on_cond(__func__, &log_thread_sleep_cond_mutex, &log_thread_sleep_cond, 60 * 1000);
724 while(log_running);
725 ll_destroy(&log_list);
728 static void init_syslog_socket(void)
730 if(cfg.sysloghost != NULL && syslog_socket == -1)
732 IN_ADDR_T in_addr;
734 if ((syslog_socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1)
736 perror("Socket create error!");
739 memset((char *) &syslog_addr, 0, sizeof(syslog_addr));
740 syslog_addr.sin_family = AF_INET;
741 syslog_addr.sin_port = htons(cfg.syslogport);
742 cs_resolve(cfg.sysloghost, &in_addr, NULL, NULL);
743 SIN_GET_ADDR(syslog_addr) = in_addr;
747 int32_t cs_init_log(void)
749 if(logStarted == 0)
751 init_syslog_socket();
752 SAFE_MUTEX_INIT_NOLOG(&log_mutex, NULL);
754 cs_pthread_cond_init_nolog(__func__, &log_thread_sleep_cond_mutex, &log_thread_sleep_cond);
756 #if defined(WEBIF) || defined(MODULE_MONITOR)
757 log_history = ll_create("log history");
758 #endif
760 log_list = ll_create(LOG_LIST);
762 int32_t ret = start_thread_nolog("logging", (void *)&log_list_thread, NULL, &log_thread, 0, 1);
763 if(ret)
765 cs_exit(1);
768 logStarted = 1;
770 int32_t rc = 0;
771 if(!cfg.disablelog) { rc = cs_open_logfiles(); }
772 logStarted = 1;
774 if(cfg.initial_debuglevel > 0)
776 cs_dblevel = cfg.initial_debuglevel;
777 cs_log("debug_level=%d", cs_dblevel);
780 return rc;
783 void cs_disable_log(int8_t disabled)
785 if(cfg.disablelog != disabled)
787 if(disabled && logStarted)
789 cs_log("Stopping log...");
790 log_list_flush();
792 cfg.disablelog = disabled;
793 if(disabled)
795 if(logStarted)
797 if(syslog_socket != -1)
799 close(syslog_socket);
800 syslog_socket = -1;
803 cs_sleepms(20);
804 cs_close_log();
807 else
809 init_syslog_socket();
810 cs_open_logfiles();
815 void log_free(void)
817 if(syslog_socket != -1)
819 close(syslog_socket);
820 syslog_socket = -1;
822 cs_close_log();
823 log_running = 0;
824 SAFE_COND_SIGNAL_NOLOG(&log_thread_sleep_cond);
825 SAFE_THREAD_JOIN_NOLOG(log_thread, NULL);