From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 699AB138334 for ; Tue, 19 Jun 2018 21:34:34 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id DF4DCE0909; Tue, 19 Jun 2018 21:34:32 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id AD0A9E0909 for ; Tue, 19 Jun 2018 21:34:32 +0000 (UTC) Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id D2329335C99 for ; Tue, 19 Jun 2018 21:34:30 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 59E5C2E4 for ; Tue, 19 Jun 2018 21:34:29 +0000 (UTC) From: "William Hubbs" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "William Hubbs" Message-ID: <1529443128.a6165168953b9c7a62c089ce946476b23b73fb12.williamh@OpenRC> Subject: [gentoo-commits] proj/openrc:master commit in: src/rc/ X-VCS-Repository: proj/openrc X-VCS-Files: src/rc/rc-status.c X-VCS-Directories: src/rc/ X-VCS-Committer: williamh X-VCS-Committer-Name: William Hubbs X-VCS-Revision: a6165168953b9c7a62c089ce946476b23b73fb12 X-VCS-Branch: master Date: Tue, 19 Jun 2018 21:34:29 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: b5500b45-3c7b-4de9-b16d-574f060ff196 X-Archives-Hash: 585511963d379e9c06da930bd7098fc2 commit: a6165168953b9c7a62c089ce946476b23b73fb12 Author: William Hubbs gmail com> AuthorDate: Tue Jun 19 21:15:22 2018 +0000 Commit: William Hubbs gentoo org> CommitDate: Tue Jun 19 21:18:48 2018 +0000 URL: https://gitweb.gentoo.org/proj/openrc.git/commit/?id=a6165168 rc-status: fix gcc 7 warnings src/rc/rc-status.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/rc/rc-status.c b/src/rc/rc-status.c index ab80d901..a6b8d299 100644 --- a/src/rc/rc-status.c +++ b/src/rc/rc-status.c @@ -75,7 +75,7 @@ print_level(const char *prefix, const char *level) printf("%s\n", level); } -static void get_uptime(const char *service, char *uptime, int uptime_size) +static char *get_uptime(const char *service) { RC_SERVICE state = rc_service_state(service); char *start_count; @@ -87,8 +87,8 @@ static void get_uptime(const char *service, char *uptime, int uptime_size) time_t diff_hours = (time_t) 0; time_t diff_mins = (time_t) 0; time_t diff_secs = (time_t) 0; + char *uptime; - uptime[0] = '\0'; if (state & RC_SERVICE_STARTED) { start_count = rc_service_value_get(service, "start_count"); start_time_string = rc_service_value_get(service, "start_time"); @@ -110,23 +110,24 @@ static void get_uptime(const char *service, char *uptime, int uptime_size) diff_secs %= diff_mins * (time_t) 60; } if (diff_days > 0) - snprintf(uptime, uptime_size, + xasprintf(&uptime, "%ld day(s) %02ld:%02ld:%02ld (%s)", diff_days, diff_hours, diff_mins, diff_secs, start_count); else - snprintf(uptime, uptime_size, + xasprintf(&uptime, "%02ld:%02ld:%02ld (%s)", diff_hours, diff_mins, diff_secs, start_count); } } + return uptime; } static void print_service(const char *service) { char status[60]; - char uptime [40]; + char *uptime = NULL; char *child_pid = NULL; char *start_time = NULL; int cols = printf(" %s", service); @@ -155,8 +156,12 @@ print_service(const char *service) free(child_pid); free(start_time); } else { - get_uptime(service, uptime, 40); - snprintf(status, sizeof(status), " started %s", uptime); + uptime = get_uptime(service); + if (uptime) { + snprintf(status, sizeof(status), " started %s", uptime); + free(uptime); + } else + snprintf(status, sizeof(status), " started "); color = ECOLOR_GOOD; } } else if (state & RC_SERVICE_SCHEDULED) {