X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Futmp-wtmp.c;h=77baaffacfdec7cc3a49f519bf69731664f61e24;hp=de3805e0045bdf6331f4cc3241c417a8c550e648;hb=1ddff895f3ad85ec79c4923ba8c882a283826f42;hpb=d6c9574fb558d9e304699b1cc7522c3b133adfc9 diff --git a/src/utmp-wtmp.c b/src/utmp-wtmp.c index de3805e00..77baaffac 100644 --- a/src/utmp-wtmp.c +++ b/src/utmp-wtmp.c @@ -290,10 +290,9 @@ finish: 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())) { @@ -301,18 +300,16 @@ int utmp_wall(const char *message) { 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; }