From 4b973374ece5cdff44368ef84dfb5ef806c81587 Mon Sep 17 00:00:00 2001 From: ExtinctFire Date: Tue, 26 Jan 2021 18:25:00 +0800 Subject: [PATCH] fix login timeout 2 minutes Signed-off-by: ExtinctFire --- ...-pids-until-the-processes-have-been-.patch | 99 +++++++++++++++++++ ...-make-sure-to-unwatch-all-PIDs-once-.patch | 49 +++++++++ systemd.spec | 10 +- 3 files changed, 157 insertions(+), 1 deletion(-) create mode 100644 core-serialize-u-pids-until-the-processes-have-been-.patch create mode 100644 scope-on-unified-make-sure-to-unwatch-all-PIDs-once-.patch diff --git a/core-serialize-u-pids-until-the-processes-have-been-.patch b/core-serialize-u-pids-until-the-processes-have-been-.patch new file mode 100644 index 0000000..c71b9ae --- /dev/null +++ b/core-serialize-u-pids-until-the-processes-have-been-.patch @@ -0,0 +1,99 @@ +From 428a9f6f1d0396b9eacde2b38d667cbe3f15eb55 Mon Sep 17 00:00:00 2001 +From: Franck Bui +Date: Mon, 16 Nov 2020 15:12:21 +0100 +Subject: [PATCH] core: serialize u->pids until the processes have been moved + to the scope cgroup + +Otherwise if a daemon-reload happens somewhere between the enqueue of the job +start for the scope unit and scope_start() then u->pids might be lost and none +of the processes specified by "PIDs=" will be moved into the scope cgroup. +--- + src/core/scope.c | 37 +++++++++++++++++++++++++++++++++++-- + 1 file changed, 35 insertions(+), 2 deletions(-) + +diff --git a/src/core/scope.c b/src/core/scope.c +index a4db272f93..a372f8d726 100644 +--- a/src/core/scope.c ++++ b/src/core/scope.c +@@ -8,6 +8,7 @@ + #include "dbus-unit.h" + #include "load-dropin.h" + #include "log.h" ++#include "process-util.h" + #include "scope.h" + #include "serialize.h" + #include "special.h" +@@ -235,8 +236,18 @@ static int scope_coldplug(Unit *u) { + if (r < 0) + return r; + +- if (!IN_SET(s->deserialized_state, SCOPE_DEAD, SCOPE_FAILED)) +- (void) unit_enqueue_rewatch_pids(u); ++ if (!IN_SET(s->deserialized_state, SCOPE_DEAD, SCOPE_FAILED)) { ++ if (u->pids) { ++ void *pidp; ++ ++ SET_FOREACH(pidp, u->pids) { ++ r = unit_watch_pid(u, PTR_TO_PID(pidp), false); ++ if (r < 0 && r != -EEXIST) ++ return r; ++ } ++ } else ++ (void) unit_enqueue_rewatch_pids(u); ++ } + + bus_scope_track_controller(s); + +@@ -366,6 +377,10 @@ static int scope_start(Unit *u) { + return r; + } + ++ /* Now u->pids have been moved into the scope cgroup, it's not needed ++ * anymore. */ ++ u->pids = set_free(u->pids); ++ + s->result = SCOPE_SUCCESS; + + scope_set_state(s, SCOPE_RUNNING); +@@ -427,6 +442,7 @@ static int scope_get_timeout(Unit *u, usec_t *timeout) { + + static int scope_serialize(Unit *u, FILE *f, FDSet *fds) { + Scope *s = SCOPE(u); ++ void *pidp; + + assert(s); + assert(f); +@@ -438,6 +454,9 @@ static int scope_serialize(Unit *u, FILE *f, FDSet *fds) { + if (s->controller) + (void) serialize_item(f, "controller", s->controller); + ++ SET_FOREACH(pidp, u->pids) ++ serialize_item_format(f, "pids", PID_FMT, PTR_TO_PID(pidp)); ++ + return 0; + } + +@@ -473,6 +492,20 @@ static int scope_deserialize_item(Unit *u, const char *key, const char *value, F + if (r < 0) + return log_oom(); + ++ } else if (streq(key, "pids")) { ++ pid_t pid; ++ ++ if (parse_pid(value, &pid) < 0) ++ log_unit_debug(u, "Failed to parse pids value: %s", value); ++ else { ++ r = set_ensure_allocated(&u->pids, NULL); ++ if (r < 0) ++ return r; ++ ++ r = set_put(u->pids, PID_TO_PTR(pid)); ++ if (r < 0) ++ return r; ++ } + } else + log_unit_debug(u, "Unknown serialization key: %s", key); + +-- +2.23.0 + diff --git a/scope-on-unified-make-sure-to-unwatch-all-PIDs-once-.patch b/scope-on-unified-make-sure-to-unwatch-all-PIDs-once-.patch new file mode 100644 index 0000000..405dcb9 --- /dev/null +++ b/scope-on-unified-make-sure-to-unwatch-all-PIDs-once-.patch @@ -0,0 +1,49 @@ +From e9eec8b5d2c106c5dd51382a155e6045c7c17c1a Mon Sep 17 00:00:00 2001 +From: Franck Bui +Date: Mon, 30 Nov 2020 15:26:15 +0100 +Subject: [PATCH] scope: on unified, make sure to unwatch all PIDs once they've + been moved to the cgroup scope + +Commit 428a9f6f1d0396b9eacde2b38d667cbe3f15eb55 freed u->pids which is +problematic since the references to this unit in m->watch_pids were no more +removed when the unit was freed. + +This patch makes sure to clean all this refs up before freeing u->pids by +calling unit_unwatch_all_pids(). +--- + src/core/scope.c | 12 +++++++----- + 1 file changed, 7 insertions(+), 5 deletions(-) + +diff --git a/src/core/scope.c b/src/core/scope.c +index 654702ca3b..a247da206f 100644 +--- a/src/core/scope.c ++++ b/src/core/scope.c +@@ -375,10 +375,6 @@ static int scope_start(Unit *u) { + return r; + } + +- /* Now u->pids have been moved into the scope cgroup, it's not needed +- * anymore. */ +- u->pids = set_free(u->pids); +- + s->result = SCOPE_SUCCESS; + + scope_set_state(s, SCOPE_RUNNING); +@@ -386,7 +382,13 @@ static int scope_start(Unit *u) { + /* Set the maximum runtime timeout. */ + scope_arm_timer(s, usec_add(UNIT(s)->active_enter_timestamp.monotonic, s->runtime_max_usec)); + +- /* Start watching the PIDs currently in the scope */ ++ /* On unified we use proper notifications hence we can unwatch the PIDs ++ * we just attached to the scope. This can also be done on legacy as ++ * we're going to update the list of the processes we watch with the ++ * PIDs currently in the scope anyway. */ ++ unit_unwatch_all_pids(u); ++ ++ /* Start watching the PIDs currently in the scope (legacy hierarchy only) */ + (void) unit_enqueue_rewatch_pids(u); + return 1; + } +-- +2.23.0 + diff --git a/systemd.spec b/systemd.spec index 8f89516..5db6b15 100644 --- a/systemd.spec +++ b/systemd.spec @@ -20,7 +20,7 @@ Name: systemd Url: https://www.freedesktop.org/wiki/Software/systemd Version: 246 -Release: 10 +Release: 11 License: MIT and LGPLv2+ and GPLv2+ Summary: System and Service Manager @@ -67,6 +67,8 @@ Patch0015: journal-don-t-enable-systemd-journald-audit.socket-b.patch Patch0016: systemd-change-time-log-level.patch Patch0017: fix-capsh-drop-but-ping-success.patch Patch0018: 0998-resolved-create-etc-resolv.conf-symlink-at-runtime.patch +Patch0019: core-serialize-u-pids-until-the-processes-have-been-.patch +Patch0020: scope-on-unified-make-sure-to-unwatch-all-PIDs-once-.patch BuildRequires: gcc, gcc-c++ BuildRequires: libcap-devel, libmount-devel, pam-devel, libselinux-devel @@ -1483,6 +1485,12 @@ fi %exclude /usr/share/man/man3/* %changelog +* Tue Jan 26 2021 extinctfire - 246-11 +- Type:bugfix +- ID:NA +- SUG:NA +- DESC:fix login timeout 2 minutes + * Fri Dec 18 2020 overweight - 246-10 - Type:bugfix - ID:NA