[gnote] Make timeout work in Process::wait_for_exit
- From: Aurimas Äernius <aurimasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnote] Make timeout work in Process::wait_for_exit
- Date: Mon, 27 Aug 2012 20:14:08 +0000 (UTC)
commit 4f499a9d68e4acd91c73a3a75eb181d4d964c10e
Author: Aurimas Äernius <aurisc4 gmail com>
Date: Mon Aug 27 23:11:55 2012 +0300
Make timeout work in Process::wait_for_exit
src/sharp/process.cpp | 27 +++++++++++++++++++++++----
1 files changed, 23 insertions(+), 4 deletions(-)
---
diff --git a/src/sharp/process.cpp b/src/sharp/process.cpp
index 2f05eac..5f2da90 100644
--- a/src/sharp/process.cpp
+++ b/src/sharp/process.cpp
@@ -105,11 +105,30 @@ void Process::wait_for_exit()
}
}
-bool Process::wait_for_exit(unsigned)
+bool Process::wait_for_exit(unsigned timeout)
{
- // TODO: make timeout work
- wait_for_exit();
- return true;
+ if(m_pid < 0) {
+ return false;
+ }
+ unsigned secs = timeout / 1000;
+ if(timeout % 1000) {
+ ++secs;
+ }
+
+ while(secs--) {
+ int status = -1;
+ waitpid(m_pid, &status, WNOHANG);
+ if(WIFEXITED(status)) {
+ m_exit_code = WEXITSTATUS(status);
+ return true;
+ }
+ if(WIFSIGNALED(status)) {
+ return true;
+ }
+ sleep(1);
+ }
+
+ return false;
}
bool Process::standard_output_eof()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]