py3: Use native string for singleinstance address format

This commit is contained in:
Kovid Goyal 2019-04-17 08:32:56 +05:30
parent 5623d8c7f4
commit d2bcc94034
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -13,7 +13,7 @@ import time
from functools import partial from functools import partial
from calibre.constants import ( from calibre.constants import (
__appname__, fcntl, filesystem_encoding, islinux, isosx, iswindows, plugins __appname__, fcntl, filesystem_encoding, islinux, isosx, iswindows, plugins, ispy3
) )
from calibre.utils.monotonic import monotonic from calibre.utils.monotonic import monotonic
@ -148,8 +148,10 @@ elif islinux:
name = '%s-singleinstance-%s-%s' % ( name = '%s-singleinstance-%s-%s' % (
__appname__, (os.geteuid() if per_user else ''), name __appname__, (os.geteuid() if per_user else ''), name
) )
name = name.encode('utf-8') name = name
address = b'\0' + name.replace(b' ', b'_') address = '\0' + name.replace(' ', '_')
if not ispy3:
address = address.encode('utf-8')
sock = socket.socket(family=socket.AF_UNIX) sock = socket.socket(family=socket.AF_UNIX)
try: try:
eintr_retry_call(sock.bind, address) eintr_retry_call(sock.bind, address)