-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsyslog_wrapper.h
More file actions
35 lines (27 loc) · 1.16 KB
/
syslog_wrapper.h
File metadata and controls
35 lines (27 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#ifndef SYSLOG_WRAPPER_H
#define SYSLOG_WRAPPER_H
#include <syslog.h>
#include <string.h>
//cgo currently cannot handle variable arguments list, so we have to use a wrapper
void go_syslog(int facility, const char* msg) {
syslog(facility,"%s",msg);
}
//As said in openlog man:
//========================================================
//Please note that the string pointer ident will be retained internally by the Syslog routines.
//You must not free the memory that ident points to.
//========================================================
//
//Because of that we store ident string in static variable and overwrite it on every
//Openlog call
void go_openlog(const char* ident, int priority, int options) {
#define max_length 1001 //extra char for null termination
static char _current_ident[max_length] = { 0 };
//Copy ident string to static array. Extra 1 substraction is for those
//cases when size of ident is larger than max_length-1. In that case
//string would be unterminated, but having extra zero in the end
//guarantees string termination.
strncpy(_current_ident,ident,max_length-1);
openlog(_current_ident,priority,options);
}
#endif