From 83110cb730f3078539a416344cda631788547053 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 5 Jun 2014 11:31:51 +0530 Subject: [PATCH] Linux build: Fix regression that caused opening PDF files (or any externally viewed files) preventing calibre from being restarted as long as the external viewer is not shutdown. Fixes #1326453 [Calibre will not reopen once closed if pdf files have been opened through calibre and left open](https://bugs.launchpad.net/calibre/+bug/1326453) --- src/calibre/utils/ipc/server.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/calibre/utils/ipc/server.py b/src/calibre/utils/ipc/server.py index ffbd58a9ba..48b8a0f2dc 100644 --- a/src/calibre/utils/ipc/server.py +++ b/src/calibre/utils/ipc/server.py @@ -87,6 +87,7 @@ class CriticalError(Exception): _name_counter = 0 if islinux: + import fcntl class LinuxListener(Listener): def __init__(self, *args, **kwargs): @@ -94,6 +95,14 @@ if islinux: # multiprocessing tries to call unlink even on abstract # named sockets, prevent it from doing so. self._listener._unlink.cancel() + # Prevent child processes from inheriting this socket + # If we dont do this child processes not created by calibre, will + # inherit this socket, preventing the calibre GUI from being restarted. + # Examples of such processes are external viewers launched by Qt + # using openUrl(). + fd = self._listener._socket.fileno() + old_flags = fcntl.fcntl(fd, fcntl.F_GETFD) + fcntl.fcntl(fd, fcntl.F_SETFD, old_flags | fcntl.FD_CLOEXEC) def close(self): # To ensure that the socket is released, we have to call