Changeset View
Changeset View
Standalone View
Standalone View
usr.sbin/syslogd/syslogd.c
| Context not available. | |||||
| #define F_WALL 6 /* everyone logged on */ | #define F_WALL 6 /* everyone logged on */ | ||||
| #define F_PIPE 7 /* pipe to program */ | #define F_PIPE 7 /* pipe to program */ | ||||
| enum log_format { DEFAULT_FORMAT = 0, RFC3164, RFC5424 }; | |||||
| #define DEFAULT_FORMAT_IS RFC3164 | |||||
| static const char *TypeNames[] = { | static const char *TypeNames[] = { | ||||
| "UNUSED", "FILE", "TTY", "CONSOLE", | "UNUSED", "FILE", "TTY", "CONSOLE", | ||||
| "FORW", "USERS", "WALL", "PIPE" | "FORW", "USERS", "WALL", "PIPE" | ||||
| Context not available. | |||||
| 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 RFC3164OutputFormat = true; /* Use legacy format by default. */ | |||||
| /* | |||||
| * Formats to write output in. NetworkFormat controls logs sent to | |||||
| * remote syslog servers; when unset, it defaults to the same as | |||||
| * OutputFormat. OutputFormat defaults to RFC3164 format for backwards | |||||
| * compatibility. | |||||
| */ | |||||
| static enum log_format NetworkFormat, OutputFormat; | |||||
| static volatile sig_atomic_t MarkSet, WantDie, WantInitialize, WantReapchild; | static volatile sig_atomic_t MarkSet, WantDie, WantInitialize, WantReapchild; | ||||
| Context not available. | |||||
| 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:m:nNoO:p:P:sS:Tuv")) | while ((ch = getopt(argc, argv, "468Aa:b:cCdf:FHkl:M:m:nNoO:p:P:r:sS:Tuv")) | ||||
| != -1) | != -1) | ||||
| switch (ch) { | switch (ch) { | ||||
| #ifdef INET | #ifdef INET | ||||
| Context not available. | |||||
| case 'O': | case 'O': | ||||
| if (strcmp(optarg, "bsd") == 0 || | if (strcmp(optarg, "bsd") == 0 || | ||||
| strcmp(optarg, "rfc3164") == 0) | strcmp(optarg, "rfc3164") == 0) | ||||
| RFC3164OutputFormat = true; | OutputFormat = RFC3164; | ||||
| else if (strcmp(optarg, "syslog") == 0 || | else if (strcmp(optarg, "syslog") == 0 || | ||||
| strcmp(optarg, "rfc5424") == 0) | strcmp(optarg, "rfc5424") == 0) | ||||
| RFC3164OutputFormat = false; | OutputFormat = RFC5424; | ||||
| else | else | ||||
| usage(); | usage(); | ||||
| break; | break; | ||||
| Context not available. | |||||
| 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) | |||||
| NetworkFormat = RFC3164; | |||||
| else if (strcmp(optarg, "syslog") == 0 || | |||||
| strcmp(optarg, "rfc5424") == 0) | |||||
| NetworkFormat = RFC5424; | |||||
| else | |||||
| usage(); | |||||
| break; | |||||
| case 's': /* no network mode */ | case 's': /* no network mode */ | ||||
| SecureMode++; | SecureMode++; | ||||
| break; | break; | ||||
| Context not available. | |||||
| if ((argc -= optind) != 0) | if ((argc -= optind) != 0) | ||||
| usage(); | usage(); | ||||
| if (RFC3164OutputFormat && MaxForwardLen > 1024) | /* Explicitly set formats which have been defaulted to the defaults */ | ||||
| if (OutputFormat == DEFAULT_FORMAT) | |||||
| OutputFormat = DEFAULT_FORMAT_IS; | |||||
| if (NetworkFormat == DEFAULT_FORMAT) | |||||
| NetworkFormat = OutputFormat; | |||||
| if (NetworkFormat == RFC3164 && MaxForwardLen > 1024) | |||||
| errx(1, "RFC 3164 messages may not exceed 1024 bytes"); | errx(1, "RFC 3164 messages may not exceed 1024 bytes"); | ||||
| /* Pipe to catch a signal during select(). */ | /* Pipe to catch a signal during select(). */ | ||||
| Context not available. | |||||
| " [-b bind_address] [-f config_file]\n" | " [-b bind_address] [-f config_file]\n" | ||||
| " [-l [mode:]path] [-M fwd_length]\n" | " [-l [mode:]path] [-M fwd_length]\n" | ||||
| " [-m mark_interval] [-O format] [-P pid_file]\n" | " [-m mark_interval] [-O format] [-P pid_file]\n" | ||||
| " [-p log_socket] [-S logpriv_socket]\n"); | " [-p log_socket] [-r format] [-S logpriv_socket]\n"); | ||||
| exit(1); | exit(1); | ||||
| } | } | ||||
| Context not available. | |||||
| 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) | ||||
| { | { | ||||
| enum log_format want_format; | |||||
| dprintf("Logging to %s", TypeNames[f->f_type]); | dprintf("Logging to %s", TypeNames[f->f_type]); | ||||
| f->f_time = now; | f->f_time = now; | ||||
| Context not available. | |||||
| return; | return; | ||||
| } | } | ||||
| if (RFC3164OutputFormat) | want_format = (f->f_type == F_FORW) ? NetworkFormat : OutputFormat; | ||||
| if (want_format == 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, | ||||
| Context not available. | |||||
| if (hl > 0 && hname[hl-1] == '.') | if (hl > 0 && hname[hl-1] == '.') | ||||
| hname[--hl] = '\0'; | hname[--hl] = '\0'; | ||||
| /* RFC 5424 prefers logging FQDNs. */ | /* RFC 5424 prefers logging FQDNs. */ | ||||
| if (RFC3164OutputFormat) | if (OutputFormat == RFC3164) | ||||
| trimdomain(hname, hl); | trimdomain(hname, hl); | ||||
| return (hname); | return (hname); | ||||
| } | } | ||||
| Context not available. | |||||
| err(EX_OSERR, "gethostname() failed"); | err(EX_OSERR, "gethostname() failed"); | ||||
| if ((p = strchr(LocalHostName, '.')) != NULL) { | if ((p = strchr(LocalHostName, '.')) != NULL) { | ||||
| /* RFC 5424 prefers logging FQDNs. */ | /* RFC 5424 prefers logging FQDNs. */ | ||||
| if (RFC3164OutputFormat) | if (OutputFormat == RFC3164) | ||||
| *p = '\0'; | *p = '\0'; | ||||
| LocalDomain = p + 1; | LocalDomain = p + 1; | ||||
| } else { | } else { | ||||
| Context not available. | |||||
| if (hl > 0 && f->f_host[hl-1] == '.') | if (hl > 0 && f->f_host[hl-1] == '.') | ||||
| f->f_host[--hl] = '\0'; | f->f_host[--hl] = '\0'; | ||||
| /* RFC 5424 prefers logging FQDNs. */ | /* RFC 5424 prefers logging FQDNs. */ | ||||
| if (RFC3164OutputFormat) | if (OutputFormat == RFC3164) | ||||
| trimdomain(f->f_host, hl); | trimdomain(f->f_host, hl); | ||||
| } | } | ||||
| Context not available. | |||||