* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config SYSLOGD
-//config: bool "syslogd (12 kb)"
+//config: bool "syslogd (13 kb)"
//config: default y
//config: help
//config: The syslogd utility is used to record logs of all the
//config: help
//config: Supports restricted syslogd config. See docs/syslog.conf.txt
//config:
+//config:config FEATURE_SYSLOGD_PRECISE_TIMESTAMPS
+//config: bool "Include milliseconds in timestamps"
+//config: default n
+//config: depends on SYSLOGD
+//config: help
+//config: Includes milliseconds (HH:MM:SS.mmm) in timestamp when
+//config: timestamps are added.
+//config:
//config:config FEATURE_SYSLOGD_READ_BUFFER_SIZE
//config: int "Read buffer size in bytes"
//config: default 256
/* ...then copy to parsebuf, escaping control chars */
/* (can grow x2 max) */
char parsebuf[MAX_READ*2];
- /* ...then sprintf into printbuf, adding timestamp (15 chars),
+ /* ...then sprintf into printbuf, adding timestamp (15 or 19 chars),
* host (64), fac.prio (20) to the message */
/* (growth by: 15 + 64 + 20 + delims = ~110) */
char printbuf[MAX_READ*2 + 128];
G.shmid = shmget(KEY_ID, G.shm_size, IPC_CREAT | 0644);
if (G.shmid == -1) {
- bb_perror_msg_and_die("shmget");
+ bb_simple_perror_msg_and_die("shmget");
}
G.shbuf = shmat(G.shmid, NULL, 0);
if (G.shbuf == (void*) -1L) { /* shmat has bizarre error return */
- bb_perror_msg_and_die("shmat");
+ bb_simple_perror_msg_and_die("shmat");
}
memset(G.shbuf, 0, G.shm_size);
if (G.s_semid != -1)
return;
}
- bb_perror_msg_and_die("semget");
+ bb_simple_perror_msg_and_die("semget");
}
}
int len;
if (semop(G.s_semid, G.SMwdn, 3) == -1) {
- bb_perror_msg_and_die("SMwdn");
+ bb_simple_perror_msg_and_die("SMwdn");
}
/* Circular Buffer Algorithm:
goto again;
}
if (semop(G.s_semid, G.SMwup, 1) == -1) {
- bb_perror_msg_and_die("SMwup");
+ bb_simple_perror_msg_and_die("SMwup");
}
if (DEBUG)
printf("tail:%d\n", G.shbuf->tail);
msg += 16;
}
+#if ENABLE_FEATURE_SYSLOGD_PRECISE_TIMESTAMPS
+ if (!timestamp) {
+ struct timeval tv;
+ gettimeofday(&tv, NULL);
+ now = tv.tv_sec;
+ timestamp = ctime(&now) + 4; /* skip day of week */
+ /* overwrite year by milliseconds, zero terminate */
+ sprintf(timestamp + 15, ".%03u", (unsigned)tv.tv_usec / 1000u);
+ } else {
+ timestamp[15] = '\0';
+ }
+#else
if (!timestamp) {
time(&now);
timestamp = ctime(&now) + 4; /* skip day of week */
}
-
timestamp[15] = '\0';
+#endif
if (option_mask32 & OPT_kmsg) {
log_to_kmsg(pri, msg);
} /* while (!bb_got_signal) */
timestamp_and_log_internal("syslogd exiting");
- remove_pidfile(CONFIG_PID_FILE_PATH "/syslogd.pid");
+ remove_pidfile_std_path_and_ext("syslogd");
ipcsyslog_cleanup();
if (option_mask32 & OPT_kmsg)
kmsg_cleanup();
}
//umask(0); - why??
- write_pidfile(CONFIG_PID_FILE_PATH "/syslogd.pid");
+ write_pidfile_std_path_and_ext("syslogd");
do_syslogd();
/* return EXIT_SUCCESS; */