qmemman: change process model from forking to single process + sd_notify

Forking daemon after initializing hypervisor connection can cause
problems (and actually does in case of libvirt).
To notify systemd when daemon is ready use notify socket (previously it
was termination of parent process).
This commit is contained in:
Marek Marczykowski 2013-05-04 04:33:58 +02:00 committed by Marek Marczykowski-Górecki
parent b242680cc1
commit 4a4fb5e243
2 changed files with 14 additions and 4 deletions

View File

@ -3,7 +3,7 @@ Description=Qubes memory management daemon
After=qubes-core.service
[Service]
Type=forking
Type=notify
ExecStart=/usr/lib/qubes/qmemman_daemon.py
StandardOutput=syslog

View File

@ -26,6 +26,7 @@ import time
import xen.lowlevel.xs
import sys
import os
import socket
from qmemman import SystemState
import qmemman_algo
from ConfigParser import SafeConfigParser
@ -172,6 +173,15 @@ class QMemmanServer:
os.umask(0)
server = SocketServer.UnixStreamServer(SOCK_PATH, QMemmanReqHandler)
os.umask(077)
if os.fork() == 0:
thread.start_new_thread(start_server, tuple([server]))
XS_Watcher().watch_loop()
# notify systemd
nofity_socket = os.getenv('NOTIFY_SOCKET')
if nofity_socket:
s = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
if nofity_socket.startswith('@'):
nofity_socket = '\0%s' % nofity_socket[1:]
s.connect(nofity_socket)
s.sendall("READY=1")
s.close()
thread.start_new_thread(start_server, tuple([server]))
XS_Watcher().watch_loop()