1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-01-08 21:17:47 +03:00

tree-wide: add FORMAT_TIMESPAN()

This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2021-07-01 14:32:46 +02:00
parent 5e62ac8b51
commit 5291f26d4a
60 changed files with 203 additions and 378 deletions

View File

@ -479,7 +479,6 @@ manager:
}
static int pretty_boot_time(sd_bus *bus, char **_buf) {
char ts[FORMAT_TIMESPAN_MAX];
BootTimes *t;
static char buf[4096];
size_t size;
@ -524,23 +523,23 @@ static int pretty_boot_time(sd_bus *bus, char **_buf) {
size = strpcpyf(&ptr, size, "Startup finished in ");
if (t->firmware_time > 0)
size = strpcpyf(&ptr, size, "%s (firmware) + ", format_timespan(ts, sizeof(ts), t->firmware_time - t->loader_time, USEC_PER_MSEC));
size = strpcpyf(&ptr, size, "%s (firmware) + ", FORMAT_TIMESPAN(t->firmware_time - t->loader_time, USEC_PER_MSEC));
if (t->loader_time > 0)
size = strpcpyf(&ptr, size, "%s (loader) + ", format_timespan(ts, sizeof(ts), t->loader_time, USEC_PER_MSEC));
size = strpcpyf(&ptr, size, "%s (loader) + ", FORMAT_TIMESPAN(t->loader_time, USEC_PER_MSEC));
if (t->kernel_done_time > 0)
size = strpcpyf(&ptr, size, "%s (kernel) + ", format_timespan(ts, sizeof(ts), t->kernel_done_time, USEC_PER_MSEC));
size = strpcpyf(&ptr, size, "%s (kernel) + ", FORMAT_TIMESPAN(t->kernel_done_time, USEC_PER_MSEC));
if (t->initrd_time > 0)
size = strpcpyf(&ptr, size, "%s (initrd) + ", format_timespan(ts, sizeof(ts), t->userspace_time - t->initrd_time, USEC_PER_MSEC));
size = strpcpyf(&ptr, size, "%s (initrd) + ", FORMAT_TIMESPAN(t->userspace_time - t->initrd_time, USEC_PER_MSEC));
size = strpcpyf(&ptr, size, "%s (userspace) ", format_timespan(ts, sizeof(ts), t->finish_time - t->userspace_time, USEC_PER_MSEC));
size = strpcpyf(&ptr, size, "%s (userspace) ", FORMAT_TIMESPAN(t->finish_time - t->userspace_time, USEC_PER_MSEC));
if (t->kernel_done_time > 0)
strpcpyf(&ptr, size, "= %s ", format_timespan(ts, sizeof(ts), t->firmware_time + t->finish_time, USEC_PER_MSEC));
strpcpyf(&ptr, size, "= %s ", FORMAT_TIMESPAN(t->firmware_time + t->finish_time, USEC_PER_MSEC));
if (unit_id && timestamp_is_set(activated_time)) {
usec_t base = t->userspace_time > 0 ? t->userspace_time : t->reverse_offset;
size = strpcpyf(&ptr, size, "\n%s reached after %s in userspace", unit_id,
format_timespan(ts, sizeof(ts), activated_time - base, USEC_PER_MSEC));
FORMAT_TIMESPAN(activated_time - base, USEC_PER_MSEC));
} else if (unit_id && activated_time == 0)
size = strpcpyf(&ptr, size, "\n%s was never reached", unit_id);
else if (unit_id && activated_time == USEC_INFINITY)
@ -591,7 +590,6 @@ static void svg_graph_box(double height, double begin, double end) {
}
static int plot_unit_times(UnitTimes *u, double width, int y) {
char ts[FORMAT_TIMESPAN_MAX];
bool b;
if (!u->name)
@ -605,7 +603,7 @@ static int plot_unit_times(UnitTimes *u, double width, int y) {
b = u->activating * SCALE_X < width / 2;
if (u->time)
svg_text(b, u->activating, y, "%s (%s)",
u->name, format_timespan(ts, sizeof(ts), u->time, USEC_PER_MSEC));
u->name, FORMAT_TIMESPAN(u->time, USEC_PER_MSEC));
else
svg_text(b, u->activating, y, "%s", u->name);
@ -836,8 +834,6 @@ static int list_dependencies_print(
UnitTimes *times,
BootTimes *boot) {
char ts[FORMAT_TIMESPAN_MAX], ts2[FORMAT_TIMESPAN_MAX];
for (unsigned i = level; i != 0; i--)
printf("%s", special_glyph(branches & (1 << (i-1)) ? SPECIAL_GLYPH_TREE_VERTICAL : SPECIAL_GLYPH_TREE_SPACE));
@ -846,10 +842,10 @@ static int list_dependencies_print(
if (times) {
if (times->time > 0)
printf("%s%s @%s +%s%s", ansi_highlight_red(), name,
format_timespan(ts, sizeof(ts), times->activating - boot->userspace_time, USEC_PER_MSEC),
format_timespan(ts2, sizeof(ts2), times->time, USEC_PER_MSEC), ansi_normal());
FORMAT_TIMESPAN(times->activating - boot->userspace_time, USEC_PER_MSEC),
FORMAT_TIMESPAN(times->time, USEC_PER_MSEC), ansi_normal());
else if (times->activated > boot->userspace_time)
printf("%s @%s", name, format_timespan(ts, sizeof(ts), times->activated - boot->userspace_time, USEC_PER_MSEC));
printf("%s @%s", name, FORMAT_TIMESPAN(times->activated - boot->userspace_time, USEC_PER_MSEC));
else
printf("%s", name);
} else
@ -964,7 +960,6 @@ static int list_dependencies_one(sd_bus *bus, const char *name, unsigned level,
static int list_dependencies(sd_bus *bus, const char *name) {
_cleanup_strv_free_ char **units = NULL;
char ts[FORMAT_TIMESPAN_MAX];
UnitTimes *times;
int r;
const char *id;
@ -1004,9 +999,10 @@ static int list_dependencies(sd_bus *bus, const char *name) {
if (times) {
if (times->time)
printf("%s%s +%s%s\n", ansi_highlight_red(), id,
format_timespan(ts, sizeof(ts), times->time, USEC_PER_MSEC), ansi_normal());
FORMAT_TIMESPAN(times->time, USEC_PER_MSEC), ansi_normal());
else if (times->activated > boot->userspace_time)
printf("%s @%s\n", id, format_timespan(ts, sizeof(ts), times->activated - boot->userspace_time, USEC_PER_MSEC));
printf("%s @%s\n", id,
FORMAT_TIMESPAN(times->activated - boot->userspace_time, USEC_PER_MSEC));
else
printf("%s\n", id);
}

View File

@ -120,13 +120,10 @@ int efi_get_variable(
n = st.st_size - 4;
if (DEBUG_LOGGING) {
char ts[FORMAT_TIMESPAN_MAX];
usec_t end;
end = now(CLOCK_MONOTONIC);
usec_t end = now(CLOCK_MONOTONIC);
if (end > begin + EFI_RETRY_DELAY)
log_debug("Detected slow EFI variable read access on %s: %s",
variable, format_timespan(ts, sizeof(ts), end - begin, 1));
variable, FORMAT_TIMESPAN(end - begin, 1));
}
/* Note that efivarfs interestingly doesn't require ftruncate() to update an existing EFI variable

View File

@ -129,6 +129,7 @@ static inline char* format_timestamp(char *buf, size_t l, usec_t t) {
* see C11 §6.5.2.5, and
* https://stackoverflow.com/questions/34880638/compound-literal-lifetime-and-if-blocks */
#define FORMAT_TIMESTAMP(t) format_timestamp((char[FORMAT_TIMESTAMP_MAX]){}, FORMAT_TIMESTAMP_MAX, t)
#define FORMAT_TIMESPAN(t, accuracy) format_timespan((char[FORMAT_TIMESPAN_MAX]){}, FORMAT_TIMESPAN_MAX, t, accuracy)
int parse_timestamp(const char *t, usec_t *usec);

View File

@ -949,7 +949,6 @@ static int run(int argc, char *argv[]) {
while (!quit) {
usec_t t;
char key;
char h[FORMAT_TIMESPAN_MAX];
t = now(CLOCK_MONOTONIC);
@ -1055,7 +1054,7 @@ static int run(int argc, char *argv[]) {
case '+':
arg_delay = usec_add(arg_delay, arg_delay < USEC_PER_SEC ? USEC_PER_MSEC * 250 : USEC_PER_SEC);
fprintf(stdout, "\nIncreased delay to %s.", format_timespan(h, sizeof(h), arg_delay, 0));
fprintf(stdout, "\nIncreased delay to %s.", FORMAT_TIMESPAN(arg_delay, 0));
fflush(stdout);
sleep(1);
break;
@ -1066,7 +1065,7 @@ static int run(int argc, char *argv[]) {
else
arg_delay = usec_sub_unsigned(arg_delay, arg_delay < USEC_PER_MSEC * 1250 ? USEC_PER_MSEC * 250 : USEC_PER_SEC);
fprintf(stdout, "\nDecreased delay to %s.", format_timespan(h, sizeof(h), arg_delay, 0));
fprintf(stdout, "\nDecreased delay to %s.", FORMAT_TIMESPAN(arg_delay, 0));
fflush(stdout);
sleep(1);
break;

View File

@ -305,7 +305,6 @@ static int automount_coldplug(Unit *u) {
}
static void automount_dump(Unit *u, FILE *f, const char *prefix) {
char time_string[FORMAT_TIMESPAN_MAX];
Automount *a = AUTOMOUNT(u);
assert(a);
@ -320,7 +319,7 @@ static void automount_dump(Unit *u, FILE *f, const char *prefix) {
prefix, automount_result_to_string(a->result),
prefix, a->where,
prefix, a->directory_mode,
prefix, format_timespan(time_string, FORMAT_TIMESPAN_MAX, a->timeout_idle_usec, USEC_PER_SEC));
prefix, FORMAT_TIMESPAN(a->timeout_idle_usec, USEC_PER_SEC));
}
static void automount_enter_dead(Automount *a, AutomountResult f) {

View File

@ -394,8 +394,6 @@ void cgroup_context_dump(Unit *u, FILE* f, const char *prefix) {
CGroupSocketBindItem *bi;
IPAddressAccessItem *iaai;
char **path;
char q[FORMAT_TIMESPAN_MAX];
char v[FORMAT_TIMESPAN_MAX];
char cda[FORMAT_CGROUP_DIFF_MAX];
char cdb[FORMAT_CGROUP_DIFF_MAX];
@ -460,8 +458,8 @@ void cgroup_context_dump(Unit *u, FILE* f, const char *prefix) {
prefix, c->startup_cpu_weight,
prefix, c->cpu_shares,
prefix, c->startup_cpu_shares,
prefix, format_timespan(q, sizeof(q), c->cpu_quota_per_sec_usec, 1),
prefix, format_timespan(v, sizeof(v), c->cpu_quota_period_usec, 1),
prefix, FORMAT_TIMESPAN(c->cpu_quota_per_sec_usec, 1),
prefix, FORMAT_TIMESPAN(c->cpu_quota_period_usec, 1),
prefix, strempty(cpuset_cpus),
prefix, strempty(cpuset_mems),
prefix, c->io_weight,
@ -514,7 +512,7 @@ void cgroup_context_dump(Unit *u, FILE* f, const char *prefix) {
"%sIODeviceLatencyTargetSec: %s %s\n",
prefix,
l->path,
format_timespan(q, sizeof(q), l->target_usec, 1));
FORMAT_TIMESPAN(l->target_usec, 1));
LIST_FOREACH(device_limits, il, c->io_device_limits) {
char buf[FORMAT_BYTES_MAX];
@ -869,10 +867,9 @@ static usec_t cgroup_cpu_adjust_period_and_log(Unit *u, usec_t period, usec_t qu
new_period = cgroup_cpu_adjust_period(period, quota, USEC_PER_MSEC, USEC_PER_SEC);
if (new_period != period) {
char v[FORMAT_TIMESPAN_MAX];
log_unit_full(u, u->warned_clamping_cpu_quota_period ? LOG_DEBUG : LOG_WARNING,
"Clamping CPU interval for cpu.max: period is now %s",
format_timespan(v, sizeof(v), new_period, 1));
FORMAT_TIMESPAN(new_period, 1));
u->warned_clamping_cpu_quota_period = true;
}

View File

@ -1114,12 +1114,10 @@ int bus_cgroup_set_property(
unit_invalidate_cgroup(u, CGROUP_MASK_CPU);
if (c->cpu_quota_period_usec == USEC_INFINITY)
unit_write_setting(u, flags, "CPUQuotaPeriodSec", "CPUQuotaPeriodSec=");
else {
char v[FORMAT_TIMESPAN_MAX];
else
unit_write_settingf(u, flags, "CPUQuotaPeriodSec",
"CPUQuotaPeriodSec=%s",
format_timespan(v, sizeof(v), c->cpu_quota_period_usec, 1));
}
FORMAT_TIMESPAN(c->cpu_quota_period_usec, 1));
}
return 1;
@ -1374,7 +1372,6 @@ int bus_cgroup_set_property(
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
_cleanup_free_ char *buf = NULL;
_cleanup_fclose_ FILE *f = NULL;
char ts[FORMAT_TIMESPAN_MAX];
CGroupIODeviceLatency *a;
size_t size = 0;
@ -1392,7 +1389,7 @@ int bus_cgroup_set_property(
fputs("IODeviceLatencyTargetSec=\n", f);
LIST_FOREACH(device_latencies, a, c->io_device_latencies)
fprintf(f, "IODeviceLatencyTargetSec=%s %s\n",
a->path, format_timespan(ts, sizeof(ts), a->target_usec, 1));
a->path, FORMAT_TIMESPAN(a->target_usec, 1));
r = fflush_and_check(f);
if (r < 0)

View File

@ -147,13 +147,12 @@ static int timer_add_one_monotonic_spec(
sd_bus_error *error) {
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
char ts[FORMAT_TIMESPAN_MAX];
TimerValue *v;
unit_write_settingf(UNIT(t), flags|UNIT_ESCAPE_SPECIFIERS, name,
"%s=%s",
timer_base_to_string(base),
format_timespan(ts, sizeof ts, usec, USEC_PER_MSEC));
FORMAT_TIMESPAN(usec, USEC_PER_MSEC));
v = new(TimerValue, 1);
if (!v)

View File

@ -112,16 +112,13 @@ int bus_set_transient_usec_internal(
return r;
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
char *n, ts[FORMAT_TIMESPAN_MAX];
if (fix_0)
*p = v != 0 ? v: USEC_INFINITY;
else
*p = v;
n = strndupa(name, strlen(name) - 4);
unit_write_settingf(u, flags, name, "%sSec=%s", n,
format_timespan(ts, sizeof(ts), v, USEC_PER_MSEC));
char *n = strndupa(name, strlen(name) - 4);
unit_write_settingf(u, flags, name, "%sSec=%s", n, FORMAT_TIMESPAN(v, USEC_PER_MSEC));
}
return 1;

View File

@ -5286,7 +5286,7 @@ static void strv_dump(FILE* f, const char *prefix, const char *name, char **strv
}
void exec_context_dump(const ExecContext *c, FILE* f, const char *prefix) {
char **e, **d, buf_clean[FORMAT_TIMESPAN_MAX];
char **e, **d;
int r;
assert(c);
@ -5404,24 +5404,16 @@ void exec_context_dump(const ExecContext *c, FILE* f, const char *prefix) {
fprintf(f, "%s%s: %s\n", prefix, exec_directory_type_to_string(dt), *d);
}
fprintf(f,
"%sTimeoutCleanSec: %s\n",
prefix, format_timespan(buf_clean, sizeof(buf_clean), c->timeout_clean_usec, USEC_PER_SEC));
fprintf(f, "%sTimeoutCleanSec: %s\n", prefix, FORMAT_TIMESPAN(c->timeout_clean_usec, USEC_PER_SEC));
if (c->nice_set)
fprintf(f,
"%sNice: %i\n",
prefix, c->nice);
fprintf(f, "%sNice: %i\n", prefix, c->nice);
if (c->oom_score_adjust_set)
fprintf(f,
"%sOOMScoreAdjust: %i\n",
prefix, c->oom_score_adjust);
fprintf(f, "%sOOMScoreAdjust: %i\n", prefix, c->oom_score_adjust);
if (c->coredump_filter_set)
fprintf(f,
"%sCoredumpFilter: 0x%"PRIx64"\n",
prefix, c->coredump_filter);
fprintf(f, "%sCoredumpFilter: 0x%"PRIx64"\n", prefix, c->coredump_filter);
for (unsigned i = 0; i < RLIM_NLIMITS; i++)
if (c->rlimit[i]) {
@ -5544,13 +5536,10 @@ void exec_context_dump(const ExecContext *c, FILE* f, const char *prefix) {
fprintf(f, "%sLogLevelMax: %s\n", prefix, strna(t));
}
if (c->log_ratelimit_interval_usec > 0) {
char buf_timespan[FORMAT_TIMESPAN_MAX];
if (c->log_ratelimit_interval_usec > 0)
fprintf(f,
"%sLogRateLimitIntervalSec: %s\n",
prefix, format_timespan(buf_timespan, sizeof(buf_timespan), c->log_ratelimit_interval_usec, USEC_PER_SEC));
}
prefix, FORMAT_TIMESPAN(c->log_ratelimit_interval_usec, USEC_PER_SEC));
if (c->log_ratelimit_burst > 0)
fprintf(f, "%sLogRateLimitBurst: %u\n", prefix, c->log_ratelimit_burst);

View File

@ -2575,7 +2575,6 @@ int main(int argc, char *argv[]) {
char *switch_root_dir = NULL, *switch_root_init = NULL;
usec_t before_startup, after_startup;
static char systemd[] = "systemd";
char timespan[FORMAT_TIMESPAN_MAX];
const char *shutdown_verb = NULL, *error_message = NULL;
int r, retval = EXIT_FAILURE;
Manager *m = NULL;
@ -2867,7 +2866,7 @@ int main(int argc, char *argv[]) {
log_full(arg_action == ACTION_TEST ? LOG_INFO : LOG_DEBUG,
"Loaded units and determined initial transaction in %s.",
format_timespan(timespan, sizeof(timespan), after_startup - before_startup, 100 * USEC_PER_MSEC));
FORMAT_TIMESPAN(after_startup - before_startup, 100 * USEC_PER_MSEC));
if (arg_action == ACTION_TEST) {
manager_test_summary(m);

View File

@ -38,14 +38,13 @@ void manager_dump(Manager *m, FILE *f, const char *prefix) {
for (ManagerTimestamp q = 0; q < _MANAGER_TIMESTAMP_MAX; q++) {
const dual_timestamp *t = m->timestamps + q;
char buf[FORMAT_TIMESPAN_MAX];
if (dual_timestamp_is_set(t))
fprintf(f, "%sTimestamp %s: %s\n",
strempty(prefix),
manager_timestamp_to_string(q),
timestamp_is_set(t->realtime) ? FORMAT_TIMESTAMP(t->realtime) :
format_timespan(buf, sizeof buf, t->monotonic, 1));
FORMAT_TIMESPAN(t->monotonic, 1));
}
manager_dump_units(m, f, prefix);

View File

@ -205,7 +205,6 @@ static void manager_print_jobs_in_progress(Manager *m) {
unsigned counter = 0, print_nr;
char cylon[6 + CYLON_BUFFER_EXTRA + 1];
unsigned cylon_pos;
char time[FORMAT_TIMESPAN_MAX], limit[FORMAT_TIMESPAN_MAX] = "no limit";
uint64_t x;
assert(m);
@ -231,14 +230,11 @@ static void manager_print_jobs_in_progress(Manager *m) {
m->jobs_in_progress_iteration++;
if (m->n_running_jobs > 1) {
if (m->n_running_jobs > 1)
if (asprintf(&job_of_n, "(%u of %u) ", counter, m->n_running_jobs) < 0)
job_of_n = NULL;
}
format_timespan(time, sizeof(time), now(CLOCK_MONOTONIC) - j->begin_usec, 1*USEC_PER_SEC);
if (job_get_timeout(j, &x) > 0)
format_timespan(limit, sizeof(limit), x - j->begin_usec, 1*USEC_PER_SEC);
bool have_timeout = job_get_timeout(j, &x) > 0;
/* We want to use enough information for the user to identify previous lines talking about the same
* unit, but keep the message as short as possible. So if 'Starting foo.service' or 'Starting
@ -252,7 +248,8 @@ static void manager_print_jobs_in_progress(Manager *m) {
strempty(job_of_n),
job_type_to_string(j->type),
ident,
time, limit);
FORMAT_TIMESPAN(now(CLOCK_MONOTONIC) - j->begin_usec, 1*USEC_PER_SEC),
have_timeout ? FORMAT_TIMESPAN(x - j->begin_usec, 1*USEC_PER_SEC) : "no limit");
}
static int have_ask_password(void) {
@ -3905,14 +3902,12 @@ static void log_taint_string(Manager *m) {
}
static void manager_notify_finished(Manager *m) {
char userspace[FORMAT_TIMESPAN_MAX], initrd[FORMAT_TIMESPAN_MAX], kernel[FORMAT_TIMESPAN_MAX], sum[FORMAT_TIMESPAN_MAX];
usec_t firmware_usec, loader_usec, kernel_usec, initrd_usec, userspace_usec, total_usec;
if (MANAGER_IS_TEST_RUN(m))
return;
if (MANAGER_IS_SYSTEM(m) && detect_container() <= 0) {
char ts[FORMAT_TIMESPAN_MAX];
char buf[FORMAT_TIMESPAN_MAX + STRLEN(" (firmware) + ") + FORMAT_TIMESPAN_MAX + STRLEN(" (loader) + ")]
= {};
char *p = buf;
@ -3928,9 +3923,9 @@ static void manager_notify_finished(Manager *m) {
total_usec = m->timestamps[MANAGER_TIMESTAMP_FIRMWARE].monotonic + m->timestamps[MANAGER_TIMESTAMP_FINISH].monotonic;
if (firmware_usec > 0)
size = strpcpyf(&p, size, "%s (firmware) + ", format_timespan(ts, sizeof(ts), firmware_usec, USEC_PER_MSEC));
size = strpcpyf(&p, size, "%s (firmware) + ", FORMAT_TIMESPAN(firmware_usec, USEC_PER_MSEC));
if (loader_usec > 0)
size = strpcpyf(&p, size, "%s (loader) + ", format_timespan(ts, sizeof(ts), loader_usec, USEC_PER_MSEC));
size = strpcpyf(&p, size, "%s (loader) + ", FORMAT_TIMESPAN(loader_usec, USEC_PER_MSEC));
if (dual_timestamp_is_set(&m->timestamps[MANAGER_TIMESTAMP_INITRD])) {
@ -3945,10 +3940,10 @@ static void manager_notify_finished(Manager *m) {
"USERSPACE_USEC="USEC_FMT, userspace_usec,
LOG_MESSAGE("Startup finished in %s%s (kernel) + %s (initrd) + %s (userspace) = %s.",
buf,
format_timespan(kernel, sizeof(kernel), kernel_usec, USEC_PER_MSEC),
format_timespan(initrd, sizeof(initrd), initrd_usec, USEC_PER_MSEC),
format_timespan(userspace, sizeof(userspace), userspace_usec, USEC_PER_MSEC),
format_timespan(sum, sizeof(sum), total_usec, USEC_PER_MSEC)));
FORMAT_TIMESPAN(kernel_usec, USEC_PER_MSEC),
FORMAT_TIMESPAN(initrd_usec, USEC_PER_MSEC),
FORMAT_TIMESPAN(userspace_usec, USEC_PER_MSEC),
FORMAT_TIMESPAN(total_usec, USEC_PER_MSEC)));
} else {
/* The initrd-less case on bare-metal */
@ -3961,9 +3956,9 @@ static void manager_notify_finished(Manager *m) {
"USERSPACE_USEC="USEC_FMT, userspace_usec,
LOG_MESSAGE("Startup finished in %s%s (kernel) + %s (userspace) = %s.",
buf,
format_timespan(kernel, sizeof(kernel), kernel_usec, USEC_PER_MSEC),
format_timespan(userspace, sizeof(userspace), userspace_usec, USEC_PER_MSEC),
format_timespan(sum, sizeof(sum), total_usec, USEC_PER_MSEC)));
FORMAT_TIMESPAN(kernel_usec, USEC_PER_MSEC),
FORMAT_TIMESPAN(userspace_usec, USEC_PER_MSEC),
FORMAT_TIMESPAN(total_usec, USEC_PER_MSEC)));
}
} else {
/* The container and --user case */
@ -3974,7 +3969,7 @@ static void manager_notify_finished(Manager *m) {
"MESSAGE_ID=" SD_MESSAGE_USER_STARTUP_FINISHED_STR,
"USERSPACE_USEC="USEC_FMT, userspace_usec,
LOG_MESSAGE("Startup finished in %s.",
format_timespan(sum, sizeof(sum), total_usec, USEC_PER_MSEC)));
FORMAT_TIMESPAN(total_usec, USEC_PER_MSEC)));
}
bus_manager_send_finished(m, firmware_usec, loader_usec, kernel_usec, initrd_usec, userspace_usec, total_usec);
@ -3983,7 +3978,7 @@ static void manager_notify_finished(Manager *m) {
m->ready_sent ? "STATUS=Startup finished in %s."
: "READY=1\n"
"STATUS=Startup finished in %s.",
format_timespan(sum, sizeof(sum), total_usec, USEC_PER_MSEC));
FORMAT_TIMESPAN(total_usec, USEC_PER_MSEC));
m->ready_sent = true;
log_taint_string(m);

View File

@ -770,7 +770,6 @@ static int mount_coldplug(Unit *u) {
}
static void mount_dump(Unit *u, FILE *f, const char *prefix) {
char buf[FORMAT_TIMESPAN_MAX];
Mount *m = MOUNT(u);
MountParameters *p;
@ -811,7 +810,7 @@ static void mount_dump(Unit *u, FILE *f, const char *prefix) {
prefix, yes_no(m->lazy_unmount),
prefix, yes_no(m->force_unmount),
prefix, yes_no(m->read_write_only),
prefix, format_timespan(buf, sizeof(buf), m->timeout_usec, USEC_PER_SEC));
prefix, FORMAT_TIMESPAN(m->timeout_usec, USEC_PER_SEC));
if (m->control_pid > 0)
fprintf(f,

View File

@ -255,7 +255,6 @@ static int scope_coldplug(Unit *u) {
static void scope_dump(Unit *u, FILE *f, const char *prefix) {
Scope *s = SCOPE(u);
char buf_runtime[FORMAT_TIMESPAN_MAX];
assert(s);
assert(f);
@ -266,7 +265,7 @@ static void scope_dump(Unit *u, FILE *f, const char *prefix) {
"%sRuntimeMaxSec: %s\n",
prefix, scope_state_to_string(s->state),
prefix, scope_result_to_string(s->result),
prefix, format_timespan(buf_runtime, sizeof(buf_runtime), s->runtime_max_usec, USEC_PER_SEC));
prefix, FORMAT_TIMESPAN(s->runtime_max_usec, USEC_PER_SEC));
cgroup_context_dump(UNIT(s), f, prefix);
kill_context_dump(&s->kill_context, f, prefix);

View File

@ -64,7 +64,6 @@ int mac_selinux_setup(bool *loaded_policy) {
r = selinux_init_load_policy(&enforce);
if (r == 0) {
_cleanup_(mac_selinux_freep) char *label = NULL;
char timespan[FORMAT_TIMESPAN_MAX];
mac_selinux_retest();
@ -84,7 +83,7 @@ int mac_selinux_setup(bool *loaded_policy) {
after_load = now(CLOCK_MONOTONIC);
log_info("Successfully loaded SELinux policy in %s.",
format_timespan(timespan, sizeof(timespan), after_load - before_load, 0));
FORMAT_TIMESPAN(after_load - before_load, 0));
*loaded_policy = true;

View File

@ -768,8 +768,6 @@ static int service_load(Unit *u) {
}
static void service_dump(Unit *u, FILE *f, const char *prefix) {
char buf_restart[FORMAT_TIMESPAN_MAX], buf_start[FORMAT_TIMESPAN_MAX], buf_stop[FORMAT_TIMESPAN_MAX],
buf_runtime[FORMAT_TIMESPAN_MAX], buf_watchdog[FORMAT_TIMESPAN_MAX], buf_abort[FORMAT_TIMESPAN_MAX];
ServiceExecCommand c;
Service *s = SERVICE(u);
const char *prefix2;
@ -844,22 +842,22 @@ static void service_dump(Unit *u, FILE *f, const char *prefix) {
"%sTimeoutStopSec: %s\n"
"%sTimeoutStartFailureMode: %s\n"
"%sTimeoutStopFailureMode: %s\n",
prefix, format_timespan(buf_restart, sizeof(buf_restart), s->restart_usec, USEC_PER_SEC),
prefix, format_timespan(buf_start, sizeof(buf_start), s->timeout_start_usec, USEC_PER_SEC),
prefix, format_timespan(buf_stop, sizeof(buf_stop), s->timeout_stop_usec, USEC_PER_SEC),
prefix, FORMAT_TIMESPAN(s->restart_usec, USEC_PER_SEC),
prefix, FORMAT_TIMESPAN(s->timeout_start_usec, USEC_PER_SEC),
prefix, FORMAT_TIMESPAN(s->timeout_stop_usec, USEC_PER_SEC),
prefix, service_timeout_failure_mode_to_string(s->timeout_start_failure_mode),
prefix, service_timeout_failure_mode_to_string(s->timeout_stop_failure_mode));
if (s->timeout_abort_set)
fprintf(f,
"%sTimeoutAbortSec: %s\n",
prefix, format_timespan(buf_abort, sizeof(buf_abort), s->timeout_abort_usec, USEC_PER_SEC));
prefix, FORMAT_TIMESPAN(s->timeout_abort_usec, USEC_PER_SEC));
fprintf(f,
"%sRuntimeMaxSec: %s\n"
"%sWatchdogSec: %s\n",
prefix, format_timespan(buf_runtime, sizeof(buf_runtime), s->runtime_max_usec, USEC_PER_SEC),
prefix, format_timespan(buf_watchdog, sizeof(buf_watchdog), s->watchdog_usec, USEC_PER_SEC));
prefix, FORMAT_TIMESPAN(s->runtime_max_usec, USEC_PER_SEC),
prefix, FORMAT_TIMESPAN(s->watchdog_usec, USEC_PER_SEC));
kill_context_dump(&s->kill_context, f, prefix);
exec_context_dump(&s->exec_context, f, prefix);
@ -3892,12 +3890,11 @@ static int service_dispatch_timer(sd_event_source *source, usec_t usec, void *us
break;
case SERVICE_AUTO_RESTART:
if (s->restart_usec > 0) {
char buf_restart[FORMAT_TIMESPAN_MAX];
if (s->restart_usec > 0)
log_unit_debug(UNIT(s),
"Service RestartSec=%s expired, scheduling restart.",
format_timespan(buf_restart, sizeof buf_restart, s->restart_usec, USEC_PER_SEC));
} else
FORMAT_TIMESPAN(s->restart_usec, USEC_PER_SEC));
else
log_unit_debug(UNIT(s),
"Service has no hold-off time (RestartSec=0), scheduling restart.");
@ -3922,7 +3919,6 @@ static int service_dispatch_timer(sd_event_source *source, usec_t usec, void *us
static int service_dispatch_watchdog(sd_event_source *source, usec_t usec, void *userdata) {
Service *s = SERVICE(userdata);
char t[FORMAT_TIMESPAN_MAX];
usec_t watchdog_usec;
assert(s);
@ -3932,12 +3928,12 @@ static int service_dispatch_watchdog(sd_event_source *source, usec_t usec, void
if (UNIT(s)->manager->service_watchdogs) {
log_unit_error(UNIT(s), "Watchdog timeout (limit %s)!",
format_timespan(t, sizeof(t), watchdog_usec, 1));
FORMAT_TIMESPAN(watchdog_usec, 1));
service_enter_signal(s, SERVICE_STOP_WATCHDOG, SERVICE_FAILURE_WATCHDOG);
} else
log_unit_warning(UNIT(s), "Watchdog disabled! Ignoring watchdog timeout (limit %s)!",
format_timespan(t, sizeof(t), watchdog_usec, 1));
FORMAT_TIMESPAN(watchdog_usec, 1));
return 0;
}

View File

@ -563,7 +563,6 @@ _const_ static const char* listen_lookup(int family, int type) {
}
static void socket_dump(Unit *u, FILE *f, const char *prefix) {
char time_string[FORMAT_TIMESPAN_MAX];
SocketExecCommand c;
Socket *s = SOCKET(u);
SocketPort *p;
@ -723,12 +722,12 @@ static void socket_dump(Unit *u, FILE *f, const char *prefix) {
if (s->keep_alive_time > 0)
fprintf(f,
"%sKeepAliveTimeSec: %s\n",
prefix, format_timespan(time_string, FORMAT_TIMESPAN_MAX, s->keep_alive_time, USEC_PER_SEC));
prefix, FORMAT_TIMESPAN(s->keep_alive_time, USEC_PER_SEC));
if (s->keep_alive_interval > 0)
fprintf(f,
"%sKeepAliveIntervalSec: %s\n",
prefix, format_timespan(time_string, FORMAT_TIMESPAN_MAX, s->keep_alive_interval, USEC_PER_SEC));
prefix, FORMAT_TIMESPAN(s->keep_alive_interval, USEC_PER_SEC));
if (s->keep_alive_cnt > 0)
fprintf(f,
@ -738,7 +737,7 @@ static void socket_dump(Unit *u, FILE *f, const char *prefix) {
if (s->defer_accept > 0)
fprintf(f,
"%sDeferAcceptSec: %s\n",
prefix, format_timespan(time_string, FORMAT_TIMESPAN_MAX, s->defer_accept, USEC_PER_SEC));
prefix, FORMAT_TIMESPAN(s->defer_accept, USEC_PER_SEC));
LIST_FOREACH(port, p, s->ports) {
@ -774,7 +773,7 @@ static void socket_dump(Unit *u, FILE *f, const char *prefix) {
fprintf(f,
"%sTriggerLimitIntervalSec: %s\n"
"%sTriggerLimitBurst: %u\n",
prefix, format_timespan(time_string, FORMAT_TIMESPAN_MAX, s->trigger_limit.interval, USEC_PER_SEC),
prefix, FORMAT_TIMESPAN(s->trigger_limit.interval, USEC_PER_SEC),
prefix, s->trigger_limit.burst);
str = ip_protocol_to_name(s->socket_protocol);
@ -793,7 +792,7 @@ static void socket_dump(Unit *u, FILE *f, const char *prefix) {
fprintf(f,
"%sTimeoutSec: %s\n",
prefix, format_timespan(time_string, FORMAT_TIMESPAN_MAX, s->timeout_usec, USEC_PER_SEC));
prefix, FORMAT_TIMESPAN(s->timeout_usec, USEC_PER_SEC));
exec_context_dump(&s->exec_context, f, prefix);
kill_context_dump(&s->kill_context, f, prefix);

View File

@ -609,7 +609,6 @@ static int swap_coldplug(Unit *u) {
}
static void swap_dump(Unit *u, FILE *f, const char *prefix) {
char buf[FORMAT_TIMESPAN_MAX];
Swap *s = SWAP(u);
SwapParameters *p;
@ -651,7 +650,7 @@ static void swap_dump(Unit *u, FILE *f, const char *prefix) {
fprintf(f,
"%sTimeoutSec: %s\n",
prefix, format_timespan(buf, sizeof(buf), s->timeout_usec, USEC_PER_SEC));
prefix, FORMAT_TIMESPAN(s->timeout_usec, USEC_PER_SEC));
if (s->control_pid > 0)
fprintf(f,

View File

@ -234,7 +234,6 @@ static int timer_load(Unit *u) {
}
static void timer_dump(Unit *u, FILE *f, const char *prefix) {
char buf[FORMAT_TIMESPAN_MAX];
Timer *t = TIMER(u);
Unit *trigger;
TimerValue *v;
@ -257,7 +256,7 @@ static void timer_dump(Unit *u, FILE *f, const char *prefix) {
prefix, trigger ? trigger->id : "n/a",
prefix, yes_no(t->persistent),
prefix, yes_no(t->wake_system),
prefix, format_timespan(buf, sizeof(buf), t->accuracy_usec, 1),
prefix, FORMAT_TIMESPAN(t->accuracy_usec, 1),
prefix, yes_no(t->remain_after_elapse),
prefix, yes_no(t->fixed_random_delay),
prefix, yes_no(t->on_clock_change),
@ -274,15 +273,12 @@ static void timer_dump(Unit *u, FILE *f, const char *prefix) {
prefix,
timer_base_to_string(v->base),
strna(p));
} else {
char timespan1[FORMAT_TIMESPAN_MAX];
} else
fprintf(f,
"%s%s: %s\n",
prefix,
timer_base_to_string(v->base),
format_timespan(timespan1, sizeof(timespan1), v->value, 0));
}
FORMAT_TIMESPAN(v->value, 0));
}
static void timer_set_state(Timer *t, TimerState state) {
@ -355,7 +351,6 @@ static void timer_enter_elapsed(Timer *t, bool leave_around) {
}
static void add_random(Timer *t, usec_t *v) {
char s[FORMAT_TIMESPAN_MAX];
usec_t add;
assert(t);
@ -373,7 +368,7 @@ static void add_random(Timer *t, usec_t *v) {
else
*v += add;
log_unit_debug(UNIT(t), "Adding %s random time.", format_timespan(s, sizeof(s), add, 0));
log_unit_debug(UNIT(t), "Adding %s random time.", FORMAT_TIMESPAN(add, 0));
}
static void timer_enter_waiting(Timer *t, bool time_change) {
@ -508,13 +503,12 @@ static void timer_enter_waiting(Timer *t, bool time_change) {
}
if (found_monotonic) {
char buf[FORMAT_TIMESPAN_MAX];
usec_t left;
add_random(t, &t->next_elapse_monotonic_or_boottime);
left = usec_sub_unsigned(t->next_elapse_monotonic_or_boottime, triple_timestamp_by_clock(&ts, TIMER_MONOTONIC_CLOCK(t)));
log_unit_debug(UNIT(t), "Monotonic timer elapses in %s.", format_timespan(buf, sizeof(buf), left, 0));
log_unit_debug(UNIT(t), "Monotonic timer elapses in %s.", FORMAT_TIMESPAN(left, 0));
if (t->monotonic_event_source) {
r = sd_event_source_set_time(t->monotonic_event_source, t->next_elapse_monotonic_or_boottime);

View File

@ -602,7 +602,6 @@ static void print_unit_dependency_mask(FILE *f, const char *kind, UnitDependency
void unit_dump(Unit *u, FILE *f, const char *prefix) {
char *t, **j;
const char *prefix2;
char timespan[FORMAT_TIMESPAN_MAX];
Unit *following;
_cleanup_set_free_ Set *following_set = NULL;
CGroupMask m;
@ -741,7 +740,7 @@ void unit_dump(Unit *u, FILE *f, const char *prefix) {
fprintf(f, "%s\tSuccess Action Exit Status: %i\n", prefix, u->success_action_exit_status);
if (u->job_timeout != USEC_INFINITY)
fprintf(f, "%s\tJob Timeout: %s\n", prefix, format_timespan(timespan, sizeof(timespan), u->job_timeout, 0));
fprintf(f, "%s\tJob Timeout: %s\n", prefix, FORMAT_TIMESPAN(u->job_timeout, 0));
if (u->job_timeout_action != EMERGENCY_ACTION_NONE)
fprintf(f, "%s\tJob Timeout Action: %s\n", prefix, emergency_action_to_string(u->job_timeout_action));

View File

@ -2273,8 +2273,6 @@ static int unit_log_resources(Unit *u) {
(void) unit_get_cpu_usage(u, &nsec);
if (nsec != NSEC_INFINITY) {
char buf[FORMAT_TIMESPAN_MAX] = "";
/* Format the CPU time for inclusion in the structured log message */
if (asprintf(&t, "CPU_USAGE_NSEC=%" PRIu64, nsec) < 0) {
r = log_oom();
@ -2283,8 +2281,7 @@ static int unit_log_resources(Unit *u) {
iovec[n_iovec++] = IOVEC_MAKE_STRING(t);
/* Format the CPU time for inclusion in the human language message string */
format_timespan(buf, sizeof(buf), nsec / NSEC_PER_USEC, USEC_PER_MSEC);
t = strjoin("consumed ", buf, " CPU time");
t = strjoin("consumed ", FORMAT_TIMESPAN(nsec / NSEC_PER_USEC, USEC_PER_MSEC), " CPU time");
if (!t) {
r = log_oom();
goto finish;

View File

@ -196,7 +196,6 @@ static int write_timeout(
const char *variable) {
_cleanup_free_ char *timeout = NULL;
char timespan[FORMAT_TIMESPAN_MAX];
usec_t u;
int r;
@ -212,7 +211,7 @@ static int write_timeout(
return 0;
}
fprintf(f, "%s=%s\n", variable, format_timespan(timespan, sizeof(timespan), u, 0));
fprintf(f, "%s=%s\n", variable, FORMAT_TIMESPAN(u, 0));
return 0;
}

View File

@ -1097,15 +1097,15 @@ static int home_ratelimit(Home *h, sd_bus_error *error) {
}
if (ret == 0) {
char buf[FORMAT_TIMESPAN_MAX];
usec_t t, n;
n = now(CLOCK_REALTIME);
t = user_record_ratelimit_next_try(h->record);
if (t != USEC_INFINITY && t > n)
return sd_bus_error_setf(error, BUS_ERROR_AUTHENTICATION_LIMIT_HIT, "Too many login attempts, please try again in %s!",
format_timespan(buf, sizeof(buf), t - n, USEC_PER_SEC));
return sd_bus_error_setf(error, BUS_ERROR_AUTHENTICATION_LIMIT_HIT,
"Too many login attempts, please try again in %s!",
FORMAT_TIMESPAN(t - n, USEC_PER_SEC));
return sd_bus_error_set(error, BUS_ERROR_AUTHENTICATION_LIMIT_HIT, "Too many login attempts, please try again later.");
}

View File

@ -892,9 +892,8 @@ _public_ PAM_EXTERN int pam_sm_acct_mgmt(
usec_t n = now(CLOCK_REALTIME);
if (t > n) {
char buf[FORMAT_TIMESPAN_MAX];
(void) pam_prompt(handle, PAM_ERROR_MSG, NULL, "Too many logins, try again in %s.",
format_timespan(buf, sizeof(buf), t - n, USEC_PER_SEC));
FORMAT_TIMESPAN(t - n, USEC_PER_SEC));
return PAM_MAXTRIES;
}

View File

@ -554,7 +554,6 @@ static int pull_job_progress_callback(void *userdata, curl_off_t dltotal, curl_o
if (n > j->last_status_usec + USEC_PER_SEC &&
percent != j->progress_percent &&
dlnow < dltotal) {
char buf[FORMAT_TIMESPAN_MAX];
if (n - j->start_usec > USEC_PER_SEC && dlnow > 0) {
char y[FORMAT_BYTES_MAX];
@ -566,7 +565,7 @@ static int pull_job_progress_callback(void *userdata, curl_off_t dltotal, curl_o
log_info("Got %u%% of %s. %s left at %s/s.",
percent,
j->url,
format_timespan(buf, sizeof(buf), left, USEC_PER_SEC),
FORMAT_TIMESPAN(left, USEC_PER_SEC),
format_bytes(y, sizeof(y), (uint64_t) ((double) dlnow / ((double) done / (double) USEC_PER_SEC))));
} else
log_info("Got %u%% of %s.", percent, j->url);

View File

@ -1942,7 +1942,6 @@ static int setup_keys(void) {
if (hn)
hostname_cleanup(hn);
char tsb[FORMAT_TIMESPAN_MAX];
fprintf(stderr,
"\nNew keys have been generated for host %s%s" SD_ID128_FORMAT_STR ".\n"
"\n"
@ -1961,7 +1960,7 @@ static int setup_keys(void) {
SD_ID128_FORMAT_VAL(machine),
ansi_highlight(), ansi_normal(),
p,
format_timespan(tsb, sizeof(tsb), arg_interval, 0),
FORMAT_TIMESPAN(arg_interval, 0),
ansi_highlight(), ansi_normal(),
ansi_highlight_red());
fflush(stderr);
@ -2014,7 +2013,7 @@ static int verify(sd_journal *j) {
else if (k < 0)
r = log_warning_errno(k, "FAIL: %s (%m)", f->path);
else {
char a[FORMAT_TIMESTAMP_MAX], b[FORMAT_TIMESTAMP_MAX], c[FORMAT_TIMESPAN_MAX];
char a[FORMAT_TIMESTAMP_MAX], b[FORMAT_TIMESTAMP_MAX];
log_info("PASS: %s", f->path);
if (arg_verify_key && JOURNAL_HEADER_SEALED(f->header)) {
@ -2022,10 +2021,10 @@ static int verify(sd_journal *j) {
log_info("=> Validated from %s to %s, final %s entries not sealed.",
format_timestamp_maybe_utc(a, sizeof(a), first),
format_timestamp_maybe_utc(b, sizeof(b), validated),
format_timespan(c, sizeof(c), last > validated ? last - validated : 0, 0));
FORMAT_TIMESPAN(last > validated ? last - validated : 0, 0));
} else if (last > 0)
log_info("=> No sealing yet, %s of entries not sealed.",
format_timespan(c, sizeof(c), last - first, 0));
FORMAT_TIMESPAN(last - first, 0));
else
log_info("=> No sealing yet, no entries in file.");
}

View File

@ -1113,7 +1113,6 @@ void server_dispatch_message(
}
int server_flush_to_var(Server *s, bool require_flag_file) {
char ts[FORMAT_TIMESPAN_MAX];
sd_journal *j = NULL;
const char *fn;
unsigned n = 0;
@ -1206,7 +1205,7 @@ finish:
server_driver_message(s, 0, NULL,
LOG_MESSAGE("Time spent on flushing to %s is %s for %u entries.",
s->system_storage.path,
format_timespan(ts, sizeof(ts), usec_sub_unsigned(now(CLOCK_MONOTONIC), start), 0),
FORMAT_TIMESPAN(usec_sub_unsigned(now(CLOCK_MONOTONIC), start), 0),
n),
NULL);

View File

@ -1686,7 +1686,6 @@ static int client_handle_ack(sd_dhcp_client *client, DHCPMessage *ack, size_t le
static int client_set_lease_timeouts(sd_dhcp_client *client) {
usec_t time_now;
char time_string[FORMAT_TIMESPAN_MAX];
int r;
assert(client);
@ -1748,7 +1747,7 @@ static int client_set_lease_timeouts(sd_dhcp_client *client) {
return 0;
log_dhcp_client(client, "lease expires in %s",
format_timespan(time_string, FORMAT_TIMESPAN_MAX, client->expire_time - time_now, USEC_PER_SEC));
FORMAT_TIMESPAN(client->expire_time - time_now, USEC_PER_SEC));
/* arm T2 timeout */
r = event_reset_time(client->event, &client->timeout_t2,
@ -1764,7 +1763,7 @@ static int client_set_lease_timeouts(sd_dhcp_client *client) {
return 0;
log_dhcp_client(client, "T2 expires in %s",
format_timespan(time_string, FORMAT_TIMESPAN_MAX, client->t2_time - time_now, USEC_PER_SEC));
FORMAT_TIMESPAN(client->t2_time - time_now, USEC_PER_SEC));
/* arm T1 timeout */
r = event_reset_time(client->event, &client->timeout_t1,
@ -1777,14 +1776,13 @@ static int client_set_lease_timeouts(sd_dhcp_client *client) {
if (client->t1_time > time_now)
log_dhcp_client(client, "T1 expires in %s",
format_timespan(time_string, FORMAT_TIMESPAN_MAX, client->t1_time - time_now, USEC_PER_SEC));
FORMAT_TIMESPAN(client->t1_time - time_now, USEC_PER_SEC));
return 0;
}
static int client_handle_message(sd_dhcp_client *client, DHCPMessage *message, int len) {
DHCP_CLIENT_DONT_DESTROY(client);
char time_string[FORMAT_TIMESPAN_MAX];
int r, notify_event;
assert(client);
@ -1830,8 +1828,7 @@ static int client_handle_message(sd_dhcp_client *client, DHCPMessage *message, i
if (r < 0)
goto error;
log_dhcp_client(client, "REBOOT in %s", format_timespan(time_string, FORMAT_TIMESPAN_MAX,
client->start_delay, USEC_PER_SEC));
log_dhcp_client(client, "REBOOT in %s", FORMAT_TIMESPAN(client->start_delay, USEC_PER_SEC));
client->start_delay = CLAMP(client->start_delay * 2,
RESTART_AFTER_NAK_MIN_USEC, RESTART_AFTER_NAK_MAX_USEC);

View File

@ -946,7 +946,6 @@ static int client_timeout_resend(sd_event_source *s, uint64_t usec, void *userda
usec_t time_now, init_retransmit_time = 0, max_retransmit_time = 0;
usec_t max_retransmit_duration = 0;
uint8_t max_retransmit_count = 0;
char time_string[FORMAT_TIMESPAN_MAX];
assert(s);
assert(client);
@ -1042,7 +1041,7 @@ static int client_timeout_resend(sd_event_source *s, uint64_t usec, void *userda
}
log_dhcp6_client(client, "Next retransmission in %s",
format_timespan(time_string, FORMAT_TIMESPAN_MAX, client->retransmit_time, USEC_PER_SEC));
FORMAT_TIMESPAN(client->retransmit_time, USEC_PER_SEC));
r = event_reset_time(client->event, &client->timeout_resend,
clock_boottime_or_monotonic(),
@ -1566,7 +1565,6 @@ static int client_get_lifetime(sd_dhcp6_client *client, uint32_t *lifetime_t1,
static int client_start(sd_dhcp6_client *client, enum DHCP6State state) {
int r;
usec_t timeout, time_now;
char time_string[FORMAT_TIMESPAN_MAX];
uint32_t lifetime_t1, lifetime_t2;
assert_return(client, -EINVAL);
@ -1639,8 +1637,7 @@ static int client_start(sd_dhcp6_client *client, enum DHCP6State state) {
timeout = client_timeout_compute_random(lifetime_t1 * USEC_PER_SEC);
log_dhcp6_client(client, "T1 expires in %s",
format_timespan(time_string, FORMAT_TIMESPAN_MAX, timeout, USEC_PER_SEC));
log_dhcp6_client(client, "T1 expires in %s", FORMAT_TIMESPAN(timeout, USEC_PER_SEC));
r = event_reset_time(client->event, &client->timeout_t1,
clock_boottime_or_monotonic(),
@ -1652,8 +1649,7 @@ static int client_start(sd_dhcp6_client *client, enum DHCP6State state) {
timeout = client_timeout_compute_random(lifetime_t2 * USEC_PER_SEC);
log_dhcp6_client(client, "T2 expires in %s",
format_timespan(time_string, FORMAT_TIMESPAN_MAX, timeout, USEC_PER_SEC));
log_dhcp6_client(client, "T2 expires in %s", FORMAT_TIMESPAN(timeout, USEC_PER_SEC));
r = event_reset_time(client->event, &client->timeout_t2,
clock_boottime_or_monotonic(),

View File

@ -225,10 +225,8 @@ static int ipv4acd_on_timeout(sd_event_source *s, uint64_t usec, void *userdata)
ipv4acd_set_state(acd, IPV4ACD_STATE_WAITING_PROBE, true);
if (acd->n_conflict >= MAX_CONFLICTS) {
char ts[FORMAT_TIMESPAN_MAX];
log_ipv4acd(acd, "Max conflicts reached, delaying by %s",
format_timespan(ts, sizeof(ts), RATE_LIMIT_INTERVAL_USEC, 0));
FORMAT_TIMESPAN(RATE_LIMIT_INTERVAL_USEC, 0));
r = ipv4acd_set_next_wakeup(acd, RATE_LIMIT_INTERVAL_USEC, PROBE_WAIT_USEC);
} else
r = ipv4acd_set_next_wakeup(acd, 0, PROBE_WAIT_USEC);

View File

@ -279,7 +279,6 @@ static usec_t ndisc_timeout_compute_random(usec_t val) {
}
static int ndisc_timeout(sd_event_source *s, uint64_t usec, void *userdata) {
char time_string[FORMAT_TIMESPAN_MAX];
sd_ndisc *nd = userdata;
usec_t time_now;
int r;
@ -314,8 +313,7 @@ static int ndisc_timeout(sd_event_source *s, uint64_t usec, void *userdata) {
}
log_ndisc(nd, "Sent Router Solicitation, next solicitation in %s",
format_timespan(time_string, FORMAT_TIMESPAN_MAX,
nd->retransmit_time, USEC_PER_SEC));
FORMAT_TIMESPAN(nd->retransmit_time, USEC_PER_SEC));
return 0;

View File

@ -301,7 +301,6 @@ static int radv_timeout(sd_event_source *s, uint64_t usec, void *userdata) {
usec_t min_timeout = SD_RADV_DEFAULT_MIN_TIMEOUT_USEC;
usec_t max_timeout = SD_RADV_DEFAULT_MAX_TIMEOUT_USEC;
usec_t time_now, timeout;
char time_string[FORMAT_TIMESPAN_MAX];
assert(s);
assert(ra);
@ -329,10 +328,7 @@ static int radv_timeout(sd_event_source *s, uint64_t usec, void *userdata) {
}
timeout = radv_compute_timeout(min_timeout, max_timeout);
log_radv(ra, "Next Router Advertisement in %s",
format_timespan(time_string, FORMAT_TIMESPAN_MAX,
timeout, USEC_PER_SEC));
log_radv(ra, "Next Router Advertisement in %s", FORMAT_TIMESPAN(timeout, USEC_PER_SEC));
r = event_reset_time(ra->event, &ra->timeout_event_source,
clock_boottime_or_monotonic(),
@ -545,8 +541,6 @@ _public_ int sd_radv_add_prefix(sd_radv *ra, sd_radv_prefix *p, int dynamic) {
sd_radv_prefix *cur;
int r;
_cleanup_free_ char *addr_p = NULL;
char time_string_preferred[FORMAT_TIMESPAN_MAX];
char time_string_valid[FORMAT_TIMESPAN_MAX];
usec_t time_now, valid, preferred, valid_until, preferred_until;
assert_return(ra, -EINVAL);
@ -628,10 +622,8 @@ _public_ int sd_radv_add_prefix(sd_radv *ra, sd_radv_prefix *p, int dynamic) {
log_radv(ra, "Updated prefix %s preferred %s valid %s",
strna(addr_p),
format_timespan(time_string_preferred, FORMAT_TIMESPAN_MAX,
preferred, USEC_PER_SEC),
format_timespan(time_string_valid, FORMAT_TIMESPAN_MAX,
valid, USEC_PER_SEC));
FORMAT_TIMESPAN(preferred, USEC_PER_SEC),
FORMAT_TIMESPAN(valid, USEC_PER_SEC));
return 0;
}
@ -662,7 +654,6 @@ _public_ sd_radv_prefix *sd_radv_remove_prefix(sd_radv *ra,
}
_public_ int sd_radv_add_route_prefix(sd_radv *ra, sd_radv_route_prefix *p, int dynamic) {
char time_string_valid[FORMAT_TIMESPAN_MAX];
usec_t time_now, valid, valid_until;
_cleanup_free_ char *pretty = NULL;
sd_radv_route_prefix *cur;
@ -732,7 +723,7 @@ _public_ int sd_radv_add_route_prefix(sd_radv *ra, sd_radv_route_prefix *p, int
log_radv(ra, "Updated route prefix %s valid %s",
strna(pretty),
format_timespan(time_string_valid, FORMAT_TIMESPAN_MAX, valid, USEC_PER_SEC));
FORMAT_TIMESPAN(valid, USEC_PER_SEC));
return 0;
}

View File

@ -317,9 +317,6 @@ static int test_timeout_value(uint8_t flags) {
static usec_t last = 0;
sd_ndisc *nd = test_timeout_nd;
usec_t min, max;
char time_string_min[FORMAT_TIMESPAN_MAX];
char time_string_nd[FORMAT_TIMESPAN_MAX];
char time_string_max[FORMAT_TIMESPAN_MAX];
assert_se(nd);
assert_se(nd->event);
@ -347,17 +344,12 @@ static int test_timeout_value(uint8_t flags) {
NDISC_MAX_ROUTER_SOLICITATION_INTERVAL / 10;
}
format_timespan(time_string_min, FORMAT_TIMESPAN_MAX,
min, USEC_PER_MSEC);
format_timespan(time_string_nd, FORMAT_TIMESPAN_MAX,
nd->retransmit_time, USEC_PER_MSEC);
format_timespan(time_string_max, FORMAT_TIMESPAN_MAX,
max, USEC_PER_MSEC);
log_info("backoff timeout interval %2d %s%s <= %s <= %s",
count,
(last * 2 > NDISC_MAX_ROUTER_SOLICITATION_INTERVAL)? "(max) ": "",
time_string_min, time_string_nd, time_string_max);
last * 2 > NDISC_MAX_ROUTER_SOLICITATION_INTERVAL ? "(max) ": "",
FORMAT_TIMESPAN(min, USEC_PER_MSEC),
FORMAT_TIMESPAN(nd->retransmit_time, USEC_PER_MSEC),
FORMAT_TIMESPAN(max, USEC_PER_MSEC));
assert_se(min <= nd->retransmit_time);
assert_se(max >= nd->retransmit_time);

View File

@ -3274,7 +3274,6 @@ fail:
void journal_file_print_header(JournalFile *f) {
char a[SD_ID128_STRING_MAX], b[SD_ID128_STRING_MAX], c[SD_ID128_STRING_MAX], d[SD_ID128_STRING_MAX];
char z[FORMAT_TIMESPAN_MAX];
struct stat st;
char bytes[FORMAT_BYTES_MAX];
@ -3325,7 +3324,7 @@ void journal_file_print_header(JournalFile *f) {
le64toh(f->header->tail_entry_seqnum), le64toh(f->header->tail_entry_seqnum),
FORMAT_TIMESTAMP_SAFE(le64toh(f->header->head_entry_realtime)), le64toh(f->header->head_entry_realtime),
FORMAT_TIMESTAMP_SAFE(le64toh(f->header->tail_entry_realtime)), le64toh(f->header->tail_entry_realtime),
format_timespan(z, sizeof(z), le64toh(f->header->tail_entry_monotonic), USEC_PER_MSEC), le64toh(f->header->tail_entry_monotonic),
FORMAT_TIMESPAN(le64toh(f->header->tail_entry_monotonic), USEC_PER_MSEC), le64toh(f->header->tail_entry_monotonic),
le64toh(f->header->n_objects),
le64toh(f->header->n_entries));

View File

@ -57,7 +57,6 @@ int main(int argc, char *argv[]) {
JournalFile *f;
const char *verification_key = argv[1];
usec_t from = 0, to = 0, total = 0;
char c[FORMAT_TIMESPAN_MAX];
struct stat st;
uint64_t p;
@ -105,7 +104,7 @@ int main(int argc, char *argv[]) {
log_info("=> Validated from %s to %s, %s missing",
FORMAT_TIMESTAMP(from),
FORMAT_TIMESTAMP(to),
format_timespan(c, sizeof(c), total > to ? total - to : 0, 0));
FORMAT_TIMESPAN(total > to ? total - to : 0, 0));
(void) journal_file_close(f);

View File

@ -867,13 +867,10 @@ void user_update_last_session_timer(User *u) {
if (r < 0)
log_warning_errno(r, "Failed to enqueue user stop event source, ignoring: %m");
if (DEBUG_LOGGING) {
char s[FORMAT_TIMESPAN_MAX];
if (DEBUG_LOGGING)
log_debug("Last session of user '%s' logged out, terminating user context in %s.",
u->user_record->user_name,
format_timespan(s, sizeof(s), user_stop_delay, USEC_PER_MSEC));
}
FORMAT_TIMESPAN(user_stop_delay, USEC_PER_MSEC));
}
static const char* const user_state_table[_USER_STATE_MAX] = {

View File

@ -622,7 +622,6 @@ int manager_has_address(Manager *manager, int family, const union in_addr_union
static void log_address_debug(const Address *address, const char *str, const Link *link) {
_cleanup_free_ char *addr = NULL, *peer = NULL, *flags_str = NULL;
char valid_buf[FORMAT_TIMESPAN_MAX], preferred_buf[FORMAT_TIMESPAN_MAX];
const char *valid_str = NULL, *preferred_str = NULL;
bool has_peer;
@ -639,14 +638,10 @@ static void log_address_debug(const Address *address, const char *str, const Lin
(void) in_addr_to_string(address->family, &address->in_addr_peer, &peer);
if (address->cinfo.ifa_valid != CACHE_INFO_INFINITY_LIFE_TIME)
valid_str = format_timespan(valid_buf, FORMAT_TIMESPAN_MAX,
address->cinfo.ifa_valid * USEC_PER_SEC,
USEC_PER_SEC);
valid_str = FORMAT_TIMESPAN(address->cinfo.ifa_valid * USEC_PER_SEC, USEC_PER_SEC);
if (address->cinfo.ifa_prefered != CACHE_INFO_INFINITY_LIFE_TIME)
preferred_str = format_timespan(preferred_buf, FORMAT_TIMESPAN_MAX,
address->cinfo.ifa_prefered * USEC_PER_SEC,
USEC_PER_SEC);
preferred_str = FORMAT_TIMESPAN(address->cinfo.ifa_prefered * USEC_PER_SEC, USEC_PER_SEC);
(void) address_flags_to_string_alloc(address->flags, address->family, &flags_str);

View File

@ -107,7 +107,6 @@ int can_set_netlink_message(Link *link, sd_netlink_message *m) {
}
if (link->network->can_restart_us > 0) {
char time_string[FORMAT_TIMESPAN_MAX];
uint64_t restart_ms;
if (link->network->can_restart_us == USEC_INFINITY)
@ -115,12 +114,11 @@ int can_set_netlink_message(Link *link, sd_netlink_message *m) {
else
restart_ms = DIV_ROUND_UP(link->network->can_restart_us, USEC_PER_MSEC);
format_timespan(time_string, FORMAT_TIMESPAN_MAX, restart_ms * 1000, MSEC_PER_SEC);
if (restart_ms > UINT32_MAX)
return log_link_debug_errno(link, SYNTHETIC_ERRNO(ERANGE), "restart timeout (%s) too big.", time_string);
return log_link_debug_errno(link, SYNTHETIC_ERRNO(ERANGE), "restart timeout (%s) too big.",
FORMAT_TIMESPAN(restart_ms * 1000, MSEC_PER_SEC));
log_link_debug(link, "Setting restart = %s", time_string);
log_link_debug(link, "Setting restart = %s", FORMAT_TIMESPAN(restart_ms * 1000, MSEC_PER_SEC));
r = sd_netlink_message_append_u32(m, IFLA_CAN_RESTART_MS, restart_ms);
if (r < 0)

View File

@ -29,10 +29,8 @@ int manager_parse_config_file(Manager *m) {
return r;
if (m->use_speed_meter && m->speed_meter_interval_usec < SPEED_METER_MINIMUM_TIME_INTERVAL) {
char buf[FORMAT_TIMESPAN_MAX];
log_warning("SpeedMeterIntervalSec= is too small, using %s.",
format_timespan(buf, sizeof buf, SPEED_METER_MINIMUM_TIME_INTERVAL, USEC_PER_SEC));
FORMAT_TIMESPAN(SPEED_METER_MINIMUM_TIME_INTERVAL, USEC_PER_SEC));
m->speed_meter_interval_usec = SPEED_METER_MINIMUM_TIME_INTERVAL;
}

View File

@ -375,7 +375,6 @@ static int dhcp6_pd_address_handler(sd_netlink *rtnl, sd_netlink_message *m, Lin
}
static void log_dhcp6_pd_address(Link *link, const Address *address) {
char valid_buf[FORMAT_TIMESPAN_MAX], preferred_buf[FORMAT_TIMESPAN_MAX];
const char *valid_str = NULL, *preferred_str = NULL;
_cleanup_free_ char *buffer = NULL;
int log_level;
@ -390,13 +389,9 @@ static void log_dhcp6_pd_address(Link *link, const Address *address) {
(void) in6_addr_prefix_to_string(&address->in_addr.in6, address->prefixlen, &buffer);
if (address->cinfo.ifa_valid != CACHE_INFO_INFINITY_LIFE_TIME)
valid_str = format_timespan(valid_buf, FORMAT_TIMESPAN_MAX,
address->cinfo.ifa_valid * USEC_PER_SEC,
USEC_PER_SEC);
valid_str = FORMAT_TIMESPAN(address->cinfo.ifa_valid * USEC_PER_SEC, USEC_PER_SEC);
if (address->cinfo.ifa_prefered != CACHE_INFO_INFINITY_LIFE_TIME)
preferred_str = format_timespan(preferred_buf, FORMAT_TIMESPAN_MAX,
address->cinfo.ifa_prefered * USEC_PER_SEC,
USEC_PER_SEC);
preferred_str = FORMAT_TIMESPAN(address->cinfo.ifa_prefered * USEC_PER_SEC, USEC_PER_SEC);
log_link_full(link, log_level, "DHCPv6-PD address %s (valid %s%s, preferred %s%s)",
strna(buffer),
@ -1063,8 +1058,6 @@ static int dhcp6_address_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *
}
static void log_dhcp6_address(Link *link, const Address *address, char **ret) {
char valid_buf[FORMAT_TIMESPAN_MAX], preferred_buf[FORMAT_TIMESPAN_MAX];
const char *valid_str = NULL, *preferred_str = NULL;
_cleanup_free_ char *buffer = NULL;
bool by_ndisc = false;
Address *existing;
@ -1076,14 +1069,11 @@ static void log_dhcp6_address(Link *link, const Address *address, char **ret) {
assert(address->family == AF_INET6);
(void) in6_addr_prefix_to_string(&address->in_addr.in6, address->prefixlen, &buffer);
if (address->cinfo.ifa_valid != CACHE_INFO_INFINITY_LIFE_TIME)
valid_str = format_timespan(valid_buf, FORMAT_TIMESPAN_MAX,
address->cinfo.ifa_valid * USEC_PER_SEC,
USEC_PER_SEC);
if (address->cinfo.ifa_prefered != CACHE_INFO_INFINITY_LIFE_TIME)
preferred_str = format_timespan(preferred_buf, FORMAT_TIMESPAN_MAX,
address->cinfo.ifa_prefered * USEC_PER_SEC,
USEC_PER_SEC);
const char *valid_str = address->cinfo.ifa_valid == CACHE_INFO_INFINITY_LIFE_TIME ? NULL :
FORMAT_TIMESPAN(address->cinfo.ifa_valid * USEC_PER_SEC, USEC_PER_SEC);
const char *preferred_str = address->cinfo.ifa_prefered == CACHE_INFO_INFINITY_LIFE_TIME ? NULL :
FORMAT_TIMESPAN(address->cinfo.ifa_prefered * USEC_PER_SEC, USEC_PER_SEC);
r = address_get(link, address, &existing);
if (r < 0) {

View File

@ -442,7 +442,6 @@ static int monitor_memory_pressure_contexts_handler(sd_event_source *s, uint64_t
OomdCGroupContext *t;
SET_FOREACH(t, targets) {
_cleanup_free_ char *selected = NULL;
char ts[FORMAT_TIMESPAN_MAX];
/* Check if there was reclaim activity in the given interval. The concern is the following case:
* Pressure climbed, a lot of high-frequency pages were reclaimed, and we killed the offending
@ -456,9 +455,7 @@ static int monitor_memory_pressure_contexts_handler(sd_event_source *s, uint64_t
t->path,
LOAD_INT(t->memory_pressure.avg10), LOAD_FRAC(t->memory_pressure.avg10),
LOAD_INT(t->mem_pressure_limit), LOAD_FRAC(t->mem_pressure_limit),
format_timespan(ts, sizeof ts,
m->default_mem_pressure_duration_usec,
USEC_PER_SEC));
FORMAT_TIMESPAN(m->default_mem_pressure_duration_usec, USEC_PER_SEC));
r = update_monitored_cgroup_contexts_candidates(
m->monitored_mem_pressure_cgroup_contexts, &m->monitored_mem_pressure_cgroup_contexts_candidates);
@ -483,9 +480,7 @@ static int monitor_memory_pressure_contexts_handler(sd_event_source *s, uint64_t
selected, t->path,
LOAD_INT(t->memory_pressure.avg10), LOAD_FRAC(t->memory_pressure.avg10),
LOAD_INT(t->mem_pressure_limit), LOAD_FRAC(t->mem_pressure_limit),
format_timespan(ts, sizeof ts,
m->default_mem_pressure_duration_usec,
USEC_PER_SEC));
FORMAT_TIMESPAN(m->default_mem_pressure_duration_usec, USEC_PER_SEC));
return 0;
}
}
@ -707,7 +702,6 @@ int manager_start(
int manager_get_dump_string(Manager *m, char **ret) {
_cleanup_free_ char *dump = NULL;
_cleanup_fclose_ FILE *f = NULL;
char buf[FORMAT_TIMESPAN_MAX];
OomdCGroupContext *c;
size_t size;
char *key;
@ -729,7 +723,7 @@ int manager_get_dump_string(Manager *m, char **ret) {
yes_no(m->dry_run),
PERMYRIAD_AS_PERCENT_FORMAT_VAL(m->swap_used_limit_permyriad),
LOAD_INT(m->default_mem_pressure_limit), LOAD_FRAC(m->default_mem_pressure_limit),
format_timespan(buf, sizeof(buf), m->default_mem_pressure_duration_usec, USEC_PER_SEC));
FORMAT_TIMESPAN(m->default_mem_pressure_duration_usec, USEC_PER_SEC));
oomd_dump_system_context(&m->system_context, f, "\t");
fprintf(f, "Swap Monitored CGroups:\n");

View File

@ -523,8 +523,7 @@ void oomd_dump_swap_cgroup_context(const OomdCGroupContext *ctx, FILE *f, const
}
void oomd_dump_memory_pressure_cgroup_context(const OomdCGroupContext *ctx, FILE *f, const char *prefix) {
char tbuf[FORMAT_TIMESPAN_MAX], mem_use[FORMAT_BYTES_MAX];
char mem_min[FORMAT_BYTES_MAX], mem_low[FORMAT_BYTES_MAX];
char mem_use[FORMAT_BYTES_MAX], mem_min[FORMAT_BYTES_MAX], mem_low[FORMAT_BYTES_MAX];
assert(ctx);
assert(f);
@ -540,7 +539,7 @@ void oomd_dump_memory_pressure_cgroup_context(const OomdCGroupContext *ctx, FILE
LOAD_INT(ctx->memory_pressure.avg10), LOAD_FRAC(ctx->memory_pressure.avg10),
LOAD_INT(ctx->memory_pressure.avg60), LOAD_FRAC(ctx->memory_pressure.avg60),
LOAD_INT(ctx->memory_pressure.avg300), LOAD_FRAC(ctx->memory_pressure.avg300),
format_timespan(tbuf, sizeof(tbuf), ctx->memory_pressure.total, USEC_PER_SEC),
FORMAT_TIMESPAN(ctx->memory_pressure.total, USEC_PER_SEC),
strempty(prefix), format_bytes(mem_use, sizeof(mem_use), ctx->current_memory_usage));
if (!empty_or_root(ctx->path))

View File

@ -150,8 +150,6 @@ int ifname_resolvconf_mangle(const char *s) {
}
static void print_source(uint64_t flags, usec_t rtt) {
char rtt_str[FORMAT_TIMESTAMP_MAX];
if (!arg_legend)
return;
@ -167,11 +165,10 @@ static void print_source(uint64_t flags, usec_t rtt) {
flags & SD_RESOLVED_MDNS_IPV4 ? " mDNS/IPv4" : "",
flags & SD_RESOLVED_MDNS_IPV6 ? " mDNS/IPv6" : "");
assert_se(format_timespan(rtt_str, sizeof(rtt_str), rtt, 100));
printf(" in %s.%s\n"
"%s-- Data is authenticated: %s; Data was acquired via local or encrypted transport: %s%s\n",
rtt_str, ansi_normal(),
FORMAT_TIMESPAN(rtt, 100),
ansi_normal(),
ansi_grey(),
yes_no(flags & SD_RESOLVED_AUTHENTICATED),
yes_no(flags & SD_RESOLVED_CONFIDENTIAL),

View File

@ -1322,17 +1322,13 @@ static int start_transient_service(
if (timestamp_is_set(c.inactive_enter_usec) &&
timestamp_is_set(c.inactive_exit_usec) &&
c.inactive_enter_usec > c.inactive_exit_usec) {
char ts[FORMAT_TIMESPAN_MAX];
c.inactive_enter_usec > c.inactive_exit_usec)
log_info("Service runtime: %s",
format_timespan(ts, sizeof ts, c.inactive_enter_usec - c.inactive_exit_usec, USEC_PER_MSEC));
}
FORMAT_TIMESPAN(c.inactive_enter_usec - c.inactive_exit_usec, USEC_PER_MSEC));
if (c.cpu_usage_nsec != NSEC_INFINITY) {
char ts[FORMAT_TIMESPAN_MAX];
if (c.cpu_usage_nsec != NSEC_INFINITY)
log_info("CPU time consumed: %s",
format_timespan(ts, sizeof ts, DIV_ROUND_UP(c.cpu_usage_nsec, NSEC_PER_USEC), USEC_PER_MSEC));
}
FORMAT_TIMESPAN(DIV_ROUND_UP(c.cpu_usage_nsec, NSEC_PER_USEC), USEC_PER_MSEC));
if (c.ip_ingress_bytes != UINT64_MAX) {
char bytes[FORMAT_BYTES_MAX];

View File

@ -109,13 +109,10 @@ static int bus_print_property(const char *name, const char *expected_value, sd_b
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")) {

View File

@ -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)

View File

@ -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

View File

@ -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 */

View File

@ -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;

View File

@ -299,10 +299,8 @@ 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_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) {
char buf[FORMAT_BYTES_MAX];
printf(" PBKDF Bytes: %s\n", format_bytes(buf, sizeof(buf), hr->luks_pbkdf_memory_cost));
@ -409,20 +407,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));
@ -432,24 +426,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");
}
@ -485,10 +478,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));

View File

@ -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) {

View File

@ -266,7 +266,6 @@ static int execute(
static int execute_s2h(const SleepConfig *sleep_config) {
_cleanup_close_ int tfd = -1;
char buf[FORMAT_TIMESPAN_MAX];
struct itimerspec ts = {};
int r;
@ -277,7 +276,7 @@ static int execute_s2h(const SleepConfig *sleep_config) {
return log_error_errno(errno, "Error creating timerfd: %m");
log_debug("Set timerfd wake alarm for %s",
format_timespan(buf, sizeof(buf), sleep_config->hibernate_delay_sec, USEC_PER_SEC));
FORMAT_TIMESPAN(sleep_config->hibernate_delay_sec, USEC_PER_SEC));
timespec_store(&ts.it_value, sleep_config->hibernate_delay_sec);
@ -299,7 +298,7 @@ static int execute_s2h(const SleepConfig *sleep_config) {
/* If woken up after alarm time, hibernate */
log_debug("Attempting to hibernate after waking from %s timer",
format_timespan(buf, sizeof(buf), sleep_config->hibernate_delay_sec, USEC_PER_SEC));
FORMAT_TIMESPAN(sleep_config->hibernate_delay_sec, USEC_PER_SEC));
r = execute(sleep_config, SLEEP_HIBERNATE, NULL);
if (r < 0) {

View File

@ -722,10 +722,8 @@ static void print_status_info(
printf("\n");
}
if (i->cpu_usage_nsec != UINT64_MAX) {
char buf[FORMAT_TIMESPAN_MAX];
printf(" CPU: %s\n", format_timespan(buf, sizeof(buf), i->cpu_usage_nsec / NSEC_PER_USEC, USEC_PER_MSEC));
}
if (i->cpu_usage_nsec != UINT64_MAX)
printf(" CPU: %s\n", FORMAT_TIMESPAN(i->cpu_usage_nsec / NSEC_PER_USEC, USEC_PER_MSEC));
if (i->control_group) {
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
@ -1235,15 +1233,12 @@ static int print_property(const char *name, const char *expected_value, sd_bus_m
if (r < 0)
return bus_log_parse_error(r);
while ((r = sd_bus_message_read(m, "(stt)", &base, &v, &next_elapse)) > 0) {
char timespan1[FORMAT_TIMESPAN_MAX] = "n/a", timespan2[FORMAT_TIMESPAN_MAX] = "n/a";
(void) format_timespan(timespan1, sizeof timespan1, v, 0);
(void) format_timespan(timespan2, sizeof timespan2, next_elapse, 0);
while ((r = sd_bus_message_read(m, "(stt)", &base, &v, &next_elapse)) > 0)
bus_print_property_valuef(name, expected_value, flags,
"{ %s=%s ; next_elapse=%s }", base, timespan1, timespan2);
}
"{ %s=%s ; next_elapse=%s }",
base,
strna(FORMAT_TIMESPAN(v, 0)),
strna(FORMAT_TIMESPAN(next_elapse, 0)));
if (r < 0)
return bus_log_parse_error(r);
@ -1397,7 +1392,6 @@ static int print_property(const char *name, const char *expected_value, sd_bus_m
} else if (contents[0] == SD_BUS_TYPE_STRUCT_BEGIN &&
streq(name, "IODeviceLatencyTargetUSec")) {
char ts[FORMAT_TIMESPAN_MAX];
const char *path;
uint64_t target;
@ -1407,7 +1401,7 @@ static int print_property(const char *name, const char *expected_value, sd_bus_m
while ((r = sd_bus_message_read(m, "(st)", &path, &target)) > 0)
bus_print_property_valuef(name, expected_value, flags, "%s %s", strna(path),
format_timespan(ts, sizeof(ts), target, 1));
FORMAT_TIMESPAN(target, 1));
if (r < 0)
return bus_log_parse_error(r);

View File

@ -11,7 +11,6 @@
#include "util.h"
static int test_acpi_fpdt(void) {
char ts_start[FORMAT_TIMESPAN_MAX], ts_exit[FORMAT_TIMESPAN_MAX], ts_span[FORMAT_TIMESPAN_MAX];
usec_t loader_start, loader_exit;
int r;
@ -24,14 +23,13 @@ static int test_acpi_fpdt(void) {
}
log_info("ACPI FPDT: loader start=%s exit=%s duration=%s",
format_timespan(ts_start, sizeof(ts_start), loader_start, USEC_PER_MSEC),
format_timespan(ts_exit, sizeof(ts_exit), loader_exit, USEC_PER_MSEC),
format_timespan(ts_span, sizeof(ts_span), loader_exit - loader_start, USEC_PER_MSEC));
FORMAT_TIMESPAN(loader_start, USEC_PER_MSEC),
FORMAT_TIMESPAN(loader_exit, USEC_PER_MSEC),
FORMAT_TIMESPAN(loader_exit - loader_start, USEC_PER_MSEC));
return 1;
}
static int test_efi_loader(void) {
char ts_start[FORMAT_TIMESPAN_MAX], ts_exit[FORMAT_TIMESPAN_MAX], ts_span[FORMAT_TIMESPAN_MAX];
usec_t loader_start, loader_exit;
int r;
@ -44,14 +42,13 @@ static int test_efi_loader(void) {
}
log_info("EFI Loader: start=%s exit=%s duration=%s",
format_timespan(ts_start, sizeof(ts_start), loader_start, USEC_PER_MSEC),
format_timespan(ts_exit, sizeof(ts_exit), loader_exit, USEC_PER_MSEC),
format_timespan(ts_span, sizeof(ts_span), loader_exit - loader_start, USEC_PER_MSEC));
FORMAT_TIMESPAN(loader_start, USEC_PER_MSEC),
FORMAT_TIMESPAN(loader_exit, USEC_PER_MSEC),
FORMAT_TIMESPAN(loader_exit - loader_start, USEC_PER_MSEC));
return 1;
}
static int test_boot_timestamps(void) {
char s[FORMAT_TIMESPAN_MAX];
dual_timestamp fw, l, k;
int r;
@ -65,8 +62,8 @@ static int test_boot_timestamps(void) {
return ok ? 0 : r;
}
log_info("Firmware began %s before kernel.", format_timespan(s, sizeof(s), fw.monotonic, 0));
log_info("Loader began %s before kernel.", format_timespan(s, sizeof(s), l.monotonic, 0));
log_info("Firmware began %s before kernel.", FORMAT_TIMESPAN(fw.monotonic, 0));
log_info("Loader began %s before kernel.", FORMAT_TIMESPAN(l.monotonic, 0));
log_info("Firmware began %s.", FORMAT_TIMESTAMP(fw.realtime));
log_info("Loader began %s.", FORMAT_TIMESTAMP(l.realtime));
log_info("Kernel began %s.", FORMAT_TIMESTAMP(k.realtime));

View File

@ -752,7 +752,6 @@ static void test_hashmap_many(void) {
for (j = 0; j < ELEMENTSOF(tests); j++) {
usec_t ts = now(CLOCK_MONOTONIC), n;
char b[FORMAT_TIMESPAN_MAX];
assert_se(h = hashmap_new(tests[j].ops));
@ -779,7 +778,7 @@ static void test_hashmap_many(void) {
hashmap_free(h);
n = now(CLOCK_MONOTONIC);
log_info("test took %s", format_timespan(b, sizeof b, n - ts, 0));
log_info("test took %s", FORMAT_TIMESPAN(n - ts, 0));
}
}
@ -790,7 +789,6 @@ static void test_hashmap_free(void) {
Hashmap *h;
bool slow = slow_tests_enabled();
usec_t ts, n;
char b[FORMAT_TIMESPAN_MAX];
unsigned n_entries = slow ? 1 << 20 : 240;
const struct {
@ -824,7 +822,7 @@ static void test_hashmap_free(void) {
hashmap_free(h);
n = now(CLOCK_MONOTONIC);
log_info("%s test took %s", tests[j].title, format_timespan(b, sizeof b, n - ts, 0));
log_info("%s test took %s", tests[j].title, FORMAT_TIMESPAN(n - ts, 0));
assert_se(custom_counter == tests[j].expect_counter);
}

View File

@ -9,7 +9,7 @@
#include "tests.h"
int main(int argc, char *argv[]) {
char buf[CONST_MAX(FORMAT_TIMESPAN_MAX, FORMAT_BYTES_MAX)];
char buf[FORMAT_BYTES_MAX];
nsec_t nsec;
uint64_t v;
int r;
@ -18,7 +18,7 @@ int main(int argc, char *argv[]) {
log_open();
assert_se(procfs_cpu_get_usage(&nsec) >= 0);
log_info("Current system CPU time: %s", format_timespan(buf, sizeof(buf), nsec/NSEC_PER_USEC, 1));
log_info("Current system CPU time: %s", FORMAT_TIMESPAN(nsec/NSEC_PER_USEC, 1));
assert_se(procfs_memory_get_used(&v) >= 0);
log_info("Current memory usage: %s", format_bytes(buf, sizeof(buf), v));

View File

@ -359,8 +359,6 @@ DEFINE_PRIVATE_STRING_TABLE_LOOKUP_TO_STRING(ntp_leap, uint32_t);
REENABLE_WARNING;
static int print_ntp_status_info(NTPStatusInfo *i) {
char ts[FORMAT_TIMESPAN_MAX], jitter[FORMAT_TIMESPAN_MAX],
tmin[FORMAT_TIMESPAN_MAX], tmax[FORMAT_TIMESPAN_MAX];
usec_t delay, t14, t23, offset, root_distance;
_cleanup_(table_unrefp) Table *table = NULL;
bool offset_sign;
@ -407,9 +405,9 @@ static int print_ntp_status_info(NTPStatusInfo *i) {
return table_log_add_error(r);
r = table_add_cell_stringf(table, NULL, "%s (min: %s; max %s)",
format_timespan(ts, sizeof(ts), i->poll_interval, 0),
format_timespan(tmin, sizeof(tmin), i->poll_min, 0),
format_timespan(tmax, sizeof(tmax), i->poll_max, 0));
FORMAT_TIMESPAN(i->poll_interval, 0),
FORMAT_TIMESPAN(i->poll_min, 0),
FORMAT_TIMESPAN(i->poll_max, 0));
if (r < 0)
return table_log_add_error(r);
@ -468,7 +466,7 @@ static int print_ntp_status_info(NTPStatusInfo *i) {
return table_log_add_error(r);
r = table_add_cell_stringf(table, NULL, "%s (%" PRIi32 ")",
format_timespan(ts, sizeof(ts), DIV_ROUND_UP((nsec_t) (exp2(i->precision) * NSEC_PER_SEC), NSEC_PER_USEC), 0),
FORMAT_TIMESPAN(DIV_ROUND_UP((nsec_t) (exp2(i->precision) * NSEC_PER_SEC), NSEC_PER_USEC), 0),
i->precision);
if (r < 0)
return table_log_add_error(r);
@ -478,8 +476,8 @@ static int print_ntp_status_info(NTPStatusInfo *i) {
return table_log_add_error(r);
r = table_add_cell_stringf(table, NULL, "%s (max: %s)",
format_timespan(ts, sizeof(ts), root_distance, 0),
format_timespan(tmax, sizeof(tmax), i->root_distance_max, 0));
FORMAT_TIMESPAN(root_distance, 0),
FORMAT_TIMESPAN(i->root_distance_max, 0));
if (r < 0)
return table_log_add_error(r);
@ -489,15 +487,15 @@ static int print_ntp_status_info(NTPStatusInfo *i) {
r = table_add_cell_stringf(table, NULL, "%s%s",
offset_sign ? "+" : "-",
format_timespan(ts, sizeof(ts), offset, 0));
FORMAT_TIMESPAN(offset, 0));
if (r < 0)
return table_log_add_error(r);
r = table_add_many(table,
TABLE_STRING, "Delay:",
TABLE_STRING, format_timespan(ts, sizeof(ts), delay, 0),
TABLE_STRING, FORMAT_TIMESPAN(delay, 0),
TABLE_STRING, "Jitter:",
TABLE_STRING, format_timespan(jitter, sizeof(jitter), i->jitter, 0),
TABLE_STRING, FORMAT_TIMESPAN(i->jitter, 0),
TABLE_STRING, "Packet count:",
TABLE_UINT64, i->packet_count);
if (r < 0)
@ -717,7 +715,6 @@ static int print_timesync_property(const char *name, const char *expected_value,
case SD_BUS_TYPE_STRUCT:
if (streq(name, "NTPMessage")) {
_cleanup_(ntp_status_info_clear) NTPStatusInfo i = {};
char ts[FORMAT_TIMESPAN_MAX];
r = map_ntp_message(NULL, NULL, m, NULL, &i);
if (r < 0)
@ -733,10 +730,8 @@ static int print_timesync_property(const char *name, const char *expected_value,
printf("{ Leap=%u, Version=%u, Mode=%u, Stratum=%u, Precision=%i,",
i.leap, i.version, i.mode, i.stratum, i.precision);
printf(" RootDelay=%s,",
format_timespan(ts, sizeof(ts), i.root_delay, 0));
printf(" RootDispersion=%s,",
format_timespan(ts, sizeof(ts), i.root_dispersion, 0));
printf(" RootDelay=%s,", FORMAT_TIMESPAN(i.root_delay, 0));
printf(" RootDispersion=%s,", FORMAT_TIMESPAN(i.root_dispersion, 0));
if (i.stratum == 1)
printf(" Reference=%s,", i.reference.str);
@ -749,8 +744,7 @@ static int print_timesync_property(const char *name, const char *expected_value,
printf(" DestinationTimestamp=%s,", FORMAT_TIMESTAMP(i.dest));
printf(" Ignored=%s PacketCount=%" PRIu64 ",",
yes_no(i.spike), i.packet_count);
printf(" Jitter=%s }\n",
format_timespan(ts, sizeof(ts), i.jitter, 0));
printf(" Jitter=%s }\n", FORMAT_TIMESPAN(i.jitter, 0));
return 1;

View File

@ -600,7 +600,6 @@ reenable:
static int on_spawn_timeout(sd_event_source *s, uint64_t usec, void *userdata) {
Spawn *spawn = userdata;
char timeout[FORMAT_TIMESPAN_MAX];
assert(spawn);
@ -610,20 +609,19 @@ static int on_spawn_timeout(sd_event_source *s, uint64_t usec, void *userdata) {
log_device_error(spawn->device, "Spawned process '%s' ["PID_FMT"] timed out after %s, killing",
spawn->cmd, spawn->pid,
format_timespan(timeout, sizeof(timeout), spawn->timeout_usec, USEC_PER_SEC));
FORMAT_TIMESPAN(spawn->timeout_usec, USEC_PER_SEC));
return 1;
}
static int on_spawn_timeout_warning(sd_event_source *s, uint64_t usec, void *userdata) {
Spawn *spawn = userdata;
char timeout[FORMAT_TIMESPAN_MAX];
assert(spawn);
log_device_warning(spawn->device, "Spawned process '%s' ["PID_FMT"] is taking longer than %s to complete",
spawn->cmd, spawn->pid,
format_timespan(timeout, sizeof(timeout), spawn->timeout_warn_usec, USEC_PER_SEC));
FORMAT_TIMESPAN(spawn->timeout_warn_usec, USEC_PER_SEC));
return 1;
}
@ -1080,10 +1078,8 @@ void udev_event_execute_run(UdevEvent *event, usec_t timeout_usec, int timeout_s
log_device_debug_errno(event->dev, r, "Failed to run built-in command \"%s\", ignoring: %m", command);
} else {
if (event->exec_delay_usec > 0) {
char buf[FORMAT_TIMESPAN_MAX];
log_device_debug(event->dev, "Delaying execution of \"%s\" for %s.",
command, format_timespan(buf, sizeof(buf), event->exec_delay_usec, USEC_PER_SEC));
command, FORMAT_TIMESPAN(event->exec_delay_usec, USEC_PER_SEC));
(void) usleep(event->exec_delay_usec);
}

View File

@ -503,18 +503,16 @@ static int run(int argc, char *argv[]) {
n = now(CLOCK_MONOTONIC);
if (n >= usec_add(start_time, RUNTIME_MAX_USEC)) {
char buf[FORMAT_TIMESPAN_MAX];
log_debug("Exiting worker, ran for %s, that's enough.",
format_timespan(buf, sizeof(buf), usec_sub_unsigned(n, start_time), 0));
FORMAT_TIMESPAN(usec_sub_unsigned(n, start_time), 0));
break;
}
if (last_busy_usec == USEC_INFINITY)
last_busy_usec = n;
else if (listen_idle_usec != USEC_INFINITY && n >= usec_add(last_busy_usec, listen_idle_usec)) {
char buf[FORMAT_TIMESPAN_MAX];
log_debug("Exiting worker, been idle for %s.",
format_timespan(buf, sizeof(buf), usec_sub_unsigned(n, last_busy_usec), 0));
FORMAT_TIMESPAN(usec_sub_unsigned(n, last_busy_usec), 0));
break;
}