[git commit master 1/1] bootchartd: fix sample period calculations

Denys Vlasenko vda.linux at googlemail.com
Mon Jun 28 14:05:54 UTC 2010


commit: http://git.busybox.net/busybox/commit/?id=c03fb3cd7d6b41706a4ade372c5df9c6b951a51c
branch: http://git.busybox.net/busybox/commit/?id=refs/heads/master

Signed-off-by: Keisuke Yasui <keisuke.yasui at toshiba.co.jp>
Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 init/bootchartd.c |   12 +++++++-----
 1 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/init/bootchartd.c b/init/bootchartd.c
index 4e15da4..42b98c8 100644
--- a/init/bootchartd.c
+++ b/init/bootchartd.c
@@ -197,7 +197,7 @@ static char *make_tempdir(void)
 	return tempdir;
 }
 
-static void do_logging(int sample_period_us)
+static void do_logging(unsigned sample_period_us)
 {
 	//# Enable process accounting if configured
 	//if [ "$PROCESS_ACCOUNTING" = "yes" ]; then
@@ -210,7 +210,7 @@ static void do_logging(int sample_period_us)
 	//FILE *proc_netdev = xfopen("proc_netdev.log", "w");
 	FILE *proc_ps = xfopen("proc_ps.log", "w");
 	int look_for_login_process = (getppid() == 1);
-	unsigned count = 60*1000*1000 / (200*1000); /* ~1 minute */
+	unsigned count = 60*1000*1000 / sample_period_us; /* ~1 minute */
 
 	while (--count && !bb_got_signal) {
 		char *p;
@@ -235,8 +235,8 @@ static void do_logging(int sample_period_us)
 			/* dump_procs saw a getty or {g,k,x}dm
 			 * stop logging in 2 seconds:
 			 */
-			if (count > 2*1000*1000 / (200*1000))
-				count = 2*1000*1000 / (200*1000);
+			if (count > 2*1000*1000 / sample_period_us)
+				count = 2*1000*1000 / sample_period_us;
 		}
 		fflush_all();
  wait_more:
@@ -325,7 +325,7 @@ static void finalize(char *tempdir, const char *prog)
 int bootchartd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
 int bootchartd_main(int argc UNUSED_PARAM, char **argv)
 {
-	int sample_period_us;
+	unsigned sample_period_us;
 	pid_t parent_pid, logger_pid;
 	smallint cmd;
 	enum {
@@ -372,6 +372,8 @@ int bootchartd_main(int argc UNUSED_PARAM, char **argv)
 		}
 		config_close(parser);
 	}
+	if ((int)sample_period_us <= 0)
+		sample_period_us = 1; /* prevent division by 0 */
 
 	/* Create logger child: */
 	logger_pid = fork_or_rexec(argv);
-- 
1.7.1



More information about the busybox-cvs mailing list