upload_symbols: fix up kill logic

If the process exited after the check but before the kill, we'll get
an ESRCH error.  Catch & ignore that.

Also fix inverted alive check -- we want to stop killing once the
process is no longer alive.

BUG=chromium:371915
TEST=`./buildbot/run_tests` pass

Change-Id: Icef6ba93dbcf77782de582ed60e98170a8ccb83e
Reviewed-on: https://chromium-review.googlesource.com/199330
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Commit-Queue: Mike Frysinger <vapier@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
Reviewed-by: Yu-Ju Hong <yjhong@chromium.org>
diff --git a/scripts/upload_symbols.py b/scripts/upload_symbols.py
index 5bcb928..1ab568b 100644
--- a/scripts/upload_symbols.py
+++ b/scripts/upload_symbols.py
@@ -13,6 +13,7 @@
 
 import ctypes
 import datetime
+import errno
 import functools
 import hashlib
 import httplib
@@ -717,9 +718,17 @@
       pid = storage_notify_proc.pid
       for sig in (signal.SIGINT, signal.SIGTERM, signal.SIGKILL):
         cros_build_lib.Warning('sending %s to %i', signals.StrSignal(sig), pid)
-        os.kill(pid, sig)
+        # The process might have exited between the last check and the
+        # actual kill below, so ignore ESRCH errors.
+        try:
+          os.kill(pid, sig)
+        except OSError as e:
+          if e.errno == errno.ESRCH:
+            break
+          else:
+            raise
         time.sleep(5)
-        if storage_notify_proc.is_alive():
+        if not storage_notify_proc.is_alive():
           break
 
       # Drain the queue so we don't hang when we finish.