]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
timedated: use format_timestamp instead of ctime
authorLuca Boccassi <bluca@debian.org>
Sat, 3 Apr 2021 13:46:46 +0000 (14:46 +0100)
committerLuca Boccassi <luca.boccassi@microsoft.com>
Thu, 8 Apr 2021 12:07:31 +0000 (13:07 +0100)
Some static analyzers (lgtm) warn against using non-re-entrant functions,
even though at the moment this code is not multi-threaded, just switch to
format_timestamp.

src/timedate/timedated.c

index 567244dc244ede65bc89285c27dd7ef85ba2e0a9..452c38e0de094efc2fd047c8e218fa112982c015 100644 (file)
@@ -801,6 +801,7 @@ static int method_set_local_rtc(sd_bus_message *m, void *userdata, sd_bus_error
 
 static int method_set_time(sd_bus_message *m, void *userdata, sd_bus_error *error) {
         sd_bus *bus = sd_bus_message_get_bus(m);
+        char buf[FORMAT_TIMESTAMP_MAX];
         int relative, interactive, r;
         Context *c = userdata;
         int64_t utc;
@@ -886,7 +887,7 @@ static int method_set_time(sd_bus_message *m, void *userdata, sd_bus_error *erro
         log_struct(LOG_INFO,
                    "MESSAGE_ID=" SD_MESSAGE_TIME_CHANGE_STR,
                    "REALTIME="USEC_FMT, timespec_load(&ts),
-                   LOG_MESSAGE("Changed local time to %s", ctime(&ts.tv_sec)));
+                   LOG_MESSAGE("Changed local time to %s", strnull(format_timestamp(buf, sizeof(buf), timespec_load(&ts)))));
 
         return sd_bus_reply_method_return(m, NULL);
 }