summaryrefslogtreecommitdiff
path: root/src/utmp-wtmp.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2010-08-16 21:24:50 +0200
committerLennart Poettering <lennart@poettering.net>2010-08-16 21:24:50 +0200
commit116205924ef498ab42df233c57e1c4357618ed8a (patch)
treec5a6660991e526017391fd165aff1c8dce4c65a6 /src/utmp-wtmp.c
parent7774cdc1d83bd28f271381b941142d0468d7d6e7 (diff)
util: use format_timestamp() instead of ctime() wherever possible
Diffstat (limited to 'src/utmp-wtmp.c')
-rw-r--r--src/utmp-wtmp.c17
1 files changed, 7 insertions, 10 deletions
diff --git a/src/utmp-wtmp.c b/src/utmp-wtmp.c
index de3805e004..77baaffacf 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;
}