public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/openrc:0.26.x commit in: src/rc/
@ 2017-05-30 17:49 William Hubbs
  0 siblings, 0 replies; 2+ messages in thread
From: William Hubbs @ 2017-05-30 17:49 UTC (permalink / raw
  To: gentoo-commits

commit:     1967cd402caf6e229263f15aef40c6c4d8f60ce3
Author:     William Hubbs <w.d.hubbs <AT> gmail <DOT> com>
AuthorDate: Mon May 15 23:55:35 2017 +0000
Commit:     William Hubbs <williamh <AT> gentoo <DOT> org>
CommitDate: Tue May 16 00:04:58 2017 +0000
URL:        https://gitweb.gentoo.org/proj/openrc.git/commit/?id=1967cd40

rc_status: calculate time differences in time_t and display seconds in uptime

 src/rc/rc-status.c | 45 ++++++++++++++++++++++++---------------------
 1 file changed, 24 insertions(+), 21 deletions(-)

diff --git a/src/rc/rc-status.c b/src/rc/rc-status.c
index a314bb1d..9a094d47 100644
--- a/src/rc/rc-status.c
+++ b/src/rc/rc-status.c
@@ -83,11 +83,11 @@ static void get_uptime(const char *service, char *uptime, int uptime_size)
 	time_t now;
 	char *start_time_string;
 	time_t start_time;
-	double time_diff;
-	double diff_tmp;
-	double diff_days;
-	double diff_hours;
-	double diff_mins;
+	time_t time_diff;
+	time_t diff_days = (time_t) 0;
+	time_t diff_hours = (time_t) 0;
+	time_t diff_mins = (time_t) 0;
+	time_t diff_secs = (time_t) 0;
 
 	uptime[0] = '\0';
 	if (state & RC_SERVICE_STARTED) {
@@ -96,26 +96,29 @@ static void get_uptime(const char *service, char *uptime, int uptime_size)
 		if (start_count && start_time_string) {
 			start_time = to_time_t(start_time_string);
 			now = time(NULL);
-			time_diff = difftime(now, start_time);
-			diff_tmp = time_diff;
-			if (diff_tmp > 86400.0) {
-				diff_days = diff_tmp / 86400.0;
-				diff_tmp -= diff_days * 86400.0;
+			time_diff = (time_t) difftime(now, start_time);
+			diff_secs = time_diff;
+			if (diff_secs > (time_t) 86400) {
+				diff_days = diff_secs / (time_t) 86400;
+				diff_secs %= diff_days * (time_t) 86400;
 			}
-			if (diff_tmp > 3600.0) {
-				diff_hours = diff_tmp / 3600.0;
-				diff_tmp -= diff_hours * 3600.0;
+			if (diff_secs > (time_t) 3600) {
+				diff_hours = diff_secs / (time_t) 3600;
+				diff_secs %= diff_hours * (time_t) 3600;
 			}
-			if (diff_tmp > 60.0) {
-				diff_mins = diff_tmp / 60.0;
-				diff_tmp -= diff_mins * 60.0;
+			if (diff_secs > (time_t) 60) {
+				diff_mins = diff_secs / (time_t) 60;
+				diff_secs %= diff_mins * (time_t) 60;
 			}
-			if ((int) diff_days > 0)
-				snprintf(uptime, uptime_size, "%.0f days %02.0f:%02.0f (%s)",
-						diff_days, diff_hours, diff_mins, start_count);
+			if (diff_days > 0)
+				snprintf(uptime, uptime_size,
+						"%ld day(s) %02ld:%02ld:%02ld (%s)",
+						diff_days, diff_hours, diff_mins, diff_secs,
+						start_count);
 			else
-				snprintf(uptime, uptime_size, "%02.0f:%02.0f (%s)",
-						diff_hours, diff_mins, start_count);
+				snprintf(uptime, uptime_size,
+						"%02ld:%02ld:%02ld (%s)",
+						diff_hours, diff_mins, diff_secs, start_count);
 		}
 	}
 }


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [gentoo-commits] proj/openrc:0.26.x commit in: src/rc/
@ 2017-05-30 17:49 William Hubbs
  0 siblings, 0 replies; 2+ messages in thread
From: William Hubbs @ 2017-05-30 17:49 UTC (permalink / raw
  To: gentoo-commits

commit:     809c205c356992145b8781ae07a5d3c98b79a8c9
Author:     Sergei Trofimovich <slyfox <AT> inbox <DOT> ru>
AuthorDate: Tue May 30 07:47:55 2017 +0000
Commit:     William Hubbs <williamh <AT> gentoo <DOT> org>
CommitDate: Tue May 30 17:32:35 2017 +0000
URL:        https://gitweb.gentoo.org/proj/openrc.git/commit/?id=809c205c

rc-logger.c: fix crash on fclose(NULL) (#137)

Only close the log if we successfully opened it.

Reported-by: Brian Evans <grknight <AT> gentoo.org>
Tested-by: Brian Evans <grknight <AT> gentoo.org>
Signed-off-by: Sergei Trofimovich <slyfox <AT> gentoo.org>

 src/rc/rc-logger.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/rc/rc-logger.c b/src/rc/rc-logger.c
index b4bd0eae..062ce3d9 100644
--- a/src/rc/rc-logger.c
+++ b/src/rc/rc-logger.c
@@ -261,12 +261,12 @@ rc_logger_open(const char *level)
 						break;
 					}
 				}
+				fclose(log);
 			} else {
 				log_error = 1;
 				eerror("Error: fopen(%s) failed: %s", TMPLOG, strerror(errno));
 			}
 
-			fclose(log);
 			fclose(plog);
 		} else {
 			/*


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-05-30 17:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-05-30 17:49 [gentoo-commits] proj/openrc:0.26.x commit in: src/rc/ William Hubbs
  -- strict thread matches above, loose matches on Subject: below --
2017-05-30 17:49 William Hubbs

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox