daandemeyer / rpms / systemd

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