Skip to content

Commit 86b39b4

Browse files
part1zanotonyhutter
authored andcommittedApr 29, 2024
Fix locale-specific time
In `zpool status -t`, scrub date/time is reported using the C locale, while trim time is reported using the current one. This is inconsistent. This patch fixes that. Reviewed-by: Tino Reichardt <milky-zfs@mcmilk.de> Reviewed-by: Tony Hutter <hutter2@llnl.gov> Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: Maxim Filimonov <che@bein.link> Closes #15878 Closes #15879
1 parent 531572b commit 86b39b4

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed
 

‎cmd/zpool/zpool_main.c

+4-6
Original file line numberDiff line numberDiff line change
@@ -2246,7 +2246,6 @@ print_status_initialize(vdev_stat_t *vs, boolean_t verbose)
22462246
!vs->vs_scan_removing) {
22472247
char zbuf[1024];
22482248
char tbuf[256];
2249-
struct tm zaction_ts;
22502249

22512250
time_t t = vs->vs_initialize_action_time;
22522251
int initialize_pct = 100;
@@ -2256,8 +2255,8 @@ print_status_initialize(vdev_stat_t *vs, boolean_t verbose)
22562255
100 / (vs->vs_initialize_bytes_est + 1));
22572256
}
22582257

2259-
(void) localtime_r(&t, &zaction_ts);
2260-
(void) strftime(tbuf, sizeof (tbuf), "%c", &zaction_ts);
2258+
(void) ctime_r(&t, tbuf);
2259+
tbuf[24] = 0;
22612260

22622261
switch (vs->vs_initialize_state) {
22632262
case VDEV_INITIALIZE_SUSPENDED:
@@ -2297,7 +2296,6 @@ print_status_trim(vdev_stat_t *vs, boolean_t verbose)
22972296
!vs->vs_scan_removing) {
22982297
char zbuf[1024];
22992298
char tbuf[256];
2300-
struct tm zaction_ts;
23012299

23022300
time_t t = vs->vs_trim_action_time;
23032301
int trim_pct = 100;
@@ -2306,8 +2304,8 @@ print_status_trim(vdev_stat_t *vs, boolean_t verbose)
23062304
100 / (vs->vs_trim_bytes_est + 1));
23072305
}
23082306

2309-
(void) localtime_r(&t, &zaction_ts);
2310-
(void) strftime(tbuf, sizeof (tbuf), "%c", &zaction_ts);
2307+
(void) ctime_r(&t, tbuf);
2308+
tbuf[24] = 0;
23112309

23122310
switch (vs->vs_trim_state) {
23132311
case VDEV_TRIM_SUSPENDED:

‎lib/libzfs/libzfs_pool.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -1899,7 +1899,8 @@ zpool_rewind_exclaim(libzfs_handle_t *hdl, const char *name, boolean_t dryrun,
18991899
(void) nvlist_lookup_int64(nv, ZPOOL_CONFIG_REWIND_TIME, &loss);
19001900

19011901
if (localtime_r((time_t *)&rewindto, &t) != NULL &&
1902-
strftime(timestr, 128, "%c", &t) != 0) {
1902+
ctime_r((time_t *)&rewindto, timestr) != NULL) {
1903+
timestr[24] = 0;
19031904
if (dryrun) {
19041905
(void) printf(dgettext(TEXT_DOMAIN,
19051906
"Would be able to return %s "
@@ -1961,7 +1962,8 @@ zpool_explain_recover(libzfs_handle_t *hdl, const char *name, int reason,
19611962
"Recovery is possible, but will result in some data loss.\n"));
19621963

19631964
if (localtime_r((time_t *)&rewindto, &t) != NULL &&
1964-
strftime(timestr, 128, "%c", &t) != 0) {
1965+
ctime_r((time_t *)&rewindto, timestr) != NULL) {
1966+
timestr[24] = 0;
19651967
(void) printf(dgettext(TEXT_DOMAIN,
19661968
"\tReturning the pool to its state as of %s\n"
19671969
"\tshould correct the problem. "),

0 commit comments

Comments
 (0)