summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2017-10-24 12:24:09 +0200
committerGitHub <noreply@github.com>2017-10-24 12:24:09 +0200
commite0237035a0d68bb748be767f9c241601db5c4cdc (patch)
treed2728cb8fe9f8f5d891744ecbb4b36ae6b14c2b0 /src
parent1898e5f9a37d1a50f8c0bd1147abe11c3d38a16b (diff)
parent14ce0c25c28ba58e80084e28b4f23884199900e4 (diff)
downloadsystemd-e0237035a0d68bb748be767f9c241601db5c4cdc.tar.gz
Merge pull request #7123 from keszybz/date-formatting
Fix for time stamp formatting in timedatectl
Diffstat (limited to 'src')
-rw-r--r--src/basic/time-util.h4
-rw-r--r--src/test/meson.build2
-rw-r--r--src/test/test-time-util.c (renamed from src/test/test-time.c)0
-rw-r--r--src/timedate/timedatectl.c21
4 files changed, 12 insertions, 15 deletions
diff --git a/src/basic/time-util.h b/src/basic/time-util.h
index 3b7f0e99c0..73f7e40066 100644
--- a/src/basic/time-util.h
+++ b/src/basic/time-util.h
@@ -148,10 +148,6 @@ clockid_t clock_boottime_or_monotonic(void);
usec_t usec_shift_clock(usec_t, clockid_t from, clockid_t to);
-#define xstrftime(buf, fmt, tm) \
- assert_message_se(strftime(buf, ELEMENTSOF(buf), fmt, tm) > 0, \
- "xstrftime: " #buf "[] must be big enough")
-
int get_timezone(char **timezone);
time_t mktime_or_timegm(struct tm *tm, bool utc);
diff --git a/src/test/meson.build b/src/test/meson.build
index 1f3db65781..c09cbe2558 100644
--- a/src/test/meson.build
+++ b/src/test/meson.build
@@ -403,7 +403,7 @@ tests += [
[],
[]],
- [['src/test/test-time.c'],
+ [['src/test/test-time-util.c'],
[],
[]],
diff --git a/src/test/test-time.c b/src/test/test-time-util.c
index b7a06c7b19..b7a06c7b19 100644
--- a/src/test/test-time.c
+++ b/src/test/test-time-util.c
diff --git a/src/timedate/timedatectl.c b/src/timedate/timedatectl.c
index a30e783c09..716675aa1d 100644
--- a/src/timedate/timedatectl.c
+++ b/src/timedate/timedatectl.c
@@ -72,12 +72,13 @@ static void status_info_clear(StatusInfo *info) {
}
static void print_status_info(const StatusInfo *i) {
- char a[FORMAT_TIMESTAMP_MAX];
+ char a[LINE_MAX];
struct tm tm;
time_t sec;
bool have_time = false;
const char *old_tz = NULL, *tz;
int r;
+ size_t n;
assert(i);
@@ -102,11 +103,11 @@ static void print_status_info(const StatusInfo *i) {
log_warning("Could not get time from timedated and not operating locally, ignoring.");
if (have_time) {
- xstrftime(a, "%a %Y-%m-%d %H:%M:%S %Z", localtime_r(&sec, &tm));
- printf(" Local time: %.*s\n", (int) sizeof(a), a);
+ n = strftime(a, sizeof a, "%a %Y-%m-%d %H:%M:%S %Z", localtime_r(&sec, &tm));
+ printf(" Local time: %s\n", n > 0 ? a : "n/a");
- xstrftime(a, "%a %Y-%m-%d %H:%M:%S UTC", gmtime_r(&sec, &tm));
- printf(" Universal time: %.*s\n", (int) sizeof(a), a);
+ n = strftime(a, sizeof a, "%a %Y-%m-%d %H:%M:%S UTC", gmtime_r(&sec, &tm));
+ printf(" Universal time: %s\n", n > 0 ? a : "n/a");
} else {
printf(" Local time: %s\n", "n/a");
printf(" Universal time: %s\n", "n/a");
@@ -116,13 +117,13 @@ static void print_status_info(const StatusInfo *i) {
time_t rtc_sec;
rtc_sec = (time_t) (i->rtc_time / USEC_PER_SEC);
- xstrftime(a, "%a %Y-%m-%d %H:%M:%S", gmtime_r(&rtc_sec, &tm));
- printf(" RTC time: %.*s\n", (int) sizeof(a), a);
+ n = strftime(a, sizeof a, "%a %Y-%m-%d %H:%M:%S", gmtime_r(&rtc_sec, &tm));
+ printf(" RTC time: %s\n", n > 0 ? a : "n/a");
} else
printf(" RTC time: %s\n", "n/a");
if (have_time)
- xstrftime(a, "%Z, %z", localtime_r(&sec, &tm));
+ n = strftime(a, sizeof a, "%Z, %z", localtime_r(&sec, &tm));
/* Restore the $TZ */
if (old_tz)
@@ -134,11 +135,11 @@ static void print_status_info(const StatusInfo *i) {
else
tzset();
- printf(" Time zone: %s (%.*s)\n"
+ printf(" Time zone: %s (%s)\n"
" System clock synchronized: %s\n"
"systemd-timesyncd.service active: %s\n"
" RTC in local TZ: %s\n",
- strna(i->timezone), (int) sizeof(a), have_time ? a : "n/a",
+ strna(i->timezone), have_time && n > 0 ? a : "n/a",
i->ntp_capable ? yes_no(i->ntp_enabled) : "n/a",
yes_no(i->ntp_synced),
yes_no(i->rtc_local));