Exit gracefully when socket fails to open

This fixes prevents a traceback that was shown when trying to listen to
an address on which 'bind' fails.
This commit is contained in:
Samuel Mannehed 2024-07-22 00:11:12 +02:00
parent 99f83ca083
commit f05cd203de
1 changed files with 19 additions and 14 deletions

View File

@ -718,6 +718,7 @@ class WebSockifyServer():
be overridden) for each new client connection.
"""
try:
if self.listen_fd != None:
lsock = socket.fromfd(self.listen_fd, socket.AF_INET, socket.SOCK_STREAM)
elif self.unix_listen != None:
@ -732,6 +733,10 @@ class WebSockifyServer():
tcp_keepcnt=self.tcp_keepcnt,
tcp_keepidle=self.tcp_keepidle,
tcp_keepintvl=self.tcp_keepintvl)
except OSError as e:
self.msg("Openening socket failed: %s", str(e))
self.vmsg("exception", exc_info=True)
sys.exit()
if self.daemon:
keepfd = self.get_log_fd()