summaryrefslogtreecommitdiffstats
path: root/cmds
diff options
context:
space:
mode:
authorChristopher Ferris <cferris@google.com>2014-09-09 13:10:49 -0700
committerChristopher Ferris <cferris@google.com>2014-09-09 13:36:52 -0700
commite2c86c71c2a214f6a8bd3335616a58484919dcb1 (patch)
tree7adb52da1d985a9e468b0801b51bc4e65526376e /cmds
parent86aeb9ef154d7aa63c58cbe5be62e5b61d6ae5fa (diff)
downloadframeworks_native-e2c86c71c2a214f6a8bd3335616a58484919dcb1.zip
frameworks_native-e2c86c71c2a214f6a8bd3335616a58484919dcb1.tar.gz
frameworks_native-e2c86c71c2a214f6a8bd3335616a58484919dcb1.tar.bz2
Use time() instead of clock() for timeouts.
The clock() function returns the processor time used by the process. This is not a good timeout mechanism since the code is suspended most of the time waiting for the forked process to finish. Replace with the time() function. Bug: 17154069 (cherry picked from commit 89d4949f86f4f7b6710e951afefad186c667fd6e) Change-Id: I42f0f24ee53ef99955fd482a1089e39d491f3bd5
Diffstat (limited to 'cmds')
-rw-r--r--cmds/dumpstate/utils.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/cmds/dumpstate/utils.c b/cmds/dumpstate/utils.c
index 56287a0..519f2b0 100644
--- a/cmds/dumpstate/utils.c
+++ b/cmds/dumpstate/utils.c
@@ -257,7 +257,7 @@ int dump_file_from_fd(const char *title, const char *path, int fd) {
/* forks a command and waits for it to finish */
int run_command(const char *title, int timeout_seconds, const char *command, ...) {
fflush(stdout);
- clock_t start = clock();
+ time_t start = time(NULL);
pid_t pid = fork();
/* handle error case */
@@ -295,19 +295,19 @@ int run_command(const char *title, int timeout_seconds, const char *command, ...
for (;;) {
int status;
pid_t p = waitpid(pid, &status, WNOHANG);
- float elapsed = (float) (clock() - start) / CLOCKS_PER_SEC;
+ time_t elapsed = time(NULL) - start;
if (p == pid) {
if (WIFSIGNALED(status)) {
printf("*** %s: Killed by signal %d\n", command, WTERMSIG(status));
} else if (WIFEXITED(status) && WEXITSTATUS(status) > 0) {
printf("*** %s: Exit code %d\n", command, WEXITSTATUS(status));
}
- if (title) printf("[%s: %.1fs elapsed]\n\n", command, elapsed);
+ if (title) printf("[%s: %ds elapsed]\n\n", command, (int) elapsed);
return status;
}
if (timeout_seconds && elapsed > timeout_seconds) {
- printf("*** %s: Timed out after %.1fs (killing pid %d)\n", command, elapsed, pid);
+ printf("*** %s: Timed out after %ds (killing pid %d)\n", command, (int) elapsed, pid);
kill(pid, SIGTERM);
return -1;
}