* 'various-fixes' of https://github.com/kerolasa/util-linux:
  kill: include sys/types.h before checking SYS_pidfd_send_signal
  libfdisk: fix pointer wraparound warning
  hwclock: update yacc file
  script: fix minor warning
  getopt: use examples installation directory in man page
  fstrim: randomize timer start time across 100 minutes
  various: use threadsafe versions of time functions [lgtm scan]
  write: fix potential string overflow
This commit is contained in:
Karel Zak 2020-02-18 14:02:41 +01:00
commit 88dbec9833
19 changed files with 121 additions and 88 deletions

View File

@ -118,6 +118,7 @@ edit_cmd = sed \
-e 's|@datadir[@]|$(datadir)|g' \ -e 's|@datadir[@]|$(datadir)|g' \
-e 's|@sbindir[@]|$(sbindir)|g' \ -e 's|@sbindir[@]|$(sbindir)|g' \
-e 's|@bindir[@]|$(bindir)|g' \ -e 's|@bindir[@]|$(bindir)|g' \
-e 's|@docdir[@]|$(docdir)|g' \
-e 's|@includedir[@]|$(includedir)|g' \ -e 's|@includedir[@]|$(includedir)|g' \
-e 's|@runstatedir[@]|$(runstatedir)|g' \ -e 's|@runstatedir[@]|$(runstatedir)|g' \
-e 's|@usrlib_execdir[@]|$(usrlib_execdir)|g' \ -e 's|@usrlib_execdir[@]|$(usrlib_execdir)|g' \

View File

@ -1,26 +1,28 @@
#ifndef UTIL_LINUX_PIDFD_UTILS #ifndef UTIL_LINUX_PIDFD_UTILS
#define UTIL_LINUX_PIDFD_UTILS #define UTIL_LINUX_PIDFD_UTILS
#if defined(__linux__) && defined(SYS_pidfd_send_signal) #if defined(__linux__)
# include <sys/types.h>
# include <sys/syscall.h> # include <sys/syscall.h>
# if defined(SYS_pidfd_send_signal)
# include <sys/types.h>
# ifndef HAVE_PIDFD_OPEN # ifndef HAVE_PIDFD_OPEN
static inline int pidfd_send_signal(int pidfd, int sig, siginfo_t *info, static inline int pidfd_send_signal(int pidfd, int sig, siginfo_t *info,
unsigned int flags) unsigned int flags)
{ {
return syscall(SYS_pidfd_send_signal, pidfd, sig, info, flags); return syscall(SYS_pidfd_send_signal, pidfd, sig, info, flags);
} }
# endif # endif
# ifndef HAVE_PIDFD_SEND_SIGNAL # ifndef HAVE_PIDFD_SEND_SIGNAL
static inline int pidfd_open(pid_t pid, unsigned int flags) static inline int pidfd_open(pid_t pid, unsigned int flags)
{ {
return syscall(SYS_pidfd_open, pid, flags); return syscall(SYS_pidfd_open, pid, flags);
} }
# endif # endif
# define UL_HAVE_PIDFD 1 # define UL_HAVE_PIDFD 1
#endif /* __linux__ && SYS_pidfd_send_signal */ # endif /* SYS_pidfd_send_signal */
#endif /* __linux__ */
#endif /* UTIL_LINUX_PIDFD_UTILS */ #endif /* UTIL_LINUX_PIDFD_UTILS */

View File

@ -74,6 +74,7 @@ enum {
ISO_TIMESTAMP_COMMA_GT = ISO_TIMESTAMP_COMMA_G | ISO_T ISO_TIMESTAMP_COMMA_GT = ISO_TIMESTAMP_COMMA_G | ISO_T
}; };
#define CTIME_BUFSIZ 26
#define ISO_BUFSIZ 42 #define ISO_BUFSIZ 42
int strtimeval_iso(struct timeval *tv, int flags, char *buf, size_t bufsz); int strtimeval_iso(struct timeval *tv, int flags, char *buf, size_t bufsz);

View File

@ -1710,13 +1710,13 @@ static int gpt_entry_attrs_to_string(struct gpt_entry *e, char **res)
p += l - 1; p += l - 1;
} }
if (isset(bits, GPT_ATTRBIT_NOBLOCK)) { if (isset(bits, GPT_ATTRBIT_NOBLOCK)) {
if (p > *res) if (p != *res)
*p++ = ' '; *p++ = ' ';
memcpy(p, GPT_ATTRSTR_NOBLOCK, (l = sizeof(GPT_ATTRSTR_NOBLOCK))); memcpy(p, GPT_ATTRSTR_NOBLOCK, (l = sizeof(GPT_ATTRSTR_NOBLOCK)));
p += l - 1; p += l - 1;
} }
if (isset(bits, GPT_ATTRBIT_LEGACY)) { if (isset(bits, GPT_ATTRBIT_LEGACY)) {
if (p > *res) if (p != *res)
*p++ = ' '; *p++ = ' ';
memcpy(p, GPT_ATTRSTR_LEGACY, (l = sizeof(GPT_ATTRSTR_LEGACY))); memcpy(p, GPT_ATTRSTR_LEGACY, (l = sizeof(GPT_ATTRSTR_LEGACY)));
p += l - 1; p += l - 1;
@ -1728,7 +1728,7 @@ static int gpt_entry_attrs_to_string(struct gpt_entry *e, char **res)
if (!isset(bits, n)) if (!isset(bits, n))
continue; continue;
if (!count) { if (!count) {
if (p > *res) if (p != *res)
*p++ = ' '; *p++ = ' ';
p += sprintf(p, "GUID:%u", n); p += sprintf(p, "GUID:%u", n);
} else } else

View File

@ -263,7 +263,9 @@ static int uread(FILE *fp, struct utmpx *u, int *quit, const char *filename)
*/ */
static char *showdate(void) static char *showdate(void)
{ {
char *s = ctime(&lastdate); static char s[CTIME_BUFSIZ];
ctime_r(&lastdate, s);
s[16] = 0; s[16] = 0;
return s; return s;
} }
@ -339,15 +341,22 @@ static int time_formatter(int fmt, char *dst, size_t dlen, time_t *when)
break; break;
case LAST_TIMEFTM_HHMM: case LAST_TIMEFTM_HHMM:
{ {
struct tm *tm = localtime(when); struct tm tm;
if (!snprintf(dst, dlen, "%02d:%02d", tm->tm_hour, tm->tm_min))
localtime_r(when, &tm);
if (!snprintf(dst, dlen, "%02d:%02d", tm.tm_hour, tm.tm_min))
ret = -1; ret = -1;
break; break;
} }
case LAST_TIMEFTM_CTIME: case LAST_TIMEFTM_CTIME:
snprintf(dst, dlen, "%s", ctime(when)); {
char buf[CTIME_BUFSIZ];
ctime_r(when, buf);
snprintf(dst, dlen, "%s", buf);
ret = rtrim_whitespace((unsigned char *) dst); ret = rtrim_whitespace((unsigned char *) dst);
break; break;
}
case LAST_TIMEFTM_ISO8601: case LAST_TIMEFTM_ISO8601:
ret = strtime_iso(when, ISO_TIMESTAMP_T, dst, dlen); ret = strtime_iso(when, ISO_TIMESTAMP_T, dst, dlen);
break; break;

View File

@ -76,6 +76,7 @@
#include "xalloc.h" #include "xalloc.h"
#include "all-io.h" #include "all-io.h"
#include "fileutils.h" #include "fileutils.h"
#include "timeutils.h"
#include "ttyutils.h" #include "ttyutils.h"
#include "pwdutils.h" #include "pwdutils.h"
@ -524,9 +525,12 @@ static void log_lastlog(struct login_context *cxt)
if (!cxt->quiet) { if (!cxt->quiet) {
if (read(fd, (char *)&ll, sizeof(ll)) == sizeof(ll) && if (read(fd, (char *)&ll, sizeof(ll)) == sizeof(ll) &&
ll.ll_time != 0) { ll.ll_time != 0) {
char time_string[CTIME_BUFSIZ];
time_t ll_time = (time_t) ll.ll_time; time_t ll_time = (time_t) ll.ll_time;
printf(_("Last login: %.*s "), 24 - 5, ctime(&ll_time)); ctime_r(&ll_time, time_string);
printf(_("Last login: %.*s "), 24 - 5, time_string);
if (*ll.ll_host != '\0') if (*ll.ll_host != '\0')
printf(_("from %.*s\n"), printf(_("from %.*s\n"),
(int)sizeof(ll.ll_host), ll.ll_host); (int)sizeof(ll.ll_host), ll.ll_host);

View File

@ -1,3 +1,4 @@
getopt.1
uuidd.8 uuidd.8
uuidd.rc uuidd.rc
uuidd.service uuidd.service

View File

@ -202,6 +202,7 @@ endif
if BUILD_GETOPT if BUILD_GETOPT
usrbin_exec_PROGRAMS += getopt usrbin_exec_PROGRAMS += getopt
dist_man_MANS += misc-utils/getopt.1 dist_man_MANS += misc-utils/getopt.1
PATHFILES += misc-utils/getopt.1
getopt_SOURCES = misc-utils/getopt.c getopt_SOURCES = misc-utils/getopt.c
getoptexampledir = $(docdir)/getopt/ getoptexampledir = $(docdir)/getopt/
dist_getoptexample_SCRIPTS = \ dist_getoptexample_SCRIPTS = \

View File

@ -281,7 +281,7 @@ static time_t cal_time(time_t *t)
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
struct tm *local_time; struct tm local_time;
char *term; char *term;
time_t now; time_t now;
int ch = 0, yflag = 0, Yflag = 0; int ch = 0, yflag = 0, Yflag = 0;
@ -467,7 +467,7 @@ int main(int argc, char **argv)
} else } else
cal_time(&now); cal_time(&now);
local_time = localtime(&now); localtime_r(&now, &local_time);
switch(argc) { switch(argc) {
case 3: case 3:
@ -500,20 +500,20 @@ int main(int argc, char **argv)
errx(EXIT_FAILURE, _("illegal day value: use 1-%d"), dm); errx(EXIT_FAILURE, _("illegal day value: use 1-%d"), dm);
ctl.req.day = day_in_year(&ctl, ctl.req.day, ctl.req.day = day_in_year(&ctl, ctl.req.day,
ctl.req.month, ctl.req.year); ctl.req.month, ctl.req.year);
} else if ((int32_t) (local_time->tm_year + 1900) == ctl.req.year) { } else if ((int32_t) (local_time.tm_year + 1900) == ctl.req.year) {
ctl.req.day = local_time->tm_yday + 1; ctl.req.day = local_time.tm_yday + 1;
} }
if (!ctl.req.month && !ctl.req.week) { if (!ctl.req.month && !ctl.req.week) {
ctl.req.month = local_time->tm_mon + 1; ctl.req.month = local_time.tm_mon + 1;
if (!ctl.num_months) if (!ctl.num_months)
yflag = 1; yflag = 1;
} }
break; break;
case 0: case 0:
ctl.req.day = local_time->tm_yday + 1; ctl.req.day = local_time.tm_yday + 1;
ctl.req.year = local_time->tm_year + 1900; ctl.req.year = local_time.tm_year + 1900;
if (!ctl.req.month) if (!ctl.req.month)
ctl.req.month = local_time->tm_mon + 1; ctl.req.month = local_time.tm_mon + 1;
break; break;
default: default:
warnx(_("bad usage")); warnx(_("bad usage"));

View File

@ -417,11 +417,9 @@ if it is called with
.SH EXAMPLES .SH EXAMPLES
Example scripts for (ba)sh and (t)csh are provided with the Example scripts for (ba)sh and (t)csh are provided with the
.BR getopt (1) .BR getopt (1)
distribution, and are optionally installed in distribution, and are installed in
.I /usr/share/getopt/ .I @docdir@/getopt/
or directory.
.I /usr/share/doc/
in the util-linux subdirectory.
.SH ENVIRONMENT .SH ENVIRONMENT
.IP POSIXLY_CORRECT .IP POSIXLY_CORRECT
This environment variable is examined by the This environment variable is examined by the

View File

@ -413,17 +413,17 @@ static char const *rfc3164_current_time(void)
{ {
static char time[32]; static char time[32];
struct timeval tv; struct timeval tv;
struct tm *tm; struct tm tm;
static char const * const monthnames[] = { static char const * const monthnames[] = {
"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug",
"Sep", "Oct", "Nov", "Dec" "Sep", "Oct", "Nov", "Dec"
}; };
logger_gettimeofday(&tv, NULL); logger_gettimeofday(&tv, NULL);
tm = localtime(&tv.tv_sec); localtime_r(&tv.tv_sec, &tm);
snprintf(time, sizeof(time),"%s %2d %2.2d:%2.2d:%2.2d", snprintf(time, sizeof(time),"%s %2d %2.2d:%2.2d:%2.2d",
monthnames[tm->tm_mon], tm->tm_mday, monthnames[tm.tm_mon], tm.tm_mday,
tm->tm_hour, tm->tm_min, tm->tm_sec); tm.tm_hour, tm.tm_min, tm.tm_sec);
return time; return time;
} }

View File

@ -7,6 +7,7 @@ ConditionVirtualization=!container
OnCalendar=weekly OnCalendar=weekly
AccuracySec=1h AccuracySec=1h
Persistent=true Persistent=true
RandomizedDelaySec=6000
[Install] [Install]
WantedBy=timers.target WantedBy=timers.target

View File

@ -284,7 +284,7 @@ set_hhmmss(parser_control *pc, intmax_t hour, intmax_t minutes,
* We want a reentrant parser, even if the TZ manipulation and the calls to * We want a reentrant parser, even if the TZ manipulation and the calls to
* localtime and gmtime are not reentrant. * localtime and gmtime are not reentrant.
*/ */
%pure-parser %define api.pure
%parse-param { parser_control *pc } %parse-param { parser_control *pc }
%lex-param { parser_control *pc } %lex-param { parser_control *pc }

View File

@ -21,6 +21,7 @@
#include "c.h" #include "c.h"
#include "nls.h" #include "nls.h"
#include "closestream.h" #include "closestream.h"
#include "timeutils.h"
#include "ipcutils.h" #include "ipcutils.h"
@ -43,8 +44,14 @@ static void print_sem (int id);
static void do_msg (char format, int unit); static void do_msg (char format, int unit);
static void print_msg (int id, int unit); static void print_msg (int id, int unit);
/* we read time as int64_t from /proc, so cast... */ static inline char *ctime64(int64_t *t)
#define xctime(_x) ctime((time_t *) (_x)) {
static char buf[CTIME_BUFSIZ];
/* we read time as int64_t from /proc, so cast... */
ctime_r((time_t *)t, buf);
return buf;
}
static void __attribute__((__noreturn__)) usage(void) static void __attribute__((__noreturn__)) usage(void)
{ {
@ -309,11 +316,11 @@ static void do_shm (char format, int unit)
printf ("%-10d %-10u", shmdsp->shm_perm.id, shmdsp->shm_perm.uid); printf ("%-10d %-10u", shmdsp->shm_perm.id, shmdsp->shm_perm.uid);
/* ctime uses static buffer: use separate calls */ /* ctime uses static buffer: use separate calls */
printf(" %-20.16s", shmdsp->shm_atim printf(" %-20.16s", shmdsp->shm_atim
? xctime(&shmdsp->shm_atim) + 4 : _("Not set")); ? ctime64(&shmdsp->shm_atim) + 4 : _("Not set"));
printf(" %-20.16s", shmdsp->shm_dtim printf(" %-20.16s", shmdsp->shm_dtim
? xctime(&shmdsp->shm_dtim) + 4 : _("Not set")); ? ctime64(&shmdsp->shm_dtim) + 4 : _("Not set"));
printf(" %-20.16s\n", shmdsp->shm_ctim printf(" %-20.16s\n", shmdsp->shm_ctim
? xctime(&shmdsp->shm_ctim) + 4 : _("Not set")); ? ctime64(&shmdsp->shm_ctim) + 4 : _("Not set"));
break; break;
case PID: case PID:
if (pw) if (pw)
@ -427,9 +434,9 @@ static void do_sem (char format)
else else
printf ("%-8d %-10u", semdsp->sem_perm.id, semdsp->sem_perm.uid); printf ("%-8d %-10u", semdsp->sem_perm.id, semdsp->sem_perm.uid);
printf (" %-26.24s", semdsp->sem_otime printf (" %-26.24s", semdsp->sem_otime
? xctime(&semdsp->sem_otime) : _("Not set")); ? ctime64(&semdsp->sem_otime) : _("Not set"));
printf (" %-26.24s\n", semdsp->sem_ctime printf (" %-26.24s\n", semdsp->sem_ctime
? xctime( &semdsp->sem_ctime) : _("Not set")); ? ctime64( &semdsp->sem_ctime) : _("Not set"));
break; break;
case PID: case PID:
break; break;
@ -535,11 +542,11 @@ static void do_msg (char format, int unit)
else else
printf ("%-8d %-10u", msgdsp->msg_perm.id, msgdsp->msg_perm.uid); printf ("%-8d %-10u", msgdsp->msg_perm.id, msgdsp->msg_perm.uid);
printf (" %-20.16s", msgdsp->q_stime printf (" %-20.16s", msgdsp->q_stime
? xctime(&msgdsp->q_stime) + 4 : _("Not set")); ? ctime64(&msgdsp->q_stime) + 4 : _("Not set"));
printf (" %-20.16s", msgdsp->q_rtime printf (" %-20.16s", msgdsp->q_rtime
? xctime(&msgdsp->q_rtime) + 4 : _("Not set")); ? ctime64(&msgdsp->q_rtime) + 4 : _("Not set"));
printf (" %-20.16s\n", msgdsp->q_ctime printf (" %-20.16s\n", msgdsp->q_ctime
? xctime(&msgdsp->q_ctime) + 4 : _("Not set")); ? ctime64(&msgdsp->q_ctime) + 4 : _("Not set"));
break; break;
case PID: case PID:
if (pw) if (pw)
@ -593,10 +600,10 @@ static void print_shm(int shmid, int unit)
shmdata->shm_lprid, shmdata->shm_cprid, shmdata->shm_lprid, shmdata->shm_cprid,
shmdata->shm_nattch); shmdata->shm_nattch);
printf(_("att_time=%-26.24s\n"), printf(_("att_time=%-26.24s\n"),
shmdata->shm_atim ? xctime(&(shmdata->shm_atim)) : _("Not set")); shmdata->shm_atim ? ctime64(&(shmdata->shm_atim)) : _("Not set"));
printf(_("det_time=%-26.24s\n"), printf(_("det_time=%-26.24s\n"),
shmdata->shm_dtim ? xctime(&shmdata->shm_dtim) : _("Not set")); shmdata->shm_dtim ? ctime64(&shmdata->shm_dtim) : _("Not set"));
printf(_("change_time=%-26.24s\n"), xctime(&shmdata->shm_ctim)); printf(_("change_time=%-26.24s\n"), ctime64(&shmdata->shm_ctim));
printf("\n"); printf("\n");
ipc_shm_free_info(shmdata); ipc_shm_free_info(shmdata);
@ -624,11 +631,11 @@ static void print_msg(int msgid, int unit)
msgdata->q_qnum, msgdata->q_qnum,
msgdata->q_lspid, msgdata->q_lrpid); msgdata->q_lspid, msgdata->q_lrpid);
printf(_("send_time=%-26.24s\n"), printf(_("send_time=%-26.24s\n"),
msgdata->q_stime ? xctime(&msgdata->q_stime) : _("Not set")); msgdata->q_stime ? ctime64(&msgdata->q_stime) : _("Not set"));
printf(_("rcv_time=%-26.24s\n"), printf(_("rcv_time=%-26.24s\n"),
msgdata->q_rtime ? xctime(&msgdata->q_rtime) : _("Not set")); msgdata->q_rtime ? ctime64(&msgdata->q_rtime) : _("Not set"));
printf(_("change_time=%-26.24s\n"), printf(_("change_time=%-26.24s\n"),
msgdata->q_ctime ? xctime(&msgdata->q_ctime) : _("Not set")); msgdata->q_ctime ? ctime64(&msgdata->q_ctime) : _("Not set"));
printf("\n"); printf("\n");
ipc_msg_free_info(msgdata); ipc_msg_free_info(msgdata);
@ -652,8 +659,8 @@ static void print_sem(int semid)
semdata->sem_perm.mode, semdata->sem_perm.mode & 0777); semdata->sem_perm.mode, semdata->sem_perm.mode & 0777);
printf(_("nsems = %ju\n"), semdata->sem_nsems); printf(_("nsems = %ju\n"), semdata->sem_nsems);
printf(_("otime = %-26.24s\n"), printf(_("otime = %-26.24s\n"),
semdata->sem_otime ? xctime(&semdata->sem_otime) : _("Not set")); semdata->sem_otime ? ctime64(&semdata->sem_otime) : _("Not set"));
printf(_("ctime = %-26.24s\n"), xctime(&semdata->sem_ctime)); printf(_("ctime = %-26.24s\n"), ctime64(&semdata->sem_ctime));
printf("%-10s %-10s %-10s %-10s %-10s\n", printf("%-10s %-10s %-10s %-10s %-10s\n",
_("semnum"), _("value"), _("ncount"), _("zcount"), _("pid")); _("semnum"), _("value"), _("ncount"), _("zcount"), _("pid"));

View File

@ -195,21 +195,22 @@ static int get_basetimes(struct rtcwake_control *ctl, int fd)
/* Unless the system uses UTC, either delta or tzone /* Unless the system uses UTC, either delta or tzone
* reflects a seconds offset from UTC. The value can * reflects a seconds offset from UTC. The value can
* help sort out problems like bugs in your C library. */ * help sort out problems like bugs in your C library. */
char s[64];
printf("\tdelta = %ld\n", ctl->sys_time - ctl->rtc_time); printf("\tdelta = %ld\n", ctl->sys_time - ctl->rtc_time);
printf("\ttzone = %ld\n", timezone); printf("\ttzone = %ld\n", timezone);
printf("\ttzname = %s\n", tzname[daylight]); printf("\ttzname = %s\n", tzname[daylight]);
gmtime_r(&ctl->rtc_time, &tm); gmtime_r(&ctl->rtc_time, &tm);
printf("\tsystime = %ld, (UTC) %s", printf("\tsystime = %ld, (UTC) %s",
(long) ctl->sys_time, asctime(gmtime(&ctl->sys_time))); (long) ctl->sys_time, asctime_r(gmtime(&ctl->sys_time), s));
printf("\trtctime = %ld, (UTC) %s", printf("\trtctime = %ld, (UTC) %s",
(long) ctl->rtc_time, asctime(&tm)); (long) ctl->rtc_time, asctime_r(&tm, s));
} }
return 0; return 0;
} }
static int setup_alarm(struct rtcwake_control *ctl, int fd, time_t *wakeup) static int setup_alarm(struct rtcwake_control *ctl, int fd, time_t *wakeup)
{ {
struct tm *tm; struct tm tm;
struct rtc_wkalrm wake = { 0 }; struct rtc_wkalrm wake = { 0 };
/* The wakeup time is in POSIX time (more or less UTC). Ideally /* The wakeup time is in POSIX time (more or less UTC). Ideally
@ -221,13 +222,13 @@ static int setup_alarm(struct rtcwake_control *ctl, int fd, time_t *wakeup)
* *
* Else clock_mode == CM_LOCAL so the time given to the RTC will * Else clock_mode == CM_LOCAL so the time given to the RTC will
* instead use the local time zone. */ * instead use the local time zone. */
tm = localtime(wakeup); localtime_r(wakeup, &tm);
wake.time.tm_sec = tm->tm_sec; wake.time.tm_sec = tm.tm_sec;
wake.time.tm_min = tm->tm_min; wake.time.tm_min = tm.tm_min;
wake.time.tm_hour = tm->tm_hour; wake.time.tm_hour = tm.tm_hour;
wake.time.tm_mday = tm->tm_mday; wake.time.tm_mday = tm.tm_mday;
wake.time.tm_mon = tm->tm_mon; wake.time.tm_mon = tm.tm_mon;
wake.time.tm_year = tm->tm_year; wake.time.tm_year = tm.tm_year;
/* wday, yday, and isdst fields are unused */ /* wday, yday, and isdst fields are unused */
wake.time.tm_wday = -1; wake.time.tm_wday = -1;
wake.time.tm_yday = -1; wake.time.tm_yday = -1;
@ -337,6 +338,7 @@ static int print_alarm(struct rtcwake_control *ctl, int fd)
struct rtc_wkalrm wake; struct rtc_wkalrm wake;
struct tm tm = { 0 }; struct tm tm = { 0 };
time_t alarm; time_t alarm;
char s[CTIME_BUFSIZ];
if (ioctl(fd, RTC_WKALM_RD, &wake) < 0) { if (ioctl(fd, RTC_WKALM_RD, &wake) < 0) {
warn(_("read rtc alarm failed")); warn(_("read rtc alarm failed"));
@ -362,7 +364,8 @@ static int print_alarm(struct rtcwake_control *ctl, int fd)
} }
/* 0 if both UTC, or expresses diff if RTC in local time */ /* 0 if both UTC, or expresses diff if RTC in local time */
alarm += ctl->sys_time - ctl->rtc_time; alarm += ctl->sys_time - ctl->rtc_time;
printf(_("alarm: on %s"), ctime(&alarm)); ctime_r(&alarm, s);
printf(_("alarm: on %s"), s);
return 0; return 0;
} }
@ -554,9 +557,12 @@ int main(int argc, char **argv)
if (suspend != DISABLE_MODE && suspend != SHOW_MODE) { if (suspend != DISABLE_MODE && suspend != SHOW_MODE) {
/* perform alarm setup when the show or disable modes are not set */ /* perform alarm setup when the show or disable modes are not set */
if (alarm) { if (alarm) {
if (alarm < ctl.sys_time) if (alarm < ctl.sys_time) {
errx(EXIT_FAILURE, _("time doesn't go backward to %s"), char s[CTIME_BUFSIZ];
ctime(&alarm));
ctime_r(&alarm, s);
errx(EXIT_FAILURE, _("time doesn't go backward to %s"), s);
}
alarm -= ctl.sys_time - ctl.rtc_time; alarm -= ctl.sys_time - ctl.rtc_time;
} else } else
alarm = ctl.rtc_time + seconds + 1; alarm = ctl.rtc_time + seconds + 1;
@ -564,14 +570,19 @@ int main(int argc, char **argv)
if (setup_alarm(&ctl, fd, &alarm) < 0) if (setup_alarm(&ctl, fd, &alarm) < 0)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
if (suspend == NO_MODE || suspend == ON_MODE) if (suspend == NO_MODE || suspend == ON_MODE) {
char s[CTIME_BUFSIZ];
ctime_r(&alarm, s);
printf(_("%s: wakeup using %s at %s"), printf(_("%s: wakeup using %s at %s"),
program_invocation_short_name, devname, program_invocation_short_name, devname, s);
ctime(&alarm)); } else {
else char s[CTIME_BUFSIZ];
ctime_r(&alarm, s);
printf(_("%s: wakeup from \"%s\" using %s at %s"), printf(_("%s: wakeup from \"%s\" using %s at %s"),
program_invocation_short_name, ctl.mode_str, devname, program_invocation_short_name, ctl.mode_str, devname, s);
ctime(&alarm)); }
fflush(stdout); fflush(stdout);
xusleep(10 * 1000); xusleep(10 * 1000);
} }

View File

@ -2721,24 +2721,21 @@ static void output_special_char(struct issue *ie,
case 't': case 't':
{ {
time_t now; time_t now;
struct tm *tm; struct tm tm;
time(&now); time(&now);
tm = localtime(&now); localtime_r(&now, &tm);
if (!tm)
break;
if (c == 'd') /* ISO 8601 */ if (c == 'd') /* ISO 8601 */
fprintf(ie->output, "%s %s %d %d", fprintf(ie->output, "%s %s %d %d",
nl_langinfo(ABDAY_1 + tm->tm_wday), nl_langinfo(ABDAY_1 + tm.tm_wday),
nl_langinfo(ABMON_1 + tm->tm_mon), nl_langinfo(ABMON_1 + tm.tm_mon),
tm->tm_mday, tm.tm_mday,
tm->tm_year < 70 ? tm->tm_year + 2000 : tm.tm_year < 70 ? tm.tm_year + 2000 :
tm->tm_year + 1900); tm.tm_year + 1900);
else else
fprintf(ie->output, "%02d:%02d:%02d", fprintf(ie->output, "%02d:%02d:%02d",
tm->tm_hour, tm->tm_min, tm->tm_sec); tm.tm_hour, tm.tm_min, tm.tm_sec);
break; break;
} }
case 'l': case 'l':

View File

@ -98,7 +98,7 @@ static inline void timerinc(struct timeval *a, struct timeval *b)
timeradd(a, b, &res); timeradd(a, b, &res);
a->tv_sec = res.tv_sec; a->tv_sec = res.tv_sec;
a->tv_usec = res.tv_usec; a->tv_usec = res.tv_usec;
}; }
struct replay_setup *replay_new_setup(void) struct replay_setup *replay_new_setup(void)
{ {

View File

@ -71,6 +71,7 @@
#include "cctype.h" #include "cctype.h"
#include "fileutils.h" #include "fileutils.h"
#include "closestream.h" #include "closestream.h"
#include "timeutils.h"
#define TERM_WIDTH 79 #define TERM_WIDTH 79
#define WRITE_TIME_OUT 300 /* in seconds */ #define WRITE_TIME_OUT 300 /* in seconds */
@ -349,7 +350,7 @@ static char *makemsg(char *fname, char **mvec, int mvecsz,
if (print_banner == TRUE) { if (print_banner == TRUE) {
char *hostname = xgethostname(); char *hostname = xgethostname();
char *whom, *where, *date; char *whom, *where, date[CTIME_BUFSIZ];
struct passwd *pw; struct passwd *pw;
time_t now; time_t now;
@ -366,7 +367,7 @@ static char *makemsg(char *fname, char **mvec, int mvecsz,
where += 5; where += 5;
time(&now); time(&now);
date = xstrdup(ctime(&now)); ctime_r(&now, date);
date[strlen(date) - 1] = '\0'; date[strlen(date) - 1] = '\0';
/* /*
@ -385,7 +386,6 @@ static char *makemsg(char *fname, char **mvec, int mvecsz,
whom, hostname, where, date); whom, hostname, where, date);
buf_printf(bs, "%-*.*s\007\007\r\n", TERM_WIDTH, TERM_WIDTH, lbuf); buf_printf(bs, "%-*.*s\007\007\r\n", TERM_WIDTH, TERM_WIDTH, lbuf);
free(hostname); free(hostname);
free(date);
} }
buf_printf(bs, "%*s\r\n", TERM_WIDTH, " "); buf_printf(bs, "%*s\r\n", TERM_WIDTH, " ");

View File

@ -179,7 +179,7 @@ static void search_utmp(struct write_control *ctl)
if (ctl->src_uid && !tty_writeable) if (ctl->src_uid && !tty_writeable)
/* skip ttys with msgs off */ /* skip ttys with msgs off */
continue; continue;
if (strcmp(u->ut_line, ctl->src_tty_name) == 0) { if (memcmp(u->ut_line, ctl->src_tty_name, strlen(ctl->src_tty_name) + 1) == 0) {
user_is_me = 1; user_is_me = 1;
/* don't write to yourself */ /* don't write to yourself */
continue; continue;