diff options
author | Ruben Rodriguez Buchillon <coconutruben@chromium.org> | 2018-08-21 08:16:02 +0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-08-24 03:59:48 -0700 |
commit | 3b39bc56d38511e10871447392b709b3b8e65637 (patch) | |
tree | b2158fd7836122d23655b7820a32c87e6c97ebb5 /util/ec3po/interpreter.py | |
parent | 118ab1fdba370bad2b476be906836657b87734f6 (diff) | |
download | chrome-ec-3b39bc56d38511e10871447392b709b3b8e65637.tar.gz |
ec3po: quit console & interpreter loop when parent process changes.
Right now, when the parent process dies ungracefully - say kill -9 -
then the interpreter, and console processes remain active.
This leads to bugs in the servod implementation from holding on to
sockets, to reinitialization issues of a new instance on the same servod
device.
This change quits the loops inside console & interpreter as soon as the
parent pid changes (i.e. the parent dies).
BRANCH=None
BUG=chromium:841121
TEST=sudo servod -b soraka
ps aux | grep servod
>xxxxx servod
>xxxxy servod
>xxxyx servod
>xxxaa grep servod
sudo kill -9 xxxxx
ps aux | grep servod
>xxxab grep servod
Before this, just kill -9 on the main thread did not take the children
with it.
Change-Id: I547bd92bf8732bff8aef2b72840417c809ba27d6
Signed-off-by: Ruben Rodriguez Buchillon <coconutruben@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1186299
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
Reviewed-by: Nick Sanders <nsanders@chromium.org>
Diffstat (limited to 'util/ec3po/interpreter.py')
-rw-r--r-- | util/ec3po/interpreter.py | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/util/ec3po/interpreter.py b/util/ec3po/interpreter.py index 9a0880f49c..6de8ff7a43 100644 --- a/util/ec3po/interpreter.py +++ b/util/ec3po/interpreter.py @@ -374,7 +374,7 @@ def Crc8(data): return crc >> 8 -def StartLoop(interp): +def StartLoop(interp, ppid = os.getppid()): """Starts an infinite loop of servicing the user and the EC. StartLoop checks to see if there are any commands to process, processing them @@ -389,10 +389,13 @@ def StartLoop(interp): Args: interp: An Interpreter object that has been properly initialised. + ppid: original parent pid to stop loop when parent dies. """ try: - while True: - readable, writeable, _ = select.select(interp.inputs, interp.outputs, []) + while os.getppid() == ppid: + # Timeout every 100ms to catch if the parent has died. + readable, writeable, _ = select.select(interp.inputs, interp.outputs, [], + 0.1) for obj in readable: # Handle any debug prints from the EC. |