Changeset View
Changeset View
Standalone View
Standalone View
syslogd.c
Show First 20 Lines • Show All 400 Lines • ▼ Show 20 Lines | |||||
static int UniquePriority; /* Only log specified priority? */ | static int UniquePriority; /* Only log specified priority? */ | ||||
static int LogFacPri; /* Put facility and priority in log message: */ | static int LogFacPri; /* Put facility and priority in log message: */ | ||||
/* 0=no, 1=numeric, 2=names */ | /* 0=no, 1=numeric, 2=names */ | ||||
static int KeepKernFac; /* Keep remotely logged kernel facility */ | static int KeepKernFac; /* Keep remotely logged kernel facility */ | ||||
static int needdofsync = 0; /* Are any file(s) waiting to be fsynced? */ | static int needdofsync = 0; /* Are any file(s) waiting to be fsynced? */ | ||||
static struct pidfh *pfh; | static struct pidfh *pfh; | ||||
static int sigpipe[2]; /* Pipe to catch a signal during select(). */ | static int sigpipe[2]; /* Pipe to catch a signal during select(). */ | ||||
static bool RFC3164NetworkFormat = true; /* Send legacy format over the wire. */ | |||||
static bool RFC3164OutputFormat = true; /* Use legacy format by default. */ | static bool RFC3164OutputFormat = true; /* Use legacy format by default. */ | ||||
static volatile sig_atomic_t MarkSet, WantDie, WantInitialize, WantReapchild; | static volatile sig_atomic_t MarkSet, WantDie, WantInitialize, WantReapchild; | ||||
struct iovlist; | struct iovlist; | ||||
static int allowaddr(char *); | static int allowaddr(char *); | ||||
static int addfile(struct filed *); | static int addfile(struct filed *); | ||||
▲ Show 20 Lines • Show All 131 Lines • ▼ Show 20 Lines | main(int argc, char *argv[]) | ||||
struct peer *pe; | struct peer *pe; | ||||
struct socklist *sl; | struct socklist *sl; | ||||
pid_t ppid = 1, spid; | pid_t ppid = 1, spid; | ||||
char *p; | char *p; | ||||
if (madvise(NULL, 0, MADV_PROTECT) != 0) | if (madvise(NULL, 0, MADV_PROTECT) != 0) | ||||
dprintf("madvise() failed: %s\n", strerror(errno)); | dprintf("madvise() failed: %s\n", strerror(errno)); | ||||
while ((ch = getopt(argc, argv, "468Aa:b:cCdf:FHkl:m:nNoO:p:P:sS:Tuv")) | while ((ch = getopt(argc, argv, "468Aa:b:cCdf:FHkl:m:nNoO:p:P:r:sS:Tuv")) | ||||
!= -1) | != -1) | ||||
switch (ch) { | switch (ch) { | ||||
#ifdef INET | #ifdef INET | ||||
case '4': | case '4': | ||||
family = PF_INET; | family = PF_INET; | ||||
break; | break; | ||||
#endif | #endif | ||||
#ifdef INET6 | #ifdef INET6 | ||||
▲ Show 20 Lines • Show All 122 Lines • ▼ Show 20 Lines | case 'O': | ||||
usage(); | usage(); | ||||
break; | break; | ||||
case 'o': | case 'o': | ||||
use_bootfile = 1; | use_bootfile = 1; | ||||
break; | break; | ||||
case 'P': /* path for alt. PID */ | case 'P': /* path for alt. PID */ | ||||
PidFile = optarg; | PidFile = optarg; | ||||
break; | break; | ||||
case 'r': | |||||
if (strcmp(optarg, "bsd") == 0 || | |||||
strcmp(optarg, "rfc3164") == 0) | |||||
RFC3164NetworkFormat = true; | |||||
else if (strcmp(optarg, "syslog") == 0 || | |||||
strcmp(optarg, "rfc5424") == 0) | |||||
RFC3164NetworkFormat = false; | |||||
else | |||||
usage(); | |||||
break; | |||||
case 's': /* no network mode */ | case 's': /* no network mode */ | ||||
SecureMode++; | SecureMode++; | ||||
break; | break; | ||||
case 'T': | case 'T': | ||||
RemoteAddDate = 1; | RemoteAddDate = 1; | ||||
break; | break; | ||||
case 'u': /* only log specified priority */ | case 'u': /* only log specified priority */ | ||||
UniquePriority++; | UniquePriority++; | ||||
▲ Show 20 Lines • Show All 242 Lines • ▼ Show 20 Lines | |||||
usage(void) | usage(void) | ||||
{ | { | ||||
fprintf(stderr, | fprintf(stderr, | ||||
"usage: syslogd [-468ACcdFHknosTuv] [-a allowed_peer]\n" | "usage: syslogd [-468ACcdFHknosTuv] [-a allowed_peer]\n" | ||||
" [-b bind_address] [-f config_file]\n" | " [-b bind_address] [-f config_file]\n" | ||||
" [-l [mode:]path] [-m mark_interval]\n" | " [-l [mode:]path] [-m mark_interval]\n" | ||||
" [-O format] [-P pid_file] [-p log_socket]\n" | " [-O format] [-P pid_file] [-p log_socket]\n" | ||||
" [-S logpriv_socket]\n"); | " [-r format] [-S logpriv_socket]\n"); | ||||
exit(1); | exit(1); | ||||
} | } | ||||
/* | /* | ||||
* Removes characters from log messages that are unsafe to display. | * Removes characters from log messages that are unsafe to display. | ||||
* TODO: Permit UTF-8 strings that include a BOM per RFC 5424? | * TODO: Permit UTF-8 strings that include a BOM per RFC 5424? | ||||
*/ | */ | ||||
static void | static void | ||||
▲ Show 20 Lines • Show All 1,176 Lines • ▼ Show 20 Lines | fprintlog_rfc3164(struct filed *f, const char *hostname, const char *app_name, | ||||
fprintlog_write(f, &il, flags); | fprintlog_write(f, &il, flags); | ||||
} | } | ||||
static void | static void | ||||
fprintlog_first(struct filed *f, const char *hostname, const char *app_name, | fprintlog_first(struct filed *f, const char *hostname, const char *app_name, | ||||
const char *procid, const char *msgid __unused, | const char *procid, const char *msgid __unused, | ||||
const char *structured_data __unused, const char *msg, int flags) | const char *structured_data __unused, const char *msg, int flags) | ||||
{ | { | ||||
bool RFC3164; | |||||
dprintf("Logging to %s", TypeNames[f->f_type]); | dprintf("Logging to %s", TypeNames[f->f_type]); | ||||
f->f_time = now; | f->f_time = now; | ||||
f->f_prevcount = 0; | f->f_prevcount = 0; | ||||
if (f->f_type == F_UNUSED) { | if (f->f_type == F_UNUSED) { | ||||
dprintf("\n"); | dprintf("\n"); | ||||
return; | return; | ||||
} | } | ||||
if (RFC3164OutputFormat) | RFC3164 = (f->f_type == F_FORW) ? RFC3164NetworkFormat : | ||||
RFC3164OutputFormat; | |||||
if (RFC3164) | |||||
fprintlog_rfc3164(f, hostname, app_name, procid, msg, flags); | fprintlog_rfc3164(f, hostname, app_name, procid, msg, flags); | ||||
else | else | ||||
fprintlog_rfc5424(f, hostname, app_name, procid, msgid, | fprintlog_rfc5424(f, hostname, app_name, procid, msgid, | ||||
structured_data, msg, flags); | structured_data, msg, flags); | ||||
} | } | ||||
/* | /* | ||||
* Prints a message to a log file that the previously logged message was | * Prints a message to a log file that the previously logged message was | ||||
▲ Show 20 Lines • Show All 1,789 Lines • Show Last 20 Lines |