systemd package update

Signed-off-by: basebuilder_pel7x64builder0 <basebuilder@powerel.org>
master
basebuilder_pel7x64builder0 2020-03-24 17:47:09 +01:00
parent 6278c8b26b
commit 113516a36c
7 changed files with 536 additions and 5 deletions

View File

@ -15,9 +15,9 @@ index 0779fa5552..f598fdd1e7 100644
--- a/src/core/cgroup.c
+++ b/src/core/cgroup.c
@@ -873,8 +873,7 @@ void unit_destroy_cgroup_if_empty(Unit *u) {

hashmap_remove(u->manager->cgroup_unit, u->cgroup_path);

- free(u->cgroup_path);
- u->cgroup_path = NULL;
+ u->cgroup_path = mfree(u->cgroup_path);
@ -29,11 +29,11 @@ index def36a0930..cabbf8056e 100644
--- a/src/core/unit.c
+++ b/src/core/unit.c
@@ -514,7 +514,7 @@ void unit_free(Unit *u) {

if (u->cgroup_path) {
hashmap_remove(u->manager->cgroup_unit, u->cgroup_path);
- free(u->cgroup_path);
+ u->cgroup_path = mfree(u->cgroup_path);
}

set_remove(u->manager->failed_units, u);

View File

@ -0,0 +1,113 @@
From 3cc0f088de0daa7bb8732128f51b657d30409c03 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
Date: Sat, 22 Oct 2016 22:16:02 -0400
Subject: [PATCH] core: when restarting services, don't close fds

We would close all the stored fds in service_release_resources(), which of
course broke the whole concept of storing fds over service restart.

Fixes #4408.

(cherry picked from commit f0bfbfac43b7faa68ef1bb2ad659c191b9ec85d2)
(cherry picked from commit 4c271437cd695c31e76adb191013009689a7797c)
(cherry picked from commit 10a6469f95c8b8fc43efb3916567e1f15f17bdcf)
Resolves: #1798162
---
src/core/service.c | 22 +++++++++++++++-------
src/core/unit.c | 6 ++++--
src/core/unit.h | 2 +-
3 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/src/core/service.c b/src/core/service.c
index 6b61ccac18..ad45a38270 100644
--- a/src/core/service.c
+++ b/src/core/service.c
@@ -262,7 +262,17 @@ static void service_fd_store_unlink(ServiceFDStore *fs) {
free(fs);
}
-static void service_release_resources(Unit *u) {
+static void service_release_fd_store(Service *s) {
+ assert(s);
+
+ log_unit_debug(UNIT(s)->id, "Releasing all stored fds");
+ while (s->fd_store)
+ service_fd_store_unlink(s->fd_store);
+
+ assert(s->n_fd_store == 0);
+}
+
+static void service_release_resources(Unit *u, bool inactive) {
Service *s = SERVICE(u);
assert(s);
@@ -270,12 +280,10 @@ static void service_release_resources(Unit *u) {
if (!s->fd_store)
return;
- log_debug("Releasing all resources for %s", u->id);
-
- while (s->fd_store)
- service_fd_store_unlink(s->fd_store);
+ log_unit_debug(u->id, "Releasing resources.");
- assert(s->n_fd_store == 0);
+ if (inactive)
+ service_release_fd_store(s);
}
static void service_done(Unit *u) {
@@ -323,7 +331,7 @@ static void service_done(Unit *u) {
s->timer_event_source = sd_event_source_unref(s->timer_event_source);
- service_release_resources(u);
+ service_release_resources(u, true);
}
static int on_fd_store_io(sd_event_source *e, int fd, uint32_t revents, void *userdata) {
diff --git a/src/core/unit.c b/src/core/unit.c
index cabbf8056e..33e0b7126b 100644
--- a/src/core/unit.c
+++ b/src/core/unit.c
@@ -284,6 +284,7 @@ int unit_set_description(Unit *u, const char *description) {
bool unit_may_gc(Unit *u) {
UnitActiveState state;
+ bool inactive;
assert(u);
/* Checks whether the unit is ready to be unloaded for garbage collection.
@@ -301,16 +302,17 @@ bool unit_may_gc(Unit *u) {
return false;
state = unit_active_state(u);
+ inactive = state == UNIT_INACTIVE;
/* If the unit is inactive and failed and no job is queued for
* it, then release its runtime resources */
if (UNIT_IS_INACTIVE_OR_FAILED(state) &&
UNIT_VTABLE(u)->release_resources)
- UNIT_VTABLE(u)->release_resources(u);
+ UNIT_VTABLE(u)->release_resources(u, inactive);
/* But we keep the unit object around for longer when it is
* referenced or configured to not be gc'ed */
- if (state != UNIT_INACTIVE)
+ if (!inactive)
return false;
if (UNIT_VTABLE(u)->no_gc)
diff --git a/src/core/unit.h b/src/core/unit.h
index a6e21d60ce..97a63f0f8b 100644
--- a/src/core/unit.h
+++ b/src/core/unit.h
@@ -359,7 +359,7 @@ struct UnitVTable {
/* When the unit is not running and no job for it queued we
* shall release its runtime resources */
- void (*release_resources)(Unit *u);
+ void (*release_resources)(Unit *u, bool inactive);
/* Return true when this unit is suitable for snapshotting */
bool (*check_snapshot)(Unit *u);

View File

@ -0,0 +1,171 @@
From 7c39b498d6ea21b1c6f4d26b74c064ef2b507706 Mon Sep 17 00:00:00 2001
From: Lennart Poettering <lennart@poettering.net>
Date: Mon, 13 Nov 2017 15:08:49 +0100
Subject: [PATCH] unit: rework a bit how we keep the service fdstore from being
destroyed during service restart

When preparing for a restart we quickly go through the DEAD/INACTIVE
service state before entering AUTO_RESTART. When doing this, we need to
make sure we don't destroy the FD store. Previously this was done by
checking the failure state of the unit, and keeping the FD store around
when the unit failed, under the assumption that the restart logic will
then get into action.

This is not entirely correct howver, as there might be failure states
that will no result in restarts.

With this commit we slightly alter the logic: a ref counter for the fd
store is added, that is increased right before we handle the restart
logic, and decreased again right-after.

This should ensure that the fdstore lives exactly as long as it needs.

Follow-up for f0bfbfac43b7faa68ef1bb2ad659c191b9ec85d2.

(cherry picked from commit 7eb2a8a1259043e107ebec94e30ed160a93f40a7)
(cherry picked from commit e2636bde0f07319d0d35262dac6ff2638ba4e598)
(cherry picked from commit 20b18b7b9aac2532215dba4d56f19989a5fca9f0)
Related: #1798162
---
src/core/service.c | 23 ++++++++++++++++++-----
src/core/service.h | 1 +
src/core/unit.c | 12 ++++--------
src/core/unit.h | 5 ++---
4 files changed, 25 insertions(+), 16 deletions(-)

diff --git a/src/core/service.c b/src/core/service.c
index ad45a38270..283c2968ea 100644
--- a/src/core/service.c
+++ b/src/core/service.c
@@ -265,6 +265,9 @@ static void service_fd_store_unlink(ServiceFDStore *fs) {
static void service_release_fd_store(Service *s) {
assert(s);
+ if (s->n_keep_fd_store > 0)
+ return;
+
log_unit_debug(UNIT(s)->id, "Releasing all stored fds");
while (s->fd_store)
service_fd_store_unlink(s->fd_store);
@@ -272,7 +275,7 @@ static void service_release_fd_store(Service *s) {
assert(s->n_fd_store == 0);
}
-static void service_release_resources(Unit *u, bool inactive) {
+static void service_release_resources(Unit *u) {
Service *s = SERVICE(u);
assert(s);
@@ -282,8 +285,7 @@ static void service_release_resources(Unit *u, bool inactive) {
log_unit_debug(u->id, "Releasing resources.");
- if (inactive)
- service_release_fd_store(s);
+ service_release_fd_store(s);
}
static void service_done(Unit *u) {
@@ -331,7 +333,7 @@ static void service_done(Unit *u) {
s->timer_event_source = sd_event_source_unref(s->timer_event_source);
- service_release_resources(u, true);
+ service_release_resources(u);
}
static int on_fd_store_io(sd_event_source *e, int fd, uint32_t revents, void *userdata) {
@@ -1354,6 +1356,10 @@ static void service_enter_dead(Service *s, ServiceResult f, bool allow_restart)
if (f != SERVICE_SUCCESS)
s->result = f;
+ /* Make sure service_release_resources() doesn't destroy our FD store, while we are changing through
+ * SERVICE_FAILED/SERVICE_DEAD before entering into SERVICE_AUTO_RESTART. */
+ s->n_keep_fd_store++;
+
service_set_state(s, s->result != SERVICE_SUCCESS ? SERVICE_FAILED : SERVICE_DEAD);
if (s->result != SERVICE_SUCCESS) {
@@ -1375,12 +1381,19 @@ static void service_enter_dead(Service *s, ServiceResult f, bool allow_restart)
(!IN_SET(s->main_exec_status.code, CLD_KILLED, CLD_DUMPED) || !set_contains(s->restart_prevent_status.signal, INT_TO_PTR(s->main_exec_status.status)))) {
r = service_arm_timer(s, s->restart_usec);
- if (r < 0)
+ if (r < 0) {
+ s->n_keep_fd_store--;
goto fail;
+ }
service_set_state(s, SERVICE_AUTO_RESTART);
}
+ /* The new state is in effect, let's decrease the fd store ref counter again. Let's also readd us to the GC
+ * queue, so that the fd store is possibly gc'ed again */
+ s->n_keep_fd_store--;
+ unit_add_to_gc_queue(UNIT(s));
+
s->forbid_restart = false;
/* We want fresh tmpdirs in case service is started again immediately */
diff --git a/src/core/service.h b/src/core/service.h
index e0547a464e..81b17db652 100644
--- a/src/core/service.h
+++ b/src/core/service.h
@@ -214,6 +214,7 @@ struct Service {
ServiceFDStore *fd_store;
unsigned n_fd_store;
unsigned n_fd_store_max;
+ unsigned n_keep_fd_store;
};
extern const UnitVTable service_vtable;
diff --git a/src/core/unit.c b/src/core/unit.c
index 33e0b7126b..e74c6bc2cc 100644
--- a/src/core/unit.c
+++ b/src/core/unit.c
@@ -284,7 +284,6 @@ int unit_set_description(Unit *u, const char *description) {
bool unit_may_gc(Unit *u) {
UnitActiveState state;
- bool inactive;
assert(u);
/* Checks whether the unit is ready to be unloaded for garbage collection.
@@ -302,17 +301,14 @@ bool unit_may_gc(Unit *u) {
return false;
state = unit_active_state(u);
- inactive = state == UNIT_INACTIVE;
- /* If the unit is inactive and failed and no job is queued for
- * it, then release its runtime resources */
+ /* If the unit is inactive and failed and no job is queued for it, then release its runtime resources */
if (UNIT_IS_INACTIVE_OR_FAILED(state) &&
UNIT_VTABLE(u)->release_resources)
- UNIT_VTABLE(u)->release_resources(u, inactive);
+ UNIT_VTABLE(u)->release_resources(u);
- /* But we keep the unit object around for longer when it is
- * referenced or configured to not be gc'ed */
- if (!inactive)
+ /* But we keep the unit object around for longer when it is referenced or configured to not be gc'ed */
+ if (state != UNIT_INACTIVE)
return false;
if (UNIT_VTABLE(u)->no_gc)
diff --git a/src/core/unit.h b/src/core/unit.h
index 97a63f0f8b..61ff59e8c7 100644
--- a/src/core/unit.h
+++ b/src/core/unit.h
@@ -357,9 +357,8 @@ struct UnitVTable {
* even though nothing references it and it isn't active in any way. */
bool (*may_gc)(Unit *u);
- /* When the unit is not running and no job for it queued we
- * shall release its runtime resources */
- void (*release_resources)(Unit *u, bool inactive);
+ /* When the unit is not running and no job for it queued we shall release its runtime resources */
+ void (*release_resources)(Unit *u);
/* Return true when this unit is suitable for snapshotting */
bool (*check_snapshot)(Unit *u);

View File

@ -0,0 +1,146 @@
From b62a63582b7985b2fb331a1eab60c1e007a16ac5 Mon Sep 17 00:00:00 2001
From: Evgeny Vereshchagin <evvers@ya.ru>
Date: Tue, 17 Nov 2015 11:21:23 +0000
Subject: [PATCH] tests: add basic journal test

(cherry picked from commit 1c36b4a73b876258fbe01fbe9bc9b750b7dcc9ce)
(cherry picked from commit e974b9915ccc7bf56d23fd6fc67631990d893c89)
(cherry picked from commit d87be62e67f4d7ee8cbd3496a85344f845498c2f)
Related: #1798162
---
test/TEST-04-JOURNAL/Makefile | 1 +
test/TEST-04-JOURNAL/test-journal.sh | 18 +++++++
test/TEST-04-JOURNAL/test.sh | 76 ++++++++++++++++++++++++++++
test/test-functions | 2 +-
4 files changed, 96 insertions(+), 1 deletion(-)
create mode 120000 test/TEST-04-JOURNAL/Makefile
create mode 100755 test/TEST-04-JOURNAL/test-journal.sh
create mode 100755 test/TEST-04-JOURNAL/test.sh

diff --git a/test/TEST-04-JOURNAL/Makefile b/test/TEST-04-JOURNAL/Makefile
new file mode 120000
index 0000000000..e9f93b1104
--- /dev/null
+++ b/test/TEST-04-JOURNAL/Makefile
@@ -0,0 +1 @@
+../TEST-01-BASIC/Makefile
\ No newline at end of file
diff --git a/test/TEST-04-JOURNAL/test-journal.sh b/test/TEST-04-JOURNAL/test-journal.sh
new file mode 100755
index 0000000000..c75f396ceb
--- /dev/null
+++ b/test/TEST-04-JOURNAL/test-journal.sh
@@ -0,0 +1,18 @@
+#!/bin/bash
+
+set -x
+set -e
+set -o pipefail
+
+# Test stdout stream
+
+# Skip empty lines
+ID=$(journalctl --new-id128 | sed -n 2p)
+>/expected
+printf $'\n\n\n' | systemd-cat -t "$ID" --level-prefix false
+journalctl --flush
+journalctl -b -o cat -t "$ID" >/output
+cmp /expected /output
+
+touch /testok
+exit 0
diff --git a/test/TEST-04-JOURNAL/test.sh b/test/TEST-04-JOURNAL/test.sh
new file mode 100755
index 0000000000..e37cb7d412
--- /dev/null
+++ b/test/TEST-04-JOURNAL/test.sh
@@ -0,0 +1,76 @@
+#!/bin/bash
+# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
+# ex: ts=8 sw=4 sts=4 et filetype=sh
+TEST_DESCRIPTION="Journal-related tests"
+
+. $TEST_BASE_DIR/test-functions
+
+check_result_qemu() {
+ ret=1
+ mkdir -p $TESTDIR/root
+ mount ${LOOPDEV}p1 $TESTDIR/root
+ [[ -e $TESTDIR/root/testok ]] && ret=0
+ [[ -f $TESTDIR/root/failed ]] && cp -a $TESTDIR/root/failed $TESTDIR
+ cp -a $TESTDIR/root/var/log/journal $TESTDIR
+ umount $TESTDIR/root
+ [[ -f $TESTDIR/failed ]] && cat $TESTDIR/failed
+ ls -l $TESTDIR/journal/*/*.journal
+ test -s $TESTDIR/failed && ret=$(($ret+1))
+ return $ret
+}
+
+test_run() {
+ if run_qemu; then
+ check_result_qemu || return 1
+ else
+ dwarn "can't run QEMU, skipping"
+ fi
+ if check_nspawn; then
+ run_nspawn
+ check_result_nspawn || return 1
+ else
+ dwarn "can't run systemd-nspawn, skipping"
+ fi
+ return 0
+}
+
+test_setup() {
+ create_empty_image
+ mkdir -p $TESTDIR/root
+ mount ${LOOPDEV}p1 $TESTDIR/root
+
+ # Create what will eventually be our root filesystem onto an overlay
+ (
+ LOG_LEVEL=5
+ eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
+
+ setup_basic_environment
+
+ # setup the testsuite service
+ cat >$initdir/etc/systemd/system/testsuite.service <<EOF
+[Unit]
+Description=Testsuite service
+After=multi-user.target
+
+[Service]
+ExecStart=/test-journal.sh
+Type=oneshot
+EOF
+
+ cp test-journal.sh $initdir/
+
+ setup_testsuite
+ )
+ setup_nspawn_root
+
+ ddebug "umount $TESTDIR/root"
+ umount $TESTDIR/root
+}
+
+test_cleanup() {
+ umount $TESTDIR/root 2>/dev/null
+ [[ $LOOPDEV ]] && losetup -d $LOOPDEV
+ return 0
+}
+
+do_test "$@"
diff --git a/test/test-functions b/test/test-functions
index e50ce556fd..d5e9650903 100644
--- a/test/test-functions
+++ b/test/test-functions
@@ -12,7 +12,7 @@ if ! ROOTLIBDIR=$(pkg-config --variable=systemdutildir systemd); then
ROOTLIBDIR=/usr/lib/systemd
fi
-BASICTOOLS="test sh bash setsid loadkeys setfont login sulogin gzip sleep echo mount umount cryptsetup date dmsetup modprobe chmod chown ln"
+BASICTOOLS="test sh bash setsid loadkeys setfont login sulogin gzip sleep echo mount umount cryptsetup date dmsetup modprobe chmod chown ln sed cmp tee"
DEBUGTOOLS="df free ls stty cat ps ln ip route dmesg dhclient mkdir cp ping dhclient strace less grep id tty touch du sort hostname"
function find_qemu_bin() {

View File

@ -0,0 +1,55 @@
From 0d93b2275f5c93148f509de28cefcf3b7cabc0c7 Mon Sep 17 00:00:00 2001
From: Evgeny Vereshchagin <evvers@ya.ru>
Date: Wed, 30 Dec 2015 03:33:43 +0000
Subject: [PATCH] tests: add regression test for `systemctl restart
systemd-journald`

See https://github.com/systemd/systemd/issues/2236

(cherry picked from commit 3889613ec6bc54b9e02955f62b9d5c5b571c3d4b)
(cherry picked from commit 4dc893c03fe9c56a3d3070fb8583f5584014aa49)
(cherry picked from commit 5c1904dbd1bd3301ce797d2764571b3e3669bec2)
Related: #1798162
---
test/TEST-04-JOURNAL/test-journal.sh | 8 ++++++++
test/TEST-04-JOURNAL/test.sh | 9 +++++++++
2 files changed, 17 insertions(+)

diff --git a/test/TEST-04-JOURNAL/test-journal.sh b/test/TEST-04-JOURNAL/test-journal.sh
index c75f396ceb..701b0cf724 100755
--- a/test/TEST-04-JOURNAL/test-journal.sh
+++ b/test/TEST-04-JOURNAL/test-journal.sh
@@ -14,5 +14,13 @@ journalctl --flush
journalctl -b -o cat -t "$ID" >/output
cmp /expected /output
+# Don't lose streams on restart
+systemctl start forever-print-hola
+sleep 3
+systemctl restart systemd-journald
+sleep 3
+systemctl stop forever-print-hola
+[[ ! -f "/i-lose-my-logs" ]]
+
touch /testok
exit 0
diff --git a/test/TEST-04-JOURNAL/test.sh b/test/TEST-04-JOURNAL/test.sh
index e37cb7d412..6aea67ba4e 100755
--- a/test/TEST-04-JOURNAL/test.sh
+++ b/test/TEST-04-JOURNAL/test.sh
@@ -55,6 +55,15 @@ After=multi-user.target
[Service]
ExecStart=/test-journal.sh
Type=oneshot
+EOF
+
+ cat >$initdir/etc/systemd/system/forever-print-hola.service <<EOF
+[Unit]
+Description=ForeverPrintHola service
+
+[Service]
+Type=simple
+ExecStart=/bin/sh -x -c 'while :; do printf "Hola\n" || touch /i-lose-my-logs; sleep 1; done'
EOF
cp test-journal.sh $initdir/

View File

@ -0,0 +1,34 @@
From cdf21cebfbe324917b7609edb08f23aa940ef038 Mon Sep 17 00:00:00 2001
From: Evgeny Vereshchagin <evvers@ya.ru>
Date: Thu, 20 Oct 2016 13:18:12 +0000
Subject: [PATCH] tests: add test that journald keeps fds over termination by
signal

This test fails before previous commit, and passes with it.

(cherry picked from commit bff653e3970bb79832568ae86b095ee530b62302)
(cherry picked from commit ee8f69ae5ddac6f05c56ea7dbcb76fbbb2e355ee)
(cherry picked from commit ad0bd9f2a41b62fa2f08eeceeff4969e83bfc32a)
Related: #1798162
---
test/TEST-04-JOURNAL/test-journal.sh | 8 ++++++++
1 file changed, 8 insertions(+)

diff --git a/test/TEST-04-JOURNAL/test-journal.sh b/test/TEST-04-JOURNAL/test-journal.sh
index 701b0cf724..d0b05c46d6 100755
--- a/test/TEST-04-JOURNAL/test-journal.sh
+++ b/test/TEST-04-JOURNAL/test-journal.sh
@@ -22,5 +22,13 @@ sleep 3
systemctl stop forever-print-hola
[[ ! -f "/i-lose-my-logs" ]]
+# https://github.com/systemd/systemd/issues/4408
+rm -f /i-lose-my-logs
+systemctl start forever-print-hola
+sleep 3
+systemctl kill --signal=SIGKILL systemd-journald
+sleep 3
+[[ ! -f "/i-lose-my-logs" ]]
+
touch /testok
exit 0

View File

@ -8,7 +8,7 @@
Name: systemd
Url: http://www.freedesktop.org/wiki/Software/systemd
Version: 219
Release: 68%{?dist}
Release: 69%{?dist}
# For a breakdown of the licensing, see README
License: LGPLv2+ and MIT and GPLv2+
Summary: A System and Service Manager
@ -800,6 +800,11 @@ Patch0757: 0757-service-relax-PID-file-symlink-chain-checks-a-bit-81.patch
Patch0758: 0758-path-util-fix-more-path_is_mount-e792e890f-fallout.patch
Patch0759: 0759-core-exclude-.slice-units-from-systemctl-isolate.patch
Patch0760: 0760-unit-fix-potential-use-of-cgroup_path-after-free-whe.patch
Patch0761: 0761-core-when-restarting-services-don-t-close-fds.patch
Patch0762: 0762-unit-rework-a-bit-how-we-keep-the-service-fdstore-fr.patch
Patch0763: 0763-tests-add-basic-journal-test.patch
Patch0764: 0764-tests-add-regression-test-for-systemctl-restart-syst.patch
Patch0765: 0765-tests-add-test-that-journald-keeps-fds-over-terminat.patch

Patch9999: 9999-Update-kernel-install-script-by-backporting-fedora-p.patch

@ -1778,6 +1783,13 @@ fi
%{_mandir}/man8/systemd-resolved.*

%changelog
* Tue Feb 18 2020 systemd maintenance team <systemd-maint@redhat.com> - 219-67.4
- core: when restarting services, don't close fds (#1798162)
- unit: rework a bit how we keep the service fdstore from being destroyed during service restart (#1798162)
- tests: add basic journal test (#1798162)
- tests: add regression test for `systemctl restart systemd-journald` (#1798162)
- tests: add test that journald keeps fds over termination by signal (#1798162)

* Fri Nov 29 2019 Lukas Nykryn <lnykryn@redhat.com> - 219-67.3
- unit: fix potential use of cgroup_path after free() when freeing unit (#1778083)