naccyde / rpms / systemd

Forked from rpms/systemd a year ago
Clone
923a60
From f838bf376249b68205641d1736da2622c0279ed2 Mon Sep 17 00:00:00 2001
923a60
From: chenglin130 <cheng.lin130@zte.com.cn>
923a60
Date: Sat, 20 Jan 2018 17:45:27 +0800
923a60
Subject: [PATCH] core:scope: fix missing fragment_path
923a60
923a60
fragment_path in struct unit is a record of unit file, which will
923a60
be deleted (unlink) in unit_free().
923a60
923a60
After a daemon-reload process, the u->fragment_path of scope unit
923a60
will be missing (NULL). Then, the discarded session scope unit file
923a60
will be redundant until reboot.
923a60
923a60
Steps to Reproduce problem:
923a60
1. ssh access and login
923a60
2. systemctl daemon-reload
923a60
3. ssh logout
923a60
4. discarded session-xxx.scope file will be found in /run/systemd/system/
923a60
923a60
So in a daemon-reload case, scope_load() need unit_load_fragment() to reload
923a60
u->fragment_path.
923a60
---
923a60
 src/core/load-fragment.c | 5 +++++
923a60
 src/core/scope.c         | 4 ++++
923a60
 2 files changed, 9 insertions(+)
923a60
923a60
diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c
923a60
index da58bcc5c9..f3d0851fe2 100644
923a60
--- a/src/core/load-fragment.c
923a60
+++ b/src/core/load-fragment.c
923a60
@@ -3950,6 +3950,11 @@ int unit_load_fragment(Unit *u) {
923a60
         assert(u->load_state == UNIT_STUB);
923a60
         assert(u->id);
923a60
 
923a60
+        if (u->transient && u->fragment_path) {
923a60
+                u->load_state = UNIT_LOADED;
923a60
+                return 0;
923a60
+        }
923a60
+
923a60
         /* First, try to find the unit under its id. We always look
923a60
          * for unit files in the default directories, to make it easy
923a60
          * to override things by placing things in /etc/systemd/system */
923a60
diff --git a/src/core/scope.c b/src/core/scope.c
923a60
index ae6614fbf0..29954ba285 100644
923a60
--- a/src/core/scope.c
923a60
+++ b/src/core/scope.c
923a60
@@ -150,6 +150,10 @@ static int scope_load(Unit *u) {
923a60
         if (!u->transient && UNIT(s)->manager->n_reloading <= 0)
923a60
                 return -ENOENT;
923a60
 
923a60
+        r = unit_load_fragment(u);
923a60
+        if (r < 0)
923a60
+                return r;
923a60
+
923a60
         u->load_state = UNIT_LOADED;
923a60
 
923a60
         r = unit_load_dropin(u);