Fixing compile time errors irt exception handling for Python 3. This particular diff fixes problems with Exception handling and the use/misues IRT Python 3 of octal numbers (InvalidToken exceptions).
This commit is contained in:
parent
cf31b4d8b5
commit
b30f6e02f6
1 changed files with 11 additions and 11 deletions
|
@ -168,14 +168,14 @@ def daemonize_self(module, password, port, minutes, pid_file):
|
||||||
vvv("exiting pid %s" % pid)
|
vvv("exiting pid %s" % pid)
|
||||||
# exit first parent
|
# exit first parent
|
||||||
module.exit_json(msg="daemonized accelerate on port %s for %s minutes with pid %s" % (port, minutes, str(pid)))
|
module.exit_json(msg="daemonized accelerate on port %s for %s minutes with pid %s" % (port, minutes, str(pid)))
|
||||||
except OSError, e:
|
except OSError as e:
|
||||||
log("fork #1 failed: %d (%s)" % (e.errno, e.strerror))
|
log("fork #1 failed: %d (%s)" % (e.errno, e.strerror))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# decouple from parent environment
|
# decouple from parent environment
|
||||||
os.chdir("/")
|
os.chdir("/")
|
||||||
os.setsid()
|
os.setsid()
|
||||||
os.umask(022)
|
os.umask(Oo22)
|
||||||
|
|
||||||
# do second fork
|
# do second fork
|
||||||
try:
|
try:
|
||||||
|
@ -187,7 +187,7 @@ def daemonize_self(module, password, port, minutes, pid_file):
|
||||||
pid_file.close()
|
pid_file.close()
|
||||||
vvv("pid file written")
|
vvv("pid file written")
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
except OSError, e:
|
except OSError as e:
|
||||||
log("fork #2 failed: %d (%s)" % (e.errno, e.strerror))
|
log("fork #2 failed: %d (%s)" % (e.errno, e.strerror))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
@ -219,9 +219,9 @@ class LocalSocketThread(Thread):
|
||||||
# make sure the directory is accessible only to this
|
# make sure the directory is accessible only to this
|
||||||
# user, as socket files derive their permissions from
|
# user, as socket files derive their permissions from
|
||||||
# the directory that contains them
|
# the directory that contains them
|
||||||
os.chmod(dir, 0700)
|
os.chmod(dir, Oo700)
|
||||||
elif not os.path.exists(dir):
|
elif not os.path.exists(dir):
|
||||||
os.makedirs(dir, 0700)
|
os.makedirs(dir, Oo700)
|
||||||
except OSError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
self.s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
self.s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||||
|
@ -260,7 +260,7 @@ class LocalSocketThread(Thread):
|
||||||
self.server.last_event = datetime.datetime.now()
|
self.server.last_event = datetime.datetime.now()
|
||||||
finally:
|
finally:
|
||||||
self.server.last_event_lock.release()
|
self.server.last_event_lock.release()
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
vv("key loaded locally was invalid, ignoring (%s)" % e)
|
vv("key loaded locally was invalid, ignoring (%s)" % e)
|
||||||
conn.sendall("BADKEY\n")
|
conn.sendall("BADKEY\n")
|
||||||
finally:
|
finally:
|
||||||
|
@ -520,7 +520,7 @@ class ThreadedTCPRequestHandler(SocketServer.BaseRequestHandler):
|
||||||
if response.get('failed',False):
|
if response.get('failed',False):
|
||||||
log("got a failed response from the master")
|
log("got a failed response from the master")
|
||||||
return dict(failed=True, stderr="Master reported failure, aborting transfer")
|
return dict(failed=True, stderr="Master reported failure, aborting transfer")
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
fd.close()
|
fd.close()
|
||||||
tb = traceback.format_exc()
|
tb = traceback.format_exc()
|
||||||
log("failed to fetch the file: %s" % tb)
|
log("failed to fetch the file: %s" % tb)
|
||||||
|
@ -541,7 +541,7 @@ class ThreadedTCPRequestHandler(SocketServer.BaseRequestHandler):
|
||||||
tmp_path = os.path.expanduser('~/.ansible/tmp/')
|
tmp_path = os.path.expanduser('~/.ansible/tmp/')
|
||||||
if not os.path.exists(tmp_path):
|
if not os.path.exists(tmp_path):
|
||||||
try:
|
try:
|
||||||
os.makedirs(tmp_path, 0700)
|
os.makedirs(tmp_path, Oo700)
|
||||||
except:
|
except:
|
||||||
return dict(failed=True, msg='could not create a temporary directory at %s' % tmp_path)
|
return dict(failed=True, msg='could not create a temporary directory at %s' % tmp_path)
|
||||||
(fd,out_path) = tempfile.mkstemp(prefix='ansible.', dir=tmp_path)
|
(fd,out_path) = tempfile.mkstemp(prefix='ansible.', dir=tmp_path)
|
||||||
|
@ -618,7 +618,7 @@ def daemonize(module, password, port, timeout, minutes, use_ipv6, pid_file):
|
||||||
server = ThreadedTCPServer(address, ThreadedTCPRequestHandler, module, password, timeout, use_ipv6=use_ipv6)
|
server = ThreadedTCPServer(address, ThreadedTCPRequestHandler, module, password, timeout, use_ipv6=use_ipv6)
|
||||||
server.allow_reuse_address = True
|
server.allow_reuse_address = True
|
||||||
break
|
break
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
vv("Failed to create the TCP server (tries left = %d) (error: %s) " % (tries,e))
|
vv("Failed to create the TCP server (tries left = %d) (error: %s) " % (tries,e))
|
||||||
tries -= 1
|
tries -= 1
|
||||||
time.sleep(0.2)
|
time.sleep(0.2)
|
||||||
|
@ -641,7 +641,7 @@ def daemonize(module, password, port, timeout, minutes, use_ipv6, pid_file):
|
||||||
|
|
||||||
v("server thread terminated, exiting!")
|
v("server thread terminated, exiting!")
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
tb = traceback.format_exc()
|
tb = traceback.format_exc()
|
||||||
log("exception caught, exiting accelerated mode: %s\n%s" % (e, tb))
|
log("exception caught, exiting accelerated mode: %s\n%s" % (e, tb))
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
@ -685,7 +685,7 @@ def main():
|
||||||
# process, other than tell the calling program
|
# process, other than tell the calling program
|
||||||
# whether other signals can be sent
|
# whether other signals can be sent
|
||||||
os.kill(daemon_pid, 0)
|
os.kill(daemon_pid, 0)
|
||||||
except OSError, e:
|
except OSError as e:
|
||||||
if e.errno == errno.EPERM:
|
if e.errno == errno.EPERM:
|
||||||
# no permissions means the pid is probably
|
# no permissions means the pid is probably
|
||||||
# running, but as a different user, so fail
|
# running, but as a different user, so fail
|
||||||
|
|
Loading…
Reference in a new issue