if (c->wall_message[0])
utmp_wall(c->wall_message);
else {
- time_t s;
- char buf[27];
+ char date[FORMAT_TIMESTAMP_MAX];
const char* prefix;
char *l;
- s = c->elapse / USEC_PER_SEC;
- ctime_r(&s, buf);
-
-
if (c->mode == 'H')
prefix = "The system is going down for system halt at";
else if (c->mode == 'P')
else
assert_not_reached("Unknown mode!");
- if (asprintf(&l, "%s %s!", prefix, strstrip(buf)) < 0)
+ if (asprintf(&l, "%s %s!",
+ prefix,
+ format_timestamp(date, sizeof(date), c->elapse)) < 0)
log_error("Failed to allocate wall message");
else {
utmp_wall(l);
goto finish;
else if (k > 0 && c.elapse > 0) {
struct itimerspec its;
- char buf[27];
-
+ char date[FORMAT_TIMESTAMP_MAX];
if (c.warn_wall) {
/* Send wall messages every so often */
goto finish;
}
- ctime_r(&its.it_value.tv_sec, buf);
-
sd_notifyf(false,
"STATUS=Shutting down at %s...",
- strstrip(buf));
+ format_timestamp(date, sizeof(date), c.elapse));
}
}
int utmp_wall(const char *message) {
struct utmpx *u;
- char date[26];
+ char date[FORMAT_TIMESTAMP_MAX];
char *text = NULL, *hn = NULL, *un = NULL, *tty = NULL;
int r;
- time_t t;
if (!(hn = gethostname_malloc()) ||
!(un = getlogname_malloc())) {
goto finish;
}
- if ((r = getttyname_malloc(&tty)) < 0)
- goto finish;
-
- time(&t);
- assert_se(ctime_r(&t, date));
- delete_chars(date, "\n\r");
+ getttyname_malloc(&tty);
if (asprintf(&text,
"\a\r\n"
- "Broadcast message from %s@%s on %s (%s):\r\n\r\n"
+ "Broadcast message from %s@%s%s%s (%s):\r\n\r\n"
"%s\r\n\r\n",
- un, hn, tty, date, message) < 0) {
+ un, hn,
+ tty ? " on " : "", strempty(tty),
+ format_timestamp(date, sizeof(date), now(CLOCK_REALTIME)),
+ message) < 0) {
r = -ENOMEM;
goto finish;
}