Skip to content

Commit

Permalink
Fix locale-specific time
Browse files Browse the repository at this point in the history
  • Loading branch information
part1zano committed Feb 27, 2024
1 parent 79c6dff commit 9649565
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
15 changes: 6 additions & 9 deletions cmd/zpool/zpool_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2246,7 +2246,6 @@ print_status_initialize(vdev_stat_t *vs, boolean_t verbose)
!vs->vs_scan_removing) {
char zbuf[1024];
char tbuf[256];
struct tm zaction_ts;

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

(void) localtime_r(&t, &zaction_ts);
(void) strftime(tbuf, sizeof (tbuf), "%c", &zaction_ts);
(void) ctime_r(&t, tbuf);
tbuf[24] = 0;

switch (vs->vs_initialize_state) {
case VDEV_INITIALIZE_SUSPENDED:
Expand Down Expand Up @@ -2297,7 +2296,6 @@ print_status_trim(vdev_stat_t *vs, boolean_t verbose)
!vs->vs_scan_removing) {
char zbuf[1024];
char tbuf[256];
struct tm zaction_ts;

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

(void) localtime_r(&t, &zaction_ts);
(void) strftime(tbuf, sizeof (tbuf), "%c", &zaction_ts);
(void) ctime_r(&t, tbuf);
tbuf[24] = 0;

switch (vs->vs_trim_state) {
case VDEV_TRIM_SUSPENDED:
Expand Down Expand Up @@ -9898,12 +9896,11 @@ print_history_records(nvlist_t *nvhis, hist_cbdata_t *cb)

if (nvlist_exists(rec, ZPOOL_HIST_TIME)) {
time_t tsec;
struct tm t;

tsec = fnvlist_lookup_uint64(records[i],
ZPOOL_HIST_TIME);
(void) localtime_r(&tsec, &t);
(void) strftime(tbuf, sizeof (tbuf), "%F.%T", &t);
(void) ctime_r(&tsec, tbuf);
tbuf[24] = 0;
}

if (nvlist_exists(rec, ZPOOL_HIST_ELAPSED_NS)) {
Expand Down
6 changes: 4 additions & 2 deletions lib/libzfs/libzfs_pool.c
Original file line number Diff line number Diff line change
Expand Up @@ -1899,7 +1899,8 @@ zpool_rewind_exclaim(libzfs_handle_t *hdl, const char *name, boolean_t dryrun,
(void) nvlist_lookup_int64(nv, ZPOOL_CONFIG_REWIND_TIME, &loss);

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

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

0 comments on commit 9649565

Please sign in to comment.