From 19f462f2de4d5513111974dad90b0eb83ae02f9d Mon Sep 17 00:00:00 2001 From: Łukasz Stelmach Date: Tue, 6 Oct 2015 15:57:14 +0200 Subject: analyze: introduce _cleanup_host_info_ --- src/analyze/analyze.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/analyze') diff --git a/src/analyze/analyze.c b/src/analyze/analyze.c index f05f1e5581..043f919a8c 100644 --- a/src/analyze/analyze.c +++ b/src/analyze/analyze.c @@ -318,6 +318,8 @@ finish: } static void free_host_info(struct host_info *hi) { + if (hi == NULL) + return; free(hi->hostname); free(hi->kernel_name); free(hi->kernel_release); @@ -327,6 +329,8 @@ static void free_host_info(struct host_info *hi) { free(hi->architecture); free(hi); } +DEFINE_TRIVIAL_CLEANUP_FUNC(struct host_info*, free_host_info); +#define _cleanup_host_info_ _cleanup_(free_host_infop) static int acquire_time_data(sd_bus *bus, struct unit_times **out) { _cleanup_bus_message_unref_ sd_bus_message *reply = NULL; @@ -537,7 +541,7 @@ static void svg_graph_box(double height, double begin, double end) { static int analyze_plot(sd_bus *bus) { struct unit_times *times; struct boot_times *boot; - struct host_info *host = NULL; + _cleanup_host_info_ struct host_info *host = NULL; int n, m = 1, y=0; double width; _cleanup_free_ char *pretty_times = NULL; @@ -557,7 +561,7 @@ static int analyze_plot(sd_bus *bus) { n = acquire_time_data(bus, ×); if (n <= 0) - goto out; + return n; qsort(times, n, sizeof(struct unit_times), compare_unit_start); @@ -742,8 +746,6 @@ static int analyze_plot(sd_bus *bus) { free_unit_times(times, (unsigned) n); n = 0; -out: - free_host_info(host); return n; } -- cgit v1.2.3-54-g00ecf From 6cdf0399f3f2b7302a79f979cbe160531bd4049a Mon Sep 17 00:00:00 2001 From: Łukasz Stelmach Date: Wed, 23 Sep 2015 17:20:59 +0200 Subject: analyze: do not require information from hostnamed --- src/analyze/analyze.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'src/analyze') diff --git a/src/analyze/analyze.c b/src/analyze/analyze.c index 043f919a8c..ae376a9553 100644 --- a/src/analyze/analyze.c +++ b/src/analyze/analyze.c @@ -436,6 +436,7 @@ fail: static int acquire_host_info(sd_bus *bus, struct host_info **hi) { int r; struct host_info *host; + _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL; static const struct bus_properties_map hostname_map[] = { { "Hostname", "s", NULL, offsetof(struct host_info, hostname) }, @@ -462,21 +463,22 @@ static int acquire_host_info(sd_bus *bus, struct host_info **hi) { hostname_map, host); if (r < 0) - goto fail; + log_debug_errno(r, "Failed to get host information from systemd-hostnamed: %s", + bus_error_message(&error, r)); r = bus_map_all_properties(bus, "org.freedesktop.systemd1", "/org/freedesktop/systemd1", manager_map, host); - if (r < 0) - goto fail; + if (r < 0) { + free_host_info(host); + return log_error_errno(r, "Failed to get host information from systemd: %s", + bus_error_message(&error, r)); + } *hi = host; return 0; -fail: - free_host_info(host); - return r; } static int pretty_boot_time(sd_bus *bus, char **_buf) { -- cgit v1.2.3-54-g00ecf From caeacefe9f4db9c7f853a06d9d50070930a4b2d6 Mon Sep 17 00:00:00 2001 From: Łukasz Stelmach Date: Fri, 2 Oct 2015 09:45:49 +0200 Subject: analyze: replace isempty()+ternary with strempty() --- src/analyze/analyze.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/analyze') diff --git a/src/analyze/analyze.c b/src/analyze/analyze.c index ae376a9553..c2ebdc3443 100644 --- a/src/analyze/analyze.c +++ b/src/analyze/analyze.c @@ -658,13 +658,13 @@ static int analyze_plot(sd_bus *bus) { svg("\n"); svg("%s", pretty_times); svg("%s %s (%s %s %s) %s %s", - isempty(host->os_pretty_name) ? "Linux" : host->os_pretty_name, - isempty(host->hostname) ? "" : host->hostname, - isempty(host->kernel_name) ? "" : host->kernel_name, - isempty(host->kernel_release) ? "" : host->kernel_release, - isempty(host->kernel_version) ? "" : host->kernel_version, - isempty(host->architecture) ? "" : host->architecture, - isempty(host->virtualization) ? "" : host->virtualization); + strempty(host->os_pretty_name), + strempty(host->hostname), + strempty(host->kernel_name), + strempty(host->kernel_release), + strempty(host->kernel_version), + strempty(host->architecture), + strempty(host->virtualization)); svg("\n", 20.0 + (SCALE_X * boot->firmware_time)); svg_graph_box(m, -(double) boot->firmware_time, boot->finish_time); -- cgit v1.2.3-54-g00ecf