naccyde / rpms / systemd

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