Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use systemd units for qubesd-spawned daemons #577

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion linux/systemd/qubesd.service
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ Before=systemd-user-sessions.service
Type=notify
ExecStart=/usr/bin/qubesd
StandardOutput=syslog
KillMode=process
Restart=on-failure
RestartSec=1s

Expand Down
30 changes: 21 additions & 9 deletions qubes/vm/qubesvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1724,8 +1724,7 @@ async def start_daemon(*command, input=None, **kwargs):
# some files (like clipboard) may be created as root and cause
# permission problems
qubes_group = grp.getgrnam('qubes')
command = ['runuser', '-u', qubes_group.gr_mem[0], '--'] + \
list(command)
command = ['runuser', '-u', qubes_group.gr_mem[0], '--', *command]
p = await asyncio.create_subprocess_exec(*command, **kwargs)
stdout, stderr = await p.communicate(input=input)
if p.returncode:
Expand All @@ -1740,25 +1739,33 @@ async def start_qrexec_daemon(self, stubdom=False):

self.log.debug('Starting the qrexec daemon')
if stubdom:
qrexec_args = [str(self.stubdom_xid), self.name + '-dm', 'root']
unit = "qrexec-daemon@" + self.name.replace("-", "\\x2d") + "\\x2ddm"
qrexec_args = ["--", str(self.stubdom_xid), self.name + '-dm', 'root']
else:
qrexec_args = [str(self.xid), self.name, self.default_user]
unit = "qrexec-daemon@" + self.name.replace("-", "\\x2d") + ".service"
qrexec_args = ["--", str(self.xid), self.name, self.default_user]

if not self.debug:
qrexec_args.insert(0, "-q")

qrexec_env = os.environ.copy()
if not self.features.check_with_template('qrexec', False):
self.log.debug(
'Starting the qrexec daemon in background, because of features')
qrexec_env['QREXEC_STARTUP_NOWAIT'] = '1'
env_arg = "-EQREXEC_STARTUP_NOWAIT=1"
else:
qrexec_env['QREXEC_STARTUP_TIMEOUT'] = str(self.qrexec_timeout)
env_arg = "-EQREXEC_STARTUP_TIMEOUT=" + str(self.qrexec_timeout)

try:
await self.start_daemon(
qubes.config.system_path['qrexec_daemon_path'], *qrexec_args,
env=qrexec_env, stderr=subprocess.PIPE)
"systemd-run",
"--service-type=forking",
"--user",
"--unit=" + unit,
env_arg,
"--",
qubes.config.system_path['qrexec_daemon_path'],
*qrexec_args,
stderr=subprocess.PIPE)
except subprocess.CalledProcessError as err:
if err.returncode == 3:
raise qubes.exc.QubesVMError(
Expand All @@ -1782,6 +1789,11 @@ async def start_qubesdb(self):
self.log.info('Starting Qubes DB')
try:
await self.start_daemon(
"systemd-run",
"--service-type=notify",
"--user",
"--unit=qubesdb-daemon@" + self.name.replace("-", "\\x2d") + ".service"
"--",
qubes.config.system_path['qubesdb_daemon_path'],
str(self.xid),
self.name)
Expand Down