char *str = getenv("LOGGER_TEST_TIMEOFDAY");
uintmax_t sec, usec;
- if (str && sscanf(str, "%ju.%ju", &sec, &usec) == 2) {
+ if (str) {
+ if (sscanf(str, "%ju.%ju", &sec, &usec) != 2)
+ goto err;
+
tv->tv_sec = sec;
tv->tv_usec = usec;
- return tv->tv_sec >= 0 && tv->tv_usec >= 0 ? 0 : -EINVAL;
+
+ if (tv->tv_sec >= 0 && tv->tv_usec >= 0)
+ return 0;
+ else
+ goto err;
}
return gettimeofday(tv, tz);
+
+err:
+ errno = EINVAL;
+ return -1;
}
static inline char *logger_xgethostname(void)
errx(EXIT_FAILURE, _("openlog %s: pathname too long"), path);
s_addr.sun_family = AF_UNIX;
- strcpy(s_addr.sun_path, path);
+ xstrncpy(s_addr.sun_path, path, sizeof(s_addr.sun_path));
for (i = 2; i; i--) {
int st = -1;
int n, lines = 0, vectors = 8, ret = 0, msgline = -1;
size_t dummy = 0;
- iovec = xmalloc(vectors * sizeof(struct iovec));
+ iovec = xreallocarray(NULL, vectors, sizeof(struct iovec));
while (1) {
buf = NULL;
sz = getline(&buf, &dummy, fp);
static char time[32];
struct timeval tv;
struct tm tm;
+ int ret;
static char const * const monthnames[] = {
"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug",
"Sep", "Oct", "Nov", "Dec"
};
- logger_gettimeofday(&tv, NULL);
+ ret = logger_gettimeofday(&tv, NULL);
+ if (ret == -1)
+ err(EXIT_FAILURE, _("gettimeofday() failed"));
localtime_r(&tv.tv_sec, &tm);
snprintf(time, sizeof(time),"%s %2d %2.2d:%2.2d:%2.2d",
monthnames[tm.tm_mon], tm.tm_mday,
if (!ctl->noact && !is_connected(ctl))
logger_reopen(ctl);
- /* 1) octen count */
+ /* 1) octet count */
if (ctl->octet_count) {
size_t len = xasprintf(&octet, "%zu ", strlen(ctl->hdr) + strlen(msg));
iovec_add_string(iov, iovlen, octet, len);
*/
static void syslog_rfc5424_header(struct logger_ctl *const ctl)
{
+ int ret;
char *time;
char *hostname;
char const *app_name = ctl->tag;
struct timeval tv;
struct tm tm;
- logger_gettimeofday(&tv, NULL);
+ ret = logger_gettimeofday(&tv, NULL);
+ if (ret == -1)
+ err(EXIT_FAILURE, _("gettimeofday() failed"));
if (localtime_r(&tv.tv_sec, &tm) != NULL) {
char fmt[64];
const size_t i = strftime(fmt, sizeof(fmt),
- "%Y-%m-%dT%H:%M:%S.%%06u%z ", &tm);
+ "%Y-%m-%dT%H:%M:%S.%%06jd%z ", &tm);
/* patch TZ info to comply with RFC3339 (we left SP at end) */
fmt[i - 1] = fmt[i - 2];
fmt[i - 2] = fmt[i - 3];
fmt[i - 3] = ':';
- xasprintf(&time, fmt, tv.tv_usec);
+ xasprintf(&time, fmt, (intmax_t) tv.tv_usec);
} else
err(EXIT_FAILURE, _("localtime() failed"));
} else
#endif
fputs(USAGE_SEPARATOR, out);
- printf(USAGE_HELP_OPTIONS(26));
- printf(USAGE_MAN_TAIL("logger(1)"));
+ fprintf(out, USAGE_HELP_OPTIONS(26));
+ fprintf(out, USAGE_MAN_TAIL("logger(1)"));
exit(EXIT_SUCCESS);
}