Commit f47dbf96 authored by Vincent Pelletier's avatar Vincent Pelletier Committed by Romain Courteaud

Be more specific about caught exception class.

Also, there is little chance for a valid user UID to be None (or a string).
parent f0cea798
...@@ -568,11 +568,12 @@ class Tap: ...@@ -568,11 +568,12 @@ class Tap:
check_file = '/sys/devices/virtual/net/%s/owner' % self.name check_file = '/sys/devices/virtual/net/%s/owner' % self.name
owner_id = None owner_id = None
if os.path.exists(check_file): if os.path.exists(check_file):
owner_id = open(check_file).read().strip()
try: try:
owner_id = int(open(check_file).read().strip()) owner_id = int(owner_id)
except Exception: except ValueError:
pass pass
if (owner_id is None) or (owner_id != pwd.getpwnam(owner.name).pw_uid): if owner_id != pwd.getpwnam(owner.name).pw_uid:
callAndRead(['tunctl', '-t', self.name, '-u', owner.name]) callAndRead(['tunctl', '-t', self.name, '-u', owner.name])
callAndRead(['ip', 'link', 'set', self.name, 'up']) callAndRead(['ip', 'link', 'set', self.name, 'up'])
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment