Chromium Code Reviews| Index: media/tools/constrained_network_server/traffic_control.py |
| diff --git a/media/tools/constrained_network_server/traffic_control.py b/media/tools/constrained_network_server/traffic_control.py |
| index c27a255365b766cdd68ade24204916fc9d02285d..1b775a0d03ac1af414afbb00bb34a07a1bca68f3 100755 |
| --- a/media/tools/constrained_network_server/traffic_control.py |
| +++ b/media/tools/constrained_network_server/traffic_control.py |
| @@ -9,6 +9,7 @@ Traffic to the constrained port is forwarded to a specified server port. |
| """ |
| import logging |
| +import os |
| import re |
| import subprocess |
| @@ -37,6 +38,28 @@ class TrafficControlError(BaseException): |
| self.error = error |
| +def CheckRequirements(): |
| + """Checks if requirements are available to run traffic control commands. |
|
DaleCurtis
2012/01/09 19:08:02
s/requirements/permissions ?
shadi
2012/01/09 23:47:44
Done.
|
| + |
| + Raises: |
| + TrafficControlError: If requirements to run traffic control commands are not |
| + available. |
| + """ |
| + if os.geteuid() == 0: |
|
DaleCurtis
2012/01/09 19:08:02
Not quite correct. You want os.geteuid() == 0 _OR_
shadi
2012/01/09 23:47:44
Shouldn't the sudo -n <blah> pass if os.geteuid()
|
| + try: |
| + command = ['sudo', '-n', 'iptables', '-L'] |
|
DaleCurtis
2012/01/09 19:08:02
For short commands like these you might consider i
shadi
2012/01/09 23:47:44
Done.
|
| + _Exec(command) |
| + # tc commands only ask for root access when modifying the network state. |
| + command = ['sudo', '-n', 'tc', 'qdisc', 'add'] |
|
DaleCurtis
2012/01/09 19:08:02
For both of these it's enough to just run "--help"
shadi
2012/01/09 23:47:44
I thought we want to try to run a command that *do
|
| + _Exec(command) |
| + except TrafficControlError as e: |
| + if 'No such device' in e.error: |
| + return |
| + pass |
| + raise TrafficControlError('Cannot run traffic control commands. Please check ' |
| + 'that you have root access.') |
| + |
| + |
| def CreateConstrainedPort(config): |
| """Creates a new constrained port. |