Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Unified Diff: build/android/pylib/ports.py

Issue 14567016: Make IsHostPortUsed() handle ports bound by foreign UIDs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: build/android/pylib/ports.py
diff --git a/build/android/pylib/ports.py b/build/android/pylib/ports.py
index 74c84c1a0c57f2c8e2b9bac982f93cb3e2ac8b2b..6cc2d9a8c18a8e9cba438d72b7473302fe27bb08 100644
--- a/build/android/pylib/ports.py
+++ b/build/android/pylib/ports.py
@@ -9,7 +9,6 @@ import fcntl
import httplib
import logging
import os
-import re
import socket
import traceback
@@ -83,22 +82,20 @@ def AllocateTestServerPort():
def IsHostPortUsed(host_port):
"""Checks whether the specified host port is used or not.
- Uses -n -P to inhibit the conversion of host/port numbers to host/port names.
-
Args:
host_port: Port on host we want to check.
Returns:
True if the port on host is already used, otherwise returns False.
"""
- port_info = '(\*)|(127\.0\.0\.1)|(localhost):%d' % host_port
- # TODO(jnd): Find a better way to filter the port. Note that connecting to the
- # socket and closing it would leave it in the TIME_WAIT state. Setting
- # SO_LINGER on it and then closing it makes the Python HTTP server crash.
- re_port = re.compile(port_info, re.MULTILINE)
- if re_port.search(cmd_helper.GetCmdOutput(['lsof', '-nPi:%d' % host_port])):
+ try:
+ sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ sock.connect(('127.0.0.1', host_port))
return True
- return False
+ except socket.error as error:
+ return False
+ finally:
+ sock.close()
def IsDevicePortUsed(adb, device_port, state=''):
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698