diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2021-07-14 09:14:08 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-14 09:14:08 +0200 |
commit | e18f21e34924d02dd7c330a644149d89fcc38042 (patch) | |
tree | 28782cf9a88b12e13f57e10069a795c4b6998865 /src/shared | |
parent | network: update interface name stored in various network engines (diff) | |
parent | networkd: minor refactoring (diff) | |
download | systemd-e18f21e34924d02dd7c330a644149d89fcc38042.tar.xz systemd-e18f21e34924d02dd7c330a644149d89fcc38042.zip |
Merge pull request #20109 from keszybz/timestamp-macros
Add macros that define scratch buffer internally for timestamp/timespan formatting
Diffstat (limited to 'src/shared')
-rw-r--r-- | src/shared/bus-print-properties.c | 16 | ||||
-rw-r--r-- | src/shared/dissect-image.c | 21 | ||||
-rw-r--r-- | src/shared/format-table.c | 4 | ||||
-rw-r--r-- | src/shared/killall.c | 10 | ||||
-rw-r--r-- | src/shared/logs-show.c | 14 | ||||
-rw-r--r-- | src/shared/mount-setup.c | 3 | ||||
-rw-r--r-- | src/shared/selinux-util.c | 5 | ||||
-rw-r--r-- | src/shared/tpm2-util.c | 12 | ||||
-rw-r--r-- | src/shared/user-record-show.c | 121 | ||||
-rw-r--r-- | src/shared/utmp-wtmp.c | 3 | ||||
-rw-r--r-- | src/shared/varlink.c | 4 | ||||
-rw-r--r-- | src/shared/watchdog.c | 4 |
12 files changed, 77 insertions, 140 deletions
diff --git a/src/shared/bus-print-properties.c b/src/shared/bus-print-properties.c index b45921943a..4e401180e9 100644 --- a/src/shared/bus-print-properties.c +++ b/src/shared/bus-print-properties.c @@ -105,20 +105,14 @@ static int bus_print_property(const char *name, const char *expected_value, sd_b * should it turn out to not be sufficient */ if (endswith(name, "Timestamp") || - STR_IN_SET(name, "NextElapseUSecRealtime", "LastTriggerUSec", "TimeUSec", "RTCTimeUSec")) { - char timestamp[FORMAT_TIMESTAMP_MAX]; - const char *t; + STR_IN_SET(name, "NextElapseUSecRealtime", "LastTriggerUSec", "TimeUSec", "RTCTimeUSec")) - t = format_timestamp(timestamp, sizeof(timestamp), u); - bus_print_property_value(name, expected_value, flags, t); + bus_print_property_value(name, expected_value, flags, FORMAT_TIMESTAMP(u)); - } else if (strstr(name, "USec")) { - char timespan[FORMAT_TIMESPAN_MAX]; + else if (strstr(name, "USec")) + bus_print_property_value(name, expected_value, flags, FORMAT_TIMESPAN(u, 0)); - (void) format_timespan(timespan, sizeof(timespan), u, 0); - bus_print_property_value(name, expected_value, flags, timespan); - - } else if (streq(name, "CoredumpFilter")) + else if (streq(name, "CoredumpFilter")) bus_print_property_valuef(name, expected_value, flags, "0x%"PRIx64, u); else if (streq(name, "RestrictNamespaces")) { diff --git a/src/shared/dissect-image.c b/src/shared/dissect-image.c index c6542cec70..27b9ac9569 100644 --- a/src/shared/dissect-image.c +++ b/src/shared/dissect-image.c @@ -506,12 +506,11 @@ static int device_wait_for_initialization_harder( left = usec_sub_unsigned(deadline, start); if (DEBUG_LOGGING) { - char buf[FORMAT_TIMESPAN_MAX]; const char *sn = NULL; (void) sd_device_get_sysname(device, &sn); log_device_debug(device, - "Waiting for device '%s' to initialize for %s.", strna(sn), format_timespan(buf, sizeof(buf), left, 0)); + "Waiting for device '%s' to initialize for %s.", strna(sn), FORMAT_TIMESPAN(left, 0)); } if (left != USEC_INFINITY) @@ -538,26 +537,22 @@ static int device_wait_for_initialization_harder( r = device_wait_for_initialization(device, subsystem, local_deadline, ret); if (r >= 0 && DEBUG_LOGGING) { - char buf[FORMAT_TIMESPAN_MAX]; const char *sn = NULL; (void) sd_device_get_sysname(device, &sn); log_device_debug(device, "Successfully waited for device '%s' to initialize for %s.", strna(sn), - format_timespan(buf, sizeof(buf), usec_sub_unsigned(now(CLOCK_MONOTONIC), start), 0)); + FORMAT_TIMESPAN(usec_sub_unsigned(now(CLOCK_MONOTONIC), start), 0)); } if (r != -ETIMEDOUT || last_try) return r; - if (DEBUG_LOGGING) { - char buf[FORMAT_TIMESPAN_MAX]; - + if (DEBUG_LOGGING) log_device_debug(device, "Device didn't initialize within %s, assuming lost event. Retriggering device.", - format_timespan(buf, sizeof(buf), usec_sub_unsigned(now(CLOCK_MONOTONIC), start), 0)); - } + FORMAT_TIMESPAN(usec_sub_unsigned(now(CLOCK_MONOTONIC), start), 0)); r = sd_device_trigger(device, SD_DEVICE_CHANGE); if (r < 0) @@ -1497,7 +1492,6 @@ static int run_fsck(const char *node, const char *fstype) { static int fs_grow(const char *node_path, const char *mount_path) { _cleanup_close_ int mount_fd = -1, node_fd = -1; - char fb[FORMAT_BYTES_MAX]; uint64_t size, newsize; int r; @@ -1519,14 +1513,11 @@ static int fs_grow(const char *node_path, const char *mount_path) { if (newsize == size) log_debug("Successfully resized \"%s\" to %s bytes.", - mount_path, - format_bytes(fb, sizeof fb, newsize)); + mount_path, FORMAT_BYTES(newsize)); else { assert(newsize < size); log_debug("Successfully resized \"%s\" to %s bytes (%"PRIu64" bytes lost due to blocksize).", - mount_path, - format_bytes(fb, sizeof fb, newsize), - size - newsize); + mount_path, FORMAT_BYTES(newsize), size - newsize); } return 0; diff --git a/src/shared/format-table.c b/src/shared/format-table.c index b298019d7c..6dca6661e1 100644 --- a/src/shared/format-table.c +++ b/src/shared/format-table.c @@ -1441,7 +1441,7 @@ static const char *table_data_format(Table *t, TableData *d, bool avoid_uppercas _cleanup_free_ char *p = NULL; char *ret; - p = new(char, FORMAT_TIMESTAMP_MAX); + p = new(char, d->type == TABLE_TIMESTAMP_RELATIVE ? FORMAT_TIMESTAMP_RELATIVE_MAX : FORMAT_TIMESTAMP_MAX); if (!p) return NULL; @@ -1450,7 +1450,7 @@ static const char *table_data_format(Table *t, TableData *d, bool avoid_uppercas else if (d->type == TABLE_TIMESTAMP_UTC) ret = format_timestamp_style(p, FORMAT_TIMESTAMP_MAX, d->timestamp, TIMESTAMP_UTC); else - ret = format_timestamp_relative(p, FORMAT_TIMESTAMP_MAX, d->timestamp); + ret = format_timestamp_relative(p, FORMAT_TIMESTAMP_RELATIVE_MAX, d->timestamp); if (!ret) return "n/a"; diff --git a/src/shared/killall.c b/src/shared/killall.c index d9fcfc21a9..869955a58f 100644 --- a/src/shared/killall.c +++ b/src/shared/killall.c @@ -17,6 +17,7 @@ #include "parse-util.h" #include "process-util.h" #include "set.h" +#include "stdio-util.h" #include "string-util.h" #include "terminal-util.h" #include "util.h" @@ -83,14 +84,13 @@ static void log_children_no_yet_killed(Set *pids) { SET_FOREACH(p, pids) { _cleanup_free_ char *s = NULL; + char fallback[DECIMAL_STR_MAX(pid_t)]; if (get_process_comm(PTR_TO_PID(p), &s) < 0) - (void) asprintf(&s, PID_FMT, PTR_TO_PID(p)); + xsprintf(fallback, PID_FMT, PTR_TO_PID(p)); - if (!strextend(&lst_child, ", ", s)) { - log_oom(); - return; - } + if (!strextend(&lst_child, ", ", s ?: fallback)) + return (void) log_oom(); } if (isempty(lst_child)) diff --git a/src/shared/logs-show.c b/src/shared/logs-show.c index e63c59bd94..3165cf29da 100644 --- a/src/shared/logs-show.c +++ b/src/shared/logs-show.c @@ -579,10 +579,9 @@ static int output_short( } } - if (!(flags & OUTPUT_SHOW_ALL) && !utf8_is_printable(message, message_len)) { - char bytes[FORMAT_BYTES_MAX]; - fprintf(f, "[%s blob data]\n", format_bytes(bytes, sizeof(bytes), message_len)); - } else { + if (!(flags & OUTPUT_SHOW_ALL) && !utf8_is_printable(message, message_len)) + fprintf(f, "[%s blob data]\n", FORMAT_BYTES(message_len)); + else { /* URLify config_file string in message, if the message starts with it. * Skip URLification if the highlighted pattern overlaps. */ @@ -726,16 +725,13 @@ static int output_verbose( p, valuelen, NULL); fputs(off, f); - } else { - char bytes[FORMAT_BYTES_MAX]; - + } else fprintf(f, " %s%.*s=[%s blob data]%s\n", on, (int) (c - (const char*) data), (const char*) data, - format_bytes(bytes, sizeof(bytes), length - (c - (const char *) data) - 1), + FORMAT_BYTES(length - (c - (const char *) data) - 1), off); - } } if (r < 0) diff --git a/src/shared/mount-setup.c b/src/shared/mount-setup.c index ef3527e9a7..3b30982835 100644 --- a/src/shared/mount-setup.c +++ b/src/shared/mount-setup.c @@ -499,7 +499,6 @@ int mount_setup(bool loaded_policy, bool leave_propagation) { * use the same label for all their files. */ if (loaded_policy) { usec_t before_relabel, after_relabel; - char timespan[FORMAT_TIMESPAN_MAX]; const char *i; int n_extra; @@ -516,7 +515,7 @@ int mount_setup(bool loaded_policy, bool leave_propagation) { log_info("Relabelled /dev, /dev/shm, /run, /sys/fs/cgroup%s in %s.", n_extra > 0 ? ", additional files" : "", - format_timespan(timespan, sizeof(timespan), after_relabel - before_relabel, 0)); + FORMAT_TIMESPAN(after_relabel - before_relabel, 0)); } #endif diff --git a/src/shared/selinux-util.c b/src/shared/selinux-util.c index 03cee76f64..e4890e8170 100644 --- a/src/shared/selinux-util.c +++ b/src/shared/selinux-util.c @@ -115,7 +115,6 @@ REENABLE_WARNING static int open_label_db(void) { struct selabel_handle *hnd; usec_t before_timestamp, after_timestamp; - char timespan[FORMAT_TIMESPAN_MAX]; # if HAVE_GENERIC_MALLINFO generic_mallinfo before_mallinfo = generic_mallinfo_get(); @@ -131,11 +130,11 @@ static int open_label_db(void) { generic_mallinfo after_mallinfo = generic_mallinfo_get(); size_t l = LESS_BY((size_t) after_mallinfo.uordblks, (size_t) before_mallinfo.uordblks); log_debug("Successfully loaded SELinux database in %s, size on heap is %zuK.", - format_timespan(timespan, sizeof(timespan), after_timestamp - before_timestamp, 0), + FORMAT_TIMESPAN(after_timestamp - before_timestamp, 0), DIV_ROUND_UP(l, 1024)); # else log_debug("Successfully loaded SELinux database in %s.", - format_timespan(timespan, sizeof(timespan), after_timestamp - before_timestamp, 0)); + FORMAT_TIMESPAN(after_timestamp - before_timestamp, 0)); # endif /* release memory after measurement */ diff --git a/src/shared/tpm2-util.c b/src/shared/tpm2-util.c index df6d2eef58..79e879b482 100644 --- a/src/shared/tpm2-util.c +++ b/src/shared/tpm2-util.c @@ -591,10 +591,8 @@ int tpm2_seal( if (!hash) return log_oom(); - if (DEBUG_LOGGING) { - char buf[FORMAT_TIMESPAN_MAX]; - log_debug("Completed TPM2 key sealing in %s.", format_timespan(buf, sizeof(buf), now(CLOCK_MONOTONIC) - start, 1)); - } + if (DEBUG_LOGGING) + log_debug("Completed TPM2 key sealing in %s.", FORMAT_TIMESPAN(now(CLOCK_MONOTONIC) - start, 1)); *ret_secret = TAKE_PTR(secret); *ret_secret_size = hmac_sensitive.sensitive.data.size; @@ -726,10 +724,8 @@ int tpm2_unseal( goto finish; } - if (DEBUG_LOGGING) { - char buf[FORMAT_TIMESPAN_MAX]; - log_debug("Completed TPM2 key unsealing in %s.", format_timespan(buf, sizeof(buf), now(CLOCK_MONOTONIC) - start, 1)); - } + if (DEBUG_LOGGING) + log_debug("Completed TPM2 key unsealing in %s.", FORMAT_TIMESPAN(now(CLOCK_MONOTONIC) - start, 1)); *ret_secret = TAKE_PTR(secret); *ret_secret_size = unsealed->size; diff --git a/src/shared/user-record-show.c b/src/shared/user-record-show.c index 29790282b4..29aa5c0c7c 100644 --- a/src/shared/user-record-show.c +++ b/src/shared/user-record-show.c @@ -43,8 +43,7 @@ void user_record_show(UserRecord *hr, bool show_full_group_info) { printf(" Disposition: %s\n", user_disposition_to_string(user_record_disposition(hr))); if (hr->last_change_usec != USEC_INFINITY) { - char buf[FORMAT_TIMESTAMP_MAX]; - printf(" Last Change: %s\n", format_timestamp(buf, sizeof(buf), hr->last_change_usec)); + printf(" Last Change: %s\n", FORMAT_TIMESTAMP(hr->last_change_usec)); if (hr->last_change_usec > now(CLOCK_REALTIME)) printf(" %sModification time lies in the future, system clock wrong?%s\n", @@ -52,10 +51,8 @@ void user_record_show(UserRecord *hr, bool show_full_group_info) { } if (hr->last_password_change_usec != USEC_INFINITY && - hr->last_password_change_usec != hr->last_change_usec) { - char buf[FORMAT_TIMESTAMP_MAX]; - printf(" Last Passw.: %s\n", format_timestamp(buf, sizeof(buf), hr->last_password_change_usec)); - } + hr->last_password_change_usec != hr->last_change_usec) + printf(" Last Passw.: %s\n", FORMAT_TIMESTAMP(hr->last_password_change_usec)); r = user_record_test_blocked(hr); switch (r) { @@ -238,15 +235,11 @@ void user_record_show(UserRecord *hr, bool show_full_group_info) { if (hr->locked >= 0) printf(" Locked: %s\n", yes_no(hr->locked)); - if (hr->not_before_usec != UINT64_MAX) { - char buf[FORMAT_TIMESTAMP_MAX]; - printf(" Not Before: %s\n", format_timestamp(buf, sizeof(buf), hr->not_before_usec)); - } + if (hr->not_before_usec != UINT64_MAX) + printf(" Not Before: %s\n", FORMAT_TIMESTAMP(hr->not_before_usec)); - if (hr->not_after_usec != UINT64_MAX) { - char buf[FORMAT_TIMESTAMP_MAX]; - printf(" Not After: %s\n", format_timestamp(buf, sizeof(buf), hr->not_after_usec)); - } + if (hr->not_after_usec != UINT64_MAX) + printf(" Not After: %s\n", FORMAT_TIMESTAMP(hr->not_after_usec)); if (hr->umask != MODE_INVALID) printf(" UMask: 0%03o\n", hr->umask); @@ -263,15 +256,11 @@ void user_record_show(UserRecord *hr, bool show_full_group_info) { if (hr->tasks_max != UINT64_MAX) printf(" Tasks Max: %" PRIu64 "\n", hr->tasks_max); - if (hr->memory_high != UINT64_MAX) { - char buf[FORMAT_BYTES_MAX]; - printf(" Memory High: %s\n", format_bytes(buf, sizeof(buf), hr->memory_high)); - } + if (hr->memory_high != UINT64_MAX) + printf(" Memory High: %s\n", FORMAT_BYTES(hr->memory_high)); - if (hr->memory_max != UINT64_MAX) { - char buf[FORMAT_BYTES_MAX]; - printf(" Memory Max: %s\n", format_bytes(buf, sizeof(buf), hr->memory_max)); - } + if (hr->memory_max != UINT64_MAX) + printf(" Memory Max: %s\n", FORMAT_BYTES(hr->memory_max)); if (hr->cpu_weight != UINT64_MAX) printf(" CPU Weight: %" PRIu64 "\n", hr->cpu_weight); @@ -306,14 +295,11 @@ void user_record_show(UserRecord *hr, bool show_full_group_info) { printf(" PBKDF Type: %s\n", hr->luks_pbkdf_type); if (hr->luks_pbkdf_hash_algorithm) printf(" PBKDF Hash: %s\n", hr->luks_pbkdf_hash_algorithm); - if (hr->luks_pbkdf_time_cost_usec != UINT64_MAX) { - char buf[FORMAT_TIMESPAN_MAX]; - printf(" PBKDF Time: %s\n", format_timespan(buf, sizeof(buf), hr->luks_pbkdf_time_cost_usec, 0)); - } - if (hr->luks_pbkdf_memory_cost != UINT64_MAX) { - char buf[FORMAT_BYTES_MAX]; - printf(" PBKDF Bytes: %s\n", format_bytes(buf, sizeof(buf), hr->luks_pbkdf_memory_cost)); - } + if (hr->luks_pbkdf_time_cost_usec != UINT64_MAX) + printf(" PBKDF Time: %s\n", FORMAT_TIMESPAN(hr->luks_pbkdf_time_cost_usec, 0)); + if (hr->luks_pbkdf_memory_cost != UINT64_MAX) + printf(" PBKDF Bytes: %s\n", FORMAT_BYTES(hr->luks_pbkdf_memory_cost)); + if (hr->luks_pbkdf_parallel_threads != UINT64_MAX) printf("PBKDF Thread: %" PRIu64 "\n", hr->luks_pbkdf_parallel_threads); @@ -337,28 +323,22 @@ void user_record_show(UserRecord *hr, bool show_full_group_info) { if (hr->skeleton_directory) printf(" Skel. Dir.: %s\n", user_record_skeleton_directory(hr)); - if (hr->disk_size != UINT64_MAX) { - char buf[FORMAT_BYTES_MAX]; - printf(" Disk Size: %s\n", format_bytes(buf, sizeof(buf), hr->disk_size)); - } + if (hr->disk_size != UINT64_MAX) + printf(" Disk Size: %s\n", FORMAT_BYTES(hr->disk_size)); if (hr->disk_usage != UINT64_MAX) { - char buf[FORMAT_BYTES_MAX]; - if (hr->disk_size != UINT64_MAX) { unsigned permille; permille = (unsigned) DIV_ROUND_UP(hr->disk_usage * 1000U, hr->disk_size); /* Round up! */ printf(" Disk Usage: %s (= %u.%01u%%)\n", - format_bytes(buf, sizeof(buf), hr->disk_usage), + FORMAT_BYTES(hr->disk_usage), permille / 10, permille % 10); } else - printf(" Disk Usage: %s\n", format_bytes(buf, sizeof(buf), hr->disk_usage)); + printf(" Disk Usage: %s\n", FORMAT_BYTES(hr->disk_usage)); } if (hr->disk_free != UINT64_MAX) { - char buf[FORMAT_BYTES_MAX]; - if (hr->disk_size != UINT64_MAX) { const char *color_on, *color_off; unsigned permille; @@ -381,38 +361,30 @@ void user_record_show(UserRecord *hr, bool show_full_group_info) { printf(" Disk Free: %s%s (= %u.%01u%%)%s\n", color_on, - format_bytes(buf, sizeof(buf), hr->disk_free), + FORMAT_BYTES(hr->disk_free), permille / 10, permille % 10, color_off); } else - printf(" Disk Free: %s\n", format_bytes(buf, sizeof(buf), hr->disk_free)); + printf(" Disk Free: %s\n", FORMAT_BYTES(hr->disk_free)); } - if (hr->disk_floor != UINT64_MAX) { - char buf[FORMAT_BYTES_MAX]; - printf(" Disk Floor: %s\n", format_bytes(buf, sizeof(buf), hr->disk_floor)); - } + if (hr->disk_floor != UINT64_MAX) + printf(" Disk Floor: %s\n", FORMAT_BYTES(hr->disk_floor)); - if (hr->disk_ceiling != UINT64_MAX) { - char buf[FORMAT_BYTES_MAX]; - printf("Disk Ceiling: %s\n", format_bytes(buf, sizeof(buf), hr->disk_ceiling)); - } + if (hr->disk_ceiling != UINT64_MAX) + printf("Disk Ceiling: %s\n", FORMAT_BYTES(hr->disk_ceiling)); if (hr->good_authentication_counter != UINT64_MAX) printf(" Good Auth.: %" PRIu64 "\n", hr->good_authentication_counter); - if (hr->last_good_authentication_usec != UINT64_MAX) { - char buf[FORMAT_TIMESTAMP_MAX]; - printf(" Last Good: %s\n", format_timestamp(buf, sizeof(buf), hr->last_good_authentication_usec)); - } + if (hr->last_good_authentication_usec != UINT64_MAX) + printf(" Last Good: %s\n", FORMAT_TIMESTAMP(hr->last_good_authentication_usec)); if (hr->bad_authentication_counter != UINT64_MAX) printf(" Bad Auth.: %" PRIu64 "\n", hr->bad_authentication_counter); - if (hr->last_bad_authentication_usec != UINT64_MAX) { - char buf[FORMAT_TIMESTAMP_MAX]; - printf(" Last Bad: %s\n", format_timestamp(buf, sizeof(buf), hr->last_bad_authentication_usec)); - } + if (hr->last_bad_authentication_usec != UINT64_MAX) + printf(" Last Bad: %s\n", FORMAT_TIMESTAMP(hr->last_bad_authentication_usec)); t = user_record_ratelimit_next_try(hr); if (t != USEC_INFINITY) { @@ -420,20 +392,16 @@ void user_record_show(UserRecord *hr, bool show_full_group_info) { if (t <= n) printf(" Next Try: anytime\n"); - else { - char buf[FORMAT_TIMESPAN_MAX]; + else printf(" Next Try: %sin %s%s\n", ansi_highlight_red(), - format_timespan(buf, sizeof(buf), t - n, USEC_PER_SEC), + FORMAT_TIMESPAN(t - n, USEC_PER_SEC), ansi_normal()); - } } - if (storage != USER_CLASSIC) { - char buf[FORMAT_TIMESPAN_MAX]; + if (storage != USER_CLASSIC) printf(" Auth. Limit: %" PRIu64 " attempts per %s\n", user_record_ratelimit_burst(hr), - format_timespan(buf, sizeof(buf), user_record_ratelimit_interval_usec(hr), 0)); - } + FORMAT_TIMESPAN(user_record_ratelimit_interval_usec(hr), 0)); if (hr->enforce_password_policy >= 0) printf(" Passwd Pol.: %s\n", yes_no(hr->enforce_password_policy)); @@ -443,24 +411,23 @@ void user_record_show(UserRecord *hr, bool show_full_group_info) { hr->password_change_warn_usec != UINT64_MAX || hr->password_change_inactive_usec != UINT64_MAX) { - char buf[FORMAT_TIMESPAN_MAX]; printf(" Passwd Chg.:"); if (hr->password_change_min_usec != UINT64_MAX) { - printf(" min %s", format_timespan(buf, sizeof(buf), hr->password_change_min_usec, 0)); + printf(" min %s", FORMAT_TIMESPAN(hr->password_change_min_usec, 0)); if (hr->password_change_max_usec != UINT64_MAX) printf(" …"); } if (hr->password_change_max_usec != UINT64_MAX) - printf(" max %s", format_timespan(buf, sizeof(buf), hr->password_change_max_usec, 0)); + printf(" max %s", FORMAT_TIMESPAN(hr->password_change_max_usec, 0)); if (hr->password_change_warn_usec != UINT64_MAX) - printf("/warn %s", format_timespan(buf, sizeof(buf), hr->password_change_warn_usec, 0)); + printf("/warn %s", FORMAT_TIMESPAN(hr->password_change_warn_usec, 0)); if (hr->password_change_inactive_usec != UINT64_MAX) - printf("/inactive %s", format_timespan(buf, sizeof(buf), hr->password_change_inactive_usec, 0)); + printf("/inactive %s", FORMAT_TIMESPAN(hr->password_change_inactive_usec, 0)); printf("\n"); } @@ -496,10 +463,8 @@ void user_record_show(UserRecord *hr, bool show_full_group_info) { if (hr->signed_locally >= 0) printf(" Local Sig.: %s\n", yes_no(hr->signed_locally)); - if (hr->stop_delay_usec != UINT64_MAX) { - char buf[FORMAT_TIMESPAN_MAX]; - printf(" Stop Delay: %s\n", format_timespan(buf, sizeof(buf), hr->stop_delay_usec, 0)); - } + if (hr->stop_delay_usec != UINT64_MAX) + printf(" Stop Delay: %s\n", FORMAT_TIMESPAN(hr->stop_delay_usec, 0)); if (hr->auto_login >= 0) printf("Autom. Login: %s\n", yes_no(hr->auto_login)); @@ -519,10 +484,8 @@ void group_record_show(GroupRecord *gr, bool show_full_user_info) { printf(" Disposition: %s\n", user_disposition_to_string(group_record_disposition(gr))); - if (gr->last_change_usec != USEC_INFINITY) { - char buf[FORMAT_TIMESTAMP_MAX]; - printf(" Last Change: %s\n", format_timestamp(buf, sizeof(buf), gr->last_change_usec)); - } + if (gr->last_change_usec != USEC_INFINITY) + printf(" Last Change: %s\n", FORMAT_TIMESTAMP(gr->last_change_usec)); if (gid_is_valid(gr->gid)) printf(" GID: " GID_FMT "\n", gr->gid); diff --git a/src/shared/utmp-wtmp.c b/src/shared/utmp-wtmp.c index 3eeee24693..b31cdd679b 100644 --- a/src/shared/utmp-wtmp.c +++ b/src/shared/utmp-wtmp.c @@ -340,7 +340,6 @@ int utmp_wall( void *userdata) { _cleanup_free_ char *text = NULL, *hn = NULL, *un = NULL, *stdin_tty = NULL; - char date[FORMAT_TIMESTAMP_MAX]; struct utmpx *u; int r; @@ -364,7 +363,7 @@ int utmp_wall( "%s\r\n\r\n", un ?: username, hn, origin_tty ? " on " : "", strempty(origin_tty), - format_timestamp(date, sizeof(date), now(CLOCK_REALTIME)), + FORMAT_TIMESTAMP(now(CLOCK_REALTIME)), message) < 0) return -ENOMEM; diff --git a/src/shared/varlink.c b/src/shared/varlink.c index 6b0b343ae9..3a53c16a72 100644 --- a/src/shared/varlink.c +++ b/src/shared/varlink.c @@ -2145,7 +2145,9 @@ int varlink_server_add_connection(VarlinkServer *server, int fd, Varlink **ret) v->ucred_acquired = true; } - (void) asprintf(&v->description, "%s-%i", server->description ?: "varlink", v->fd); + _cleanup_free_ char *desc = NULL; + if (asprintf(&desc, "%s-%i", server->description ?: "varlink", v->fd) >= 0) + v->description = TAKE_PTR(desc); /* Link up the server and the connection, and take reference in both directions. Note that the * reference on the connection is left dangling. It will be dropped when the connection is closed, diff --git a/src/shared/watchdog.c b/src/shared/watchdog.c index d33acafe64..361d5837dc 100644 --- a/src/shared/watchdog.c +++ b/src/shared/watchdog.c @@ -32,7 +32,6 @@ static int update_timeout(void) { if (ioctl(watchdog_fd, WDIOC_SETOPTIONS, &flags) < 0) return log_warning_errno(errno, "Failed to disable hardware watchdog: %m"); } else { - char buf[FORMAT_TIMESPAN_MAX]; int sec, flags; usec_t t; @@ -41,8 +40,7 @@ static int update_timeout(void) { if (ioctl(watchdog_fd, WDIOC_SETTIMEOUT, &sec) < 0) return log_warning_errno(errno, "Failed to set timeout to %is: %m", sec); - watchdog_timeout = (usec_t) sec * USEC_PER_SEC; - log_info("Set hardware watchdog to %s.", format_timespan(buf, sizeof(buf), watchdog_timeout, 0)); + log_info("Set hardware watchdog to %s.", FORMAT_TIMESPAN(sec * USEC_PER_SEC, 0)); flags = WDIOS_ENABLECARD; if (ioctl(watchdog_fd, WDIOC_SETOPTIONS, &flags) < 0) { |