Skip to content
Snippets Groups Projects
Commit 27bc30d8 authored by Sjoerd Simons's avatar Sjoerd Simons
Browse files

Refresh patchset


- Drop patches from upstream
- Refresh remainder

Signed-off-by: default avatarSjoerd Simons <sjoerd@collabora.com>
parent 027c3e47
No related branches found
No related tags found
No related merge requests found
Showing
with 184 additions and 4186 deletions
......@@ -7,7 +7,6 @@ systemd (247.3-1apertis1) apertis; urgency=medium
+ Don’t build against libdw, since 0.158 isn’t available in target.
* Add /usr to non-unmountable list.
-- Sjoerd Simons <sjoerd@collabora.com> Tue, 16 Mar 2021 21:06:54 +0100
systemd (247.3-1) unstable; urgency=medium
......
From 753dadfde295b15826a414757c664c6a760e979b Mon Sep 17 00:00:00 2001
From: Denis Pynkin <denis.pynkin@collabora.com>
Date: Wed, 10 Mar 2021 01:58:37 +0300
Subject: [PATCH] Add /usr to non-unmountable list
......@@ -20,14 +19,14 @@ unmounting it for Apertis images.
Signed-off-by: Denis Pynkin <denis.pynkin@collabora.com>
---
src/core/umount.c | 2 --
src/shutdown/umount.c | 2 --
1 file changed, 2 deletions(-)
diff --git a/src/core/umount.c b/src/core/umount.c
index 7af0195..26f4c11 100644
--- a/src/core/umount.c
+++ b/src/core/umount.c
@@ -382,9 +382,7 @@ static int delete_dm(dev_t devnum) {
diff --git a/src/shutdown/umount.c b/src/shutdown/umount.c
index 3a72a13..970c055 100644
--- a/src/shutdown/umount.c
+++ b/src/shutdown/umount.c
@@ -500,9 +500,7 @@ static int delete_md(MountPoint *m) {
static bool nonunmountable_path(const char *path) {
return path_equal(path, "/")
......@@ -37,6 +36,3 @@ index 7af0195..26f4c11 100644
|| path_startswith(path, "/run/initramfs");
}
--
2.25.4
From f09e75bfb76f747e966b5ee9c5843a66177871dd Mon Sep 17 00:00:00 2001
From: Denis Pynkin <denis.pynkin@collabora.com>
Date: Tue, 17 Nov 2020 20:03:17 +0300
Subject: [PATCH] Force the call of systemd-journal-flush before `/var` unmount
The problem with failed `/var` unmount placed on separate partition
have a long story: https://github.com/systemd/systemd/issues/867
According messages after the fix integrated into upstream -- there are
some corner cases which aren't fully fixed by patches adding [relinquish
options](https://gitlab.apertis.org/pkg/systemd/-/merge_requests/26)
In case of ostree-based images we have a similar issue since `/var` is
bind-mounted in initramfs. Systemd is trying to unmount `/var` on
shutdown, however `ExecStop=` command from `systemd-journal-flush`
service is not executed during shutdown.
By adding `PartOf=var.mount` into service file we force the
`systemd-journal-flush.service` to be called prior the `/var` unmount.
This allow to unlock the bind-mount, since `journald` have a chance to
re-link it's journal into `/run` with `journalctl
--smart-relinquish-var` call.
Signed-off-by: Denis Pynkin <denis.pynkin@collabora.com>
---
units/systemd-journal-flush.service.in | 1 +
1 file changed, 1 insertion(+)
diff --git a/units/systemd-journal-flush.service.in b/units/systemd-journal-flush.service.in
index bacfe51..c10eece 100644
--- a/units/systemd-journal-flush.service.in
+++ b/units/systemd-journal-flush.service.in
@@ -15,6 +15,7 @@ Requires=systemd-journald.service
After=systemd-journald.service systemd-remount-fs.service
Before=systemd-tmpfiles-setup.service
RequiresMountsFor=/var/log/journal
+PartOf=var.mount
[Service]
ExecStart=@rootbindir@/journalctl --flush
--
2.25.4
From: Denis Pynkin <denis.pynkin@collabora.com>
Date: Thu, 14 Feb 2019 00:04:13 +0300
Subject: [PATCH 2/3] Remove bashisms from the UEFI entries generator
Subject: Remove bashisms from the UEFI entries generator
- Use [ not [[ and -n to test for non-emptiness
- Use shell lists instead of arrays
......@@ -8,60 +8,54 @@ Subject: [PATCH 2/3] Remove bashisms from the UEFI entries generator
Signed-off-by: Denis Pynkin <denis.pynkin@collabora.com>
Signed-off-by: Frederic Dalleau <frederic.dalleau@collabora.com>
---
src/kernel-install/90-loaderentry.install | 81 ++++++++++++++++++-------------
1 file changed, 47 insertions(+), 34 deletions(-)
src/kernel-install/90-loaderentry.install | 77 +++++++++++++++++--------------
1 file changed, 43 insertions(+), 34 deletions(-)
diff --git a/src/kernel-install/90-loaderentry.install b/src/kernel-install/90-loaderentry.install
index 75dd5a1..c7d0ac4 100644
index d096745..9e1b910 100644
--- a/src/kernel-install/90-loaderentry.install
+++ b/src/kernel-install/90-loaderentry.install
@@ -1,4 +1,4 @@
-#!/bin/bash
-#!/usr/bin/env bash
+#!/bin/sh
# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# ex: ts=8 sw=4 sts=4 et filetype=sh
@@ -6,68 +6,71 @@ COMMAND="$1"
@@ -6,13 +6,13 @@ COMMAND="$1"
KERNEL_VERSION="$2"
BOOT_DIR_ABS="$3"
ENTRY_DIR_ABS="$3"
KERNEL_IMAGE="$4"
-INITRD_OPTIONS_START="5"
+INITRD_OPTIONS_SHIFT="4"
+INITRD_OPTIONS_START="4"
-if ! [[ $KERNEL_INSTALL_MACHINE_ID ]]; then
- exit 0
+if ! [ -n "$KERNEL_INSTALL_MACHINE_ID" ]; then
+ if ! [ -f /etc/machine-id ]; then
+ exit 0
+ fi
+ read KERNEL_INSTALL_MACHINE_ID </etc/machine-id
+if ! [ -n $KERNEL_INSTALL_MACHINE_ID ]; then
exit 0
fi
-if ! [[ -d "$BOOT_DIR_ABS" ]]; then
+if ! [ -d "$BOOT_DIR_ABS" ]; then
-if ! [[ -d "$ENTRY_DIR_ABS" ]]; then
+if ! [ -d "$ENTRY_DIR_ABS" ]; then
exit 0
fi
MACHINE_ID=$KERNEL_INSTALL_MACHINE_ID
BOOT_DIR="/$MACHINE_ID/$KERNEL_VERSION"
-BOOT_ROOT=${BOOT_DIR_ABS%$BOOT_DIR}
+BOOT_ROOT="${BOOT_DIR_ABS%$BOOT_DIR}"
@@ -22,48 +22,47 @@ BOOT_ROOT=${ENTRY_DIR_ABS%/$MACHINE_ID/$KERNEL_VERSION}
BOOT_MNT=$(stat -c %m $BOOT_ROOT)
ENTRY_DIR=${ENTRY_DIR_ABS#$BOOT_MNT}
-if [[ $COMMAND == remove ]]; then
+if [ "$COMMAND" = "remove" ]; then
+if [ $COMMAND = "remove" ]; then
rm -f "$BOOT_ROOT/loader/entries/$MACHINE_ID-$KERNEL_VERSION.conf"
rm -f "$BOOT_ROOT/loader/entries/$MACHINE_ID-$KERNEL_VERSION+"*".conf"
exit 0
fi
-if ! [[ $COMMAND == add ]]; then
+if ! [ "$COMMAND" = "add" ]; then
+if ! [ $COMMAND = "add" ]; then
exit 1
fi
-if ! [[ $KERNEL_IMAGE ]]; then
+if [ -z "$KERNEL_IMAGE" ]; then
+if ! [ -z "$KERNEL_IMAGE" ]; then
exit 1
fi
......@@ -74,39 +68,35 @@ index 75dd5a1..c7d0ac4 100644
fi
-if ! [[ $PRETTY_NAME ]]; then
+if [ -z "$PRETTY_NAME" ]; then
+if ! [ -z "$PRETTY_NAME" ]; then
PRETTY_NAME="Linux $KERNEL_VERSION"
fi
-declare -a BOOT_OPTIONS
-
-if [[ -f /etc/kernel/cmdline ]]; then
- read -r -d '' -a BOOT_OPTIONS < /etc/kernel/cmdline
+if [ -f /etc/kernel/cmdline ]; then
+ read -r BOOT_OPTIONS < /etc/kernel/cmdline
fi
-if ! [[ ${BOOT_OPTIONS[*]} ]]; then
-elif [[ -f /usr/lib/kernel/cmdline ]]; then
- read -r -d '' -a BOOT_OPTIONS < /usr/lib/kernel/cmdline
-else
- declare -a BOOT_OPTIONS
-
- read -r -d '' -a line < /proc/cmdline
- for i in "${line[@]}"; do
- [[ "${i#initrd=*}" != "$i" ]] && continue
- [[ "${i#BOOT_IMAGE=*}" != "$i" ]] && continue
- BOOT_OPTIONS+=("$i")
- done
+if [ -z "${BOOT_OPTIONS}" ] && [ -f "/proc/cmdline" ]; then
+if [ -f /etc/kernel/cmdline ]; then
+ read -r BOOT_OPTIONS < /etc/kernel/cmdline
+elif [ -f /usr/lib/kernel/cmdline ]; then
+ read -r BOOT_OPTIONS < /usr/lib/kernel/cmdline
+elif [ -f "/proc/cmdline" ]; then
+ BOOT_OPTIONS=$(
+ cat /proc/cmdline | tr ' ' '\n' | \
+ while read -r i; do
+ [ "${i#initrd=*}" != "$i" ] && continue
+ echo -n " $i"
+ done
+ )
fi
-if ! [[ ${BOOT_OPTIONS[*]} ]]; then
+if [ -z "${BOOT_OPTIONS}" ]; then
echo "Could not determine the kernel command line parameters." >&2
echo "Please specify the kernel command line in /etc/kernel/cmdline!" >&2
exit 1
+ )
fi
-if [[ -f /etc/kernel/tries ]]; then
......@@ -117,7 +107,7 @@ index 75dd5a1..c7d0ac4 100644
echo "/etc/kernel/tries does not contain an integer." >&2
exit 1
fi
@@ -83,11 +86,20 @@ cp "$KERNEL_IMAGE" "$BOOT_DIR_ABS/linux" &&
@@ -79,11 +78,20 @@ cp "$KERNEL_IMAGE" "$ENTRY_DIR_ABS/linux" &&
exit 1
}
......@@ -125,12 +115,12 @@ index 75dd5a1..c7d0ac4 100644
+shift $INITRD_OPTIONS_SHIFT
+INITRD_OPTIONS=""
+while [ $# -gt 0 ] ; do
+ if [ -z "$INITRD_OPTIONS" ] ; then
+ INITRD_OPTIONS="$1"
+ else
+ INITRD_OPTIONS="$INITRD_OPTIONS\n$1"
+ fi
+ shift
+ if [ -z "$INITRD_OPTIONS" ] ; then
+ INITRD_OPTIONS="$1"
+ else
+ INITRD_OPTIONS="$INITRD_OPTIONS\n$1"
+ fi
+ shift
+done
-for initrd in "${INITRD_OPTIONS[@]}"; do
......@@ -139,28 +129,28 @@ index 75dd5a1..c7d0ac4 100644
+echo "${INITRD_OPTIONS}" | while read initrd; do
+ if [ -f "${initrd}" ]; then
+ initrd_basename=$(basename "${initrd}")
cp "${initrd}" "$BOOT_DIR_ABS/${initrd_basename}" &&
chown root:root "$BOOT_DIR_ABS/${initrd_basename}" &&
chmod 0644 "$BOOT_DIR_ABS/${initrd_basename}" || {
@@ -99,7 +111,7 @@ done
[ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && \
echo "Installing $ENTRY_DIR_ABS/${initrd_basename}"
cp "${initrd}" "$ENTRY_DIR_ABS/${initrd_basename}" &&
@@ -97,7 +105,7 @@ done
# If no initrd option is supplied, fallback to "initrd" which is
# If no initrd option is supplied, fall back to "initrd" which is
# the name used by dracut when generating it in its kernel-install hook
-[[ ${#INITRD_OPTIONS[@]} == 0 ]] && INITRD_OPTIONS=( initrd )
+[ -z "${INITRD_OPTIONS}" ] && INITRD_OPTIONS=initrd
mkdir -p "${LOADER_ENTRY%/*}" || {
echo "Could not create loader entry directory '${LOADER_ENTRY%/*}'." >&2
@@ -110,11 +122,12 @@ mkdir -p "${LOADER_ENTRY%/*}" || {
@@ -110,11 +118,12 @@ mkdir -p "${LOADER_ENTRY%/*}" || {
echo "title $PRETTY_NAME"
echo "version $KERNEL_VERSION"
echo "machine-id $MACHINE_ID"
- echo "options ${BOOT_OPTIONS[*]}"
+ echo "options $BOOT_OPTIONS"
echo "linux $BOOT_DIR/linux"
+ echo "options ${BOOT_OPTIONS}"
echo "linux $ENTRY_DIR/linux"
- for initrd in "${INITRD_OPTIONS[@]}"; do
- [[ -f $BOOT_DIR_ABS/$(basename ${initrd}) ]] && \
- echo "initrd $BOOT_DIR/$(basename ${initrd})"
- [[ -f $ENTRY_DIR_ABS/$(basename ${initrd}) ]] && \
- echo "initrd $ENTRY_DIR/$(basename ${initrd})"
+ echo "${INITRD_OPTIONS}" | while read initrd; do
+ initrd_basename=$(basename "${initrd}")
+ [ -f "$BOOT_DIR_ABS/${initrd_basename}" ] && \
......
From fedc892fb38e059a2f675f33770ddd9e4cad235f Mon Sep 17 00:00:00 2001
From: Denis Pynkin <denis.pynkin@collabora.com>
Date: Thu, 24 Jan 2019 22:40:46 +0300
Subject: [PATCH 1/3] Remove bashisms from the depmod wrapper
Subject: Remove bashisms from the depmod wrapper
- Use [ not [[ and -n to test for non-emptiness
- Use for loop instead of comma expansion
......@@ -10,45 +9,52 @@ Signed-off-by: Denis Pynkin <denis.pynkin@collabora.com>
[ Rebased to the latest master, amended the rm call ]
Signed-off-by: Andrej Shadura <andrew.shadura@collabora.co.uk>
---
src/kernel-install/50-depmod.install | 19 +++++++++++++++----
1 file changed, 15 insertions(+), 4 deletions(-)
src/kernel-install/50-depmod.install | 21 ++++++++++++++++-----
1 file changed, 16 insertions(+), 5 deletions(-)
diff --git a/src/kernel-install/50-depmod.install b/src/kernel-install/50-depmod.install
index 88f550a486..78fdf6b7ea 100644
index 3850eac..2b026da 100644
--- a/src/kernel-install/50-depmod.install
+++ b/src/kernel-install/50-depmod.install
@@ -1,16 +1,27 @@
-#!/bin/bash
+#!/bin/sh
@@ -1,4 +1,4 @@
-#!/usr/bin/env bash
+#!//bin/sh
# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# ex: ts=8 sw=4 sts=4 et filetype=sh
-[[ $2 ]] || exit 1
+[ -n "$2" ] || exit 1
@@ -8,11 +8,11 @@ ENTRY_DIR_ABS="$3"
KERNEL_IMAGE="$4"
INITRD_OPTIONS_START="5"
case "$1" in
-[[ $KERNEL_VERSION ]] || exit 1
+[ -n $KERNEL_VERSION ] || exit 1
case "$COMMAND" in
add)
- [[ -d /lib/modules/"$2"/kernel ]] || exit 0
+ [ -d "/lib/modules/$2/kernel" ] || exit 0
exec depmod -a "$2"
;;
- [[ -d "/lib/modules/${KERNEL_VERSION}/kernel" ]] || exit 0
+ [ -d "/lib/modules/${KERNEL_VERSION}/kernel" ] || exit 0
[ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && \
echo "Running depmod -a ${KERNEL_VERSION}"
exec depmod -a "${KERNEL_VERSION}"
@@ -20,8 +20,19 @@ case "$COMMAND" in
remove)
- exec rm -f /lib/modules/"$2"/modules.{alias{,.bin},builtin.bin,dep{,.bin},devname,softdep,symbols{,.bin}}
[ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && \
echo "Removing /lib/modules/${KERNEL_VERSION}/modules.dep and associated files"
- exec rm -f /lib/modules/"${KERNEL_VERSION}"/modules.{alias{,.bin},builtin.bin,dep{,.bin},devname,softdep,symbols{,.bin}}
- ;;
+ for d in alias \
+ alias.bin \
+ builtin.bin \
+ dep \
+ dep.bin \
+ devname \
+ softdep \
+ symbols \
+ symbols.bin
+ alias.bin \
+ builtin.bin \
+ dep \
+ dep.bin \
+ devname \
+ softdep \
+ symbols \
+ symbols.bin
+ do
+ rm -f "/lib/modules/$2/modules.$d"
+ done
;;
+ ;;
*)
exit 0
--
2.19.2
esac
From: Denis Pynkin <denis.pynkin@collabora.com>
Date: Thu, 14 Feb 2019 00:46:48 +0300
Subject: [PATCH 3/3] Reworked kernel-install script
Subject: Reworked kernel-install script
- Removed bashisms -- script is adapted for running with `/bin/sh`
- Add support of calling the script without passing the kernel image.
......@@ -13,23 +13,20 @@ Subject: [PATCH 3/3] Reworked kernel-install script
Signed-off-by: Denis Pynkin <denis.pynkin@collabora.com>
Signed-off-by: Frederic Dalleau <frederic.dalleau@collabora.com>
---
src/kernel-install/kernel-install | 100 ++++++++++++++++++++++----------------
1 file changed, 57 insertions(+), 43 deletions(-)
mode change 100644 => 100755 src/kernel-install/kernel-install
src/kernel-install/kernel-install | 99 ++++++++++++++++++++++-----------------
1 file changed, 56 insertions(+), 43 deletions(-)
diff --git a/src/kernel-install/kernel-install b/src/kernel-install/kernel-install
old mode 100644
new mode 100755
index b85c7c5..3ca2071
index e7457e9..edd6514 100755
--- a/src/kernel-install/kernel-install
+++ b/src/kernel-install/kernel-install
@@ -1,4 +1,4 @@
-#!/bin/bash
-#!/usr/bin/env bash
+#!/bin/sh
# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# ex: ts=8 sw=4 sts=4 et filetype=sh
# SPDX-License-Identifier: LGPL-2.1+
@@ -31,22 +31,18 @@ usage()
# SPDX-License-Identifier: LGPL-2.1-or-later
@@ -33,22 +33,18 @@ usage()
dropindirs_sort()
{
local suffix=$1; shift
......@@ -61,23 +58,31 @@ index b85c7c5..3ca2071
echo "$d/$f"
continue 2
fi
@@ -57,42 +53,58 @@ dropindirs_sort()
@@ -59,51 +55,65 @@ dropindirs_sort()
export LC_COLLATE=C
for i in "$@"; do
- if [ "$i" == "--help" -o "$i" == "-h" ]; then
+ if [ "$i" = "--help" ] || [ "$i" = "-h" ]; then
+ if [ "$i" = "--help" -o "$i" = "-h" ]; then
usage
exit 0
fi
done
KERNEL_INSTALL_VERBOSE=0
-if [ "$1" == "--verbose" -o "$1" == "-v" ]; then
+if [ "$1" = "--verbose" -o "$1" = "-v" ]; then
shift
KERNEL_INSTALL_VERBOSE=1
fi
export KERNEL_INSTALL_VERBOSE
-if [[ "${0##*/}" == 'installkernel' ]]; then
+INITRD_OPTIONS=""
+if [ "${0%installkernel}" != "${0}" ]; then
COMMAND='add'
- # make install doesn't pass any parameter wrt initrd handling
- INITRD_OPTIONS=()
# make install doesn't pass any parameter wrt initrd handling
INITRD_OPTIONS=()
+ KERNEL_VERSION="$1"
+ KERNEL_IMAGE="$2"
+elif [ "${0%removekernel}" != "${0}" ]; then
......@@ -86,26 +91,32 @@ index b85c7c5..3ca2071
+ KERNEL_IMAGE="$2"
else
COMMAND="$1"
+ KERNEL_VERSION="$2"
+ KERNEL_IMAGE="$3"
+ KERNEL_VERSION="$1"
+ KERNEL_IMAGE="$2"
shift
- INITRD_OPTIONS=( "${@:3}" )
+ while [ $# -gt 2 ] ; do
+ if [ -z "$INITRD_OPTIONS" ] ; then
+ INITRD_OPTIONS="$3"
+ else
+ INITRD_OPTIONS="$INITRD_OPTIONS\n$3"
+ fi
+ shift
+ if [ -z "$INITRD_OPTIONS" ] ; then
+ INITRD_OPTIONS="$3"
+ else
+ INITRD_OPTIONS="$INITRD_OPTIONS\n$3"
+ fi
+ shift
+ done
fi
-KERNEL_VERSION="$1"
-KERNEL_IMAGE="$2"
-
-if [[ -f /etc/machine-id ]]; then
+if [ -f /etc/machine-id ]; then
# Reuse directory created without a machine ID present if it exists.
-if [[ -d /efi/Default ]] || [[ -d /boot/Default ]] || [[ -d /boot/efi/Default ]]; then
+if [ -d /efi/Default ] || [ -d /boot/Default ] || [ -d /boot/efi/Default ]; then
MACHINE_ID="Default"
-elif [[ -f /etc/machine-id ]]; then
+elif [ -f /etc/machine-id ]; then
read MACHINE_ID < /etc/machine-id
else
MACHINE_ID="Default"
fi
-if [[ ! $COMMAND ]] || [[ ! $KERNEL_VERSION ]]; then
......@@ -114,27 +125,18 @@ index b85c7c5..3ca2071
exit 1
fi
-if ! [[ $MACHINE_ID ]]; then
+# According to man page 2-nd parameter could be skipped
+if [ -z "$KERNEL_IMAGE" ]; then
+ KERNEL_IMAGE="/boot/vmlinuz-$KERNEL_VERSION"
+fi
+
+if [ -z "$MACHINE_ID" ]; then
BOOT_DIR_ABS=$(mktemp -d /tmp/kernel-install.XXXXX) || exit 1
trap "rm -rf '$BOOT_DIR_ABS'" EXIT INT QUIT PIPE
-elif [[ -d /efi/loader/entries ]] || [[ -d /efi/$MACHINE_ID ]]; then
+elif [ -d /efi/loader/entries ] || [ -d /efi/$MACHINE_ID ]; then
BOOT_DIR_ABS="/efi/$MACHINE_ID/$KERNEL_VERSION"
-if [[ -d /efi/loader/entries ]] || [[ -d /efi/$MACHINE_ID ]]; then
+if [ -d /efi/loader/entries ] || [ -d /efi/$MACHINE_ID ]; then
ENTRY_DIR_ABS="/efi/$MACHINE_ID/$KERNEL_VERSION"
-elif [[ -d /boot/loader/entries ]] || [[ -d /boot/$MACHINE_ID ]]; then
+elif [ -d /boot/loader/entries ] || [ -d /boot/$MACHINE_ID ]; then
BOOT_DIR_ABS="/boot/$MACHINE_ID/$KERNEL_VERSION"
ENTRY_DIR_ABS="/boot/$MACHINE_ID/$KERNEL_VERSION"
-elif [[ -d /boot/efi/loader/entries ]] || [[ -d /boot/efi/$MACHINE_ID ]]; then
+elif [ -d /boot/efi/loader/entries ] || [ -d /boot/efi/$MACHINE_ID ]; then
BOOT_DIR_ABS="/boot/efi/$MACHINE_ID/$KERNEL_VERSION"
ENTRY_DIR_ABS="/boot/efi/$MACHINE_ID/$KERNEL_VERSION"
elif mountpoint -q /efi; then
BOOT_DIR_ABS="/efi/$MACHINE_ID/$KERNEL_VERSION"
@@ -106,15 +118,16 @@ export KERNEL_INSTALL_MACHINE_ID=$MACHINE_ID
ENTRY_DIR_ABS="/efi/$MACHINE_ID/$KERNEL_VERSION"
@@ -117,51 +127,53 @@ export KERNEL_INSTALL_MACHINE_ID=$MACHINE_ID
ret=0
......@@ -150,20 +152,29 @@ index b85c7c5..3ca2071
case $COMMAND in
add)
- if [[ ! "$KERNEL_IMAGE" ]]; then
- echo "Command 'add' requires an argument" >&2
- exit 1
+ # According to man page 2-nd parameter could be skipped
+ if [ -z "$KERNEL_IMAGE" ]; then
echo "Command 'add' requires an argument" >&2
exit 1
+ KERNEL_IMAGE="/boot/vmlinuz-$KERNEL_VERSION"
fi
@@ -124,42 +137,42 @@ case $COMMAND in
- if [[ ! -f "$KERNEL_IMAGE" ]]; then
+ if [ ! -f "$KERNEL_IMAGE" ]; then
echo "Kernel image argument ${KERNEL_IMAGE} not a file" >&2
exit 1
}
fi
- for f in "${PLUGINS[@]}"; do
- if [[ -x $f ]]; then
- "$f" add "$KERNEL_VERSION" "$BOOT_DIR_ABS" "$KERNEL_IMAGE" "${INITRD_OPTIONS[@]}"
+ plugins_list | while read f; do
+ if [ -x "$f" ]; then
+ "$f" add "$KERNEL_VERSION" "$BOOT_DIR_ABS" "$KERNEL_IMAGE" "${INITRD_OPTIONS}"
+
[ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && \
- echo "+$f add $KERNEL_VERSION $ENTRY_DIR_ABS $KERNEL_IMAGE ${INITRD_OPTIONS[@]}"
- "$f" add "$KERNEL_VERSION" "$ENTRY_DIR_ABS" "$KERNEL_IMAGE" "${INITRD_OPTIONS[@]}"
+ echo "+$f add $KERNEL_VERSION $ENTRY_DIR_ABS $KERNEL_IMAGE ${INITRD_OPTIONS}"
+ "$f" add "$KERNEL_VERSION" "$ENTRY_DIR_ABS" "$KERNEL_IMAGE" "${INITRD_OPTIONS}"
x=$?
- if [[ $x == $SKIP_REMAINING ]]; then
+ if [ $x = $SKIP_REMAINING ]; then
......@@ -171,19 +182,9 @@ index b85c7c5..3ca2071
break
fi
- ((ret+=$x))
+ ret=`expr $ret + $x`
+ ret=`expr $ret + $?
fi
done
- if ! [[ $MACHINE_ID ]] && ! rmdir "$BOOT_DIR_ABS"; then
+ if [ -z "$MACHINE_ID" ] && ! rmdir "$BOOT_DIR_ABS"; then
echo "Warning: In kernel-install plugins, requiring BOOT_DIR_ABS to be preset is deprecated." >&2
echo " All plugins should not put anything in BOOT_DIR_ABS if the environment" >&2
echo " variable KERNEL_INSTALL_MACHINE_ID is empty." >&2
rm -rf "$BOOT_DIR_ABS"
- ((ret+=$?))
+ ret=`expr $ret + $?`
fi
;;
remove)
......@@ -191,7 +192,9 @@ index b85c7c5..3ca2071
- if [[ -x $f ]]; then
+ plugins_list | while read f; do
+ if [ -x "$f" ]; then
"$f" remove "$KERNEL_VERSION" "$BOOT_DIR_ABS"
[ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && \
echo "+$f remove $KERNEL_VERSION $ENTRY_DIR_ABS"
"$f" remove "$KERNEL_VERSION" "$ENTRY_DIR_ABS"
x=$?
- if [[ $x == $SKIP_REMAINING ]]; then
+ if [ $x = $SKIP_REMAINING ]; then
......@@ -203,13 +206,16 @@ index b85c7c5..3ca2071
fi
done
rm -rf "$BOOT_DIR_ABS"
@@ -169,7 +181,7 @@ case $COMMAND in
echo "Removing $ENTRY_DIR_ABS"
rm -rf "$ENTRY_DIR_ABS"
- ((ret+=$?))
+ ret=`expr $ret + $?`
;;
*)
@@ -169,3 +182,4 @@ case $COMMAND in
@@ -179,3 +191,4 @@ case $COMMAND in
esac
exit $ret
......
File deleted
From: Lennart Poettering <lennart@poettering.net>
Date: Fri, 5 Apr 2019 18:21:02 +0200
Subject: journalctl: add new --relinquish and --smart-relinquish options
The latter is identical to the former, but becomes a NOP if
/var/log/journal is on the same mount as /, and thus during shutdown
unmounting /var is not necessary and hence we can keep logging until the
very end.
Signed-off-by: Martyn Welch <martyn.welch@collabora.com>
[Martyn Welch: Backported to systemd v241]
---
src/journal/journalctl.c | 161 ++++++++++++++++++++++++++++++-----------------
1 file changed, 103 insertions(+), 58 deletions(-)
diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c
index 910aced..5bde51d 100644
--- a/src/journal/journalctl.c
+++ b/src/journal/journalctl.c
@@ -51,6 +51,7 @@
#include "log.h"
#include "logs-show.h"
#include "mkdir.h"
+#include "mountpoint-util.h"
#include "pager.h"
#include "parse-util.h"
#include "path-util.h"
@@ -165,6 +166,7 @@ static enum {
ACTION_UPDATE_CATALOG,
ACTION_LIST_BOOTS,
ACTION_FLUSH,
+ ACTION_RELINQUISH_VAR,
ACTION_SYNC,
ACTION_ROTATE,
ACTION_VACUUM,
@@ -361,6 +363,8 @@ static int help(void) {
" --vacuum-time=TIME Remove journal files older than specified time\n"
" --verify Verify journal file consistency\n"
" --sync Synchronize unwritten journal messages to disk\n"
+ " --relinquish-var Stop logging to disk, log to temporary file system\n"
+ " --smart-relinquish-var Similar, but NOP if log directory is on root mount\n"
" --flush Flush all journal data from /run into /var\n"
" --rotate Request immediate rotation of the journal files\n"
" --header Show journal header information\n"
@@ -407,6 +411,8 @@ static int parse_argv(int argc, char *argv[]) {
ARG_UTC,
ARG_SYNC,
ARG_FLUSH,
+ ARG_RELINQUISH_VAR,
+ ARG_SMART_RELINQUISH_VAR,
ARG_ROTATE,
ARG_VACUUM_SIZE,
ARG_VACUUM_FILES,
@@ -416,64 +422,66 @@ static int parse_argv(int argc, char *argv[]) {
};
static const struct option options[] = {
- { "help", no_argument, NULL, 'h' },
- { "version" , no_argument, NULL, ARG_VERSION },
- { "no-pager", no_argument, NULL, ARG_NO_PAGER },
- { "pager-end", no_argument, NULL, 'e' },
- { "follow", no_argument, NULL, 'f' },
- { "force", no_argument, NULL, ARG_FORCE },
- { "output", required_argument, NULL, 'o' },
- { "all", no_argument, NULL, 'a' },
- { "full", no_argument, NULL, 'l' },
- { "no-full", no_argument, NULL, ARG_NO_FULL },
- { "lines", optional_argument, NULL, 'n' },
- { "no-tail", no_argument, NULL, ARG_NO_TAIL },
- { "new-id128", no_argument, NULL, ARG_NEW_ID128 }, /* deprecated */
- { "quiet", no_argument, NULL, 'q' },
- { "merge", no_argument, NULL, 'm' },
- { "this-boot", no_argument, NULL, ARG_THIS_BOOT }, /* deprecated */
- { "boot", optional_argument, NULL, 'b' },
- { "list-boots", no_argument, NULL, ARG_LIST_BOOTS },
- { "dmesg", no_argument, NULL, 'k' },
- { "system", no_argument, NULL, ARG_SYSTEM },
- { "user", no_argument, NULL, ARG_USER },
- { "directory", required_argument, NULL, 'D' },
- { "file", required_argument, NULL, ARG_FILE },
- { "root", required_argument, NULL, ARG_ROOT },
- { "header", no_argument, NULL, ARG_HEADER },
- { "identifier", required_argument, NULL, 't' },
- { "priority", required_argument, NULL, 'p' },
- { "grep", required_argument, NULL, 'g' },
- { "case-sensitive", optional_argument, NULL, ARG_CASE_SENSITIVE },
- { "setup-keys", no_argument, NULL, ARG_SETUP_KEYS },
- { "interval", required_argument, NULL, ARG_INTERVAL },
- { "verify", no_argument, NULL, ARG_VERIFY },
- { "verify-key", required_argument, NULL, ARG_VERIFY_KEY },
- { "disk-usage", no_argument, NULL, ARG_DISK_USAGE },
- { "cursor", required_argument, NULL, 'c' },
- { "after-cursor", required_argument, NULL, ARG_AFTER_CURSOR },
- { "show-cursor", no_argument, NULL, ARG_SHOW_CURSOR },
- { "since", required_argument, NULL, 'S' },
- { "until", required_argument, NULL, 'U' },
- { "unit", required_argument, NULL, 'u' },
- { "user-unit", required_argument, NULL, ARG_USER_UNIT },
- { "field", required_argument, NULL, 'F' },
- { "fields", no_argument, NULL, 'N' },
- { "catalog", no_argument, NULL, 'x' },
- { "list-catalog", no_argument, NULL, ARG_LIST_CATALOG },
- { "dump-catalog", no_argument, NULL, ARG_DUMP_CATALOG },
- { "update-catalog", no_argument, NULL, ARG_UPDATE_CATALOG },
- { "reverse", no_argument, NULL, 'r' },
- { "machine", required_argument, NULL, 'M' },
- { "utc", no_argument, NULL, ARG_UTC },
- { "flush", no_argument, NULL, ARG_FLUSH },
- { "sync", no_argument, NULL, ARG_SYNC },
- { "rotate", no_argument, NULL, ARG_ROTATE },
- { "vacuum-size", required_argument, NULL, ARG_VACUUM_SIZE },
- { "vacuum-files", required_argument, NULL, ARG_VACUUM_FILES },
- { "vacuum-time", required_argument, NULL, ARG_VACUUM_TIME },
- { "no-hostname", no_argument, NULL, ARG_NO_HOSTNAME },
- { "output-fields", required_argument, NULL, ARG_OUTPUT_FIELDS },
+ { "help", no_argument, NULL, 'h' },
+ { "version" , no_argument, NULL, ARG_VERSION },
+ { "no-pager", no_argument, NULL, ARG_NO_PAGER },
+ { "pager-end", no_argument, NULL, 'e' },
+ { "follow", no_argument, NULL, 'f' },
+ { "force", no_argument, NULL, ARG_FORCE },
+ { "output", required_argument, NULL, 'o' },
+ { "all", no_argument, NULL, 'a' },
+ { "full", no_argument, NULL, 'l' },
+ { "no-full", no_argument, NULL, ARG_NO_FULL },
+ { "lines", optional_argument, NULL, 'n' },
+ { "no-tail", no_argument, NULL, ARG_NO_TAIL },
+ { "new-id128", no_argument, NULL, ARG_NEW_ID128 }, /* deprecated */
+ { "quiet", no_argument, NULL, 'q' },
+ { "merge", no_argument, NULL, 'm' },
+ { "this-boot", no_argument, NULL, ARG_THIS_BOOT }, /* deprecated */
+ { "boot", optional_argument, NULL, 'b' },
+ { "list-boots", no_argument, NULL, ARG_LIST_BOOTS },
+ { "dmesg", no_argument, NULL, 'k' },
+ { "system", no_argument, NULL, ARG_SYSTEM },
+ { "user", no_argument, NULL, ARG_USER },
+ { "directory", required_argument, NULL, 'D' },
+ { "file", required_argument, NULL, ARG_FILE },
+ { "root", required_argument, NULL, ARG_ROOT },
+ { "header", no_argument, NULL, ARG_HEADER },
+ { "identifier", required_argument, NULL, 't' },
+ { "priority", required_argument, NULL, 'p' },
+ { "grep", required_argument, NULL, 'g' },
+ { "case-sensitive", optional_argument, NULL, ARG_CASE_SENSITIVE },
+ { "setup-keys", no_argument, NULL, ARG_SETUP_KEYS },
+ { "interval", required_argument, NULL, ARG_INTERVAL },
+ { "verify", no_argument, NULL, ARG_VERIFY },
+ { "verify-key", required_argument, NULL, ARG_VERIFY_KEY },
+ { "disk-usage", no_argument, NULL, ARG_DISK_USAGE },
+ { "cursor", required_argument, NULL, 'c' },
+ { "after-cursor", required_argument, NULL, ARG_AFTER_CURSOR },
+ { "show-cursor", no_argument, NULL, ARG_SHOW_CURSOR },
+ { "since", required_argument, NULL, 'S' },
+ { "until", required_argument, NULL, 'U' },
+ { "unit", required_argument, NULL, 'u' },
+ { "user-unit", required_argument, NULL, ARG_USER_UNIT },
+ { "field", required_argument, NULL, 'F' },
+ { "fields", no_argument, NULL, 'N' },
+ { "catalog", no_argument, NULL, 'x' },
+ { "list-catalog", no_argument, NULL, ARG_LIST_CATALOG },
+ { "dump-catalog", no_argument, NULL, ARG_DUMP_CATALOG },
+ { "update-catalog", no_argument, NULL, ARG_UPDATE_CATALOG },
+ { "reverse", no_argument, NULL, 'r' },
+ { "machine", required_argument, NULL, 'M' },
+ { "utc", no_argument, NULL, ARG_UTC },
+ { "flush", no_argument, NULL, ARG_FLUSH },
+ { "relinquish-var", no_argument, NULL, ARG_RELINQUISH_VAR },
+ { "smart-relinquish-var", no_argument, NULL, ARG_SMART_RELINQUISH_VAR },
+ { "sync", no_argument, NULL, ARG_SYNC },
+ { "rotate", no_argument, NULL, ARG_ROTATE },
+ { "vacuum-size", required_argument, NULL, ARG_VACUUM_SIZE },
+ { "vacuum-files", required_argument, NULL, ARG_VACUUM_FILES },
+ { "vacuum-time", required_argument, NULL, ARG_VACUUM_TIME },
+ { "no-hostname", no_argument, NULL, ARG_NO_HOSTNAME },
+ { "output-fields", required_argument, NULL, ARG_OUTPUT_FIELDS },
{}
};
@@ -897,6 +905,35 @@ static int parse_argv(int argc, char *argv[]) {
arg_action = ACTION_FLUSH;
break;
+ case ARG_SMART_RELINQUISH_VAR: {
+ int root_mnt_id, log_mnt_id;
+
+ /* Try to be smart about relinquishing access to /var/log/journal/ during shutdown:
+ * if it's on the same mount as the root file system there's no point in
+ * relinquishing access and we can leave journald write to it until the very last
+ * moment. */
+
+ r = path_get_mnt_id("/", &root_mnt_id);
+ if (r < 0)
+ log_debug_errno(r, "Failed to get root mount ID, ignoring: %m");
+ else {
+ r = path_get_mnt_id("/var/log/journal/", &log_mnt_id);
+ if (r < 0)
+ log_debug_errno(r, "Failed to get journal directory mount ID, ignoring: %m");
+ else if (root_mnt_id == log_mnt_id) {
+ log_debug("/var/log/journal/ is on root file system, not relinquishing access to /var.");
+ return 0;
+ } else
+ log_debug("/var/log/journal/ is not on the root file system, relinquishing access to it.");
+ }
+
+ _fallthrough_;
+ }
+
+ case ARG_RELINQUISH_VAR:
+ arg_action = ACTION_RELINQUISH_VAR;
+ break;
+
case ARG_ROTATE:
arg_action = arg_action == ACTION_VACUUM ? ACTION_ROTATE_AND_VACUUM : ACTION_ROTATE;
break;
@@ -1907,6 +1944,10 @@ static int flush_to_var(void) {
return simple_varlink_call("--flush", "io.systemd.Journal.FlushToVar");
}
+static int relinquish_var(void) {
+ return simple_varlink_call("--relinquish-var", "io.systemd.Journal.RelinquishVar");
+}
+
static int rotate(void) {
return simple_varlink_call("--rotate", "io.systemd.Journal.Rotate");
}
@@ -2020,6 +2061,10 @@ int main(int argc, char *argv[]) {
r = flush_to_var();
goto finish;
+ case ACTION_RELINQUISH_VAR:
+ r = relinquish_var();
+ goto finish;
+
case ACTION_SYNC:
r = sync_journal();
goto finish;
From: Lennart Poettering <lennart@poettering.net>
Date: Thu, 4 Apr 2019 19:41:33 +0200
Subject: journalctl: port --flush/--sync/--rotate to use varlink method calls
Signed-off-by: Martyn Welch <martyn.welch@collabora.com>
[Martyn Welch: Backported to systemd v241]
---
src/journal/journalctl.c | 149 ++++--------------------------------------
src/journal/journald-server.c | 58 +++++++++++++++-
2 files changed, 70 insertions(+), 137 deletions(-)
diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c
index 14a02ed..910aced 100644
--- a/src/journal/journalctl.c
+++ b/src/journal/journalctl.c
@@ -65,6 +65,7 @@
#include "tmpfile-util.h"
#include "unit-name.h"
#include "user-util.h"
+#include "varlink.h"
#define DEFAULT_FSS_INTERVAL_USEC (15*USEC_PER_MINUTE)
@@ -1883,157 +1884,35 @@ static int verify(sd_journal *j) {
return r;
}
-static int flush_to_var(void) {
- _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
- _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
- _cleanup_close_ int watch_fd = -1;
+static int simple_varlink_call(const char *option, const char *method) {
+ _cleanup_(varlink_flush_close_unrefp) Varlink *link = NULL;
+ const char *error;
int r;
- if (arg_machine) {
- log_error("--flush is not supported in conjunction with --machine=.");
- return -EOPNOTSUPP;
- }
-
- /* Quick exit */
- if (access("/run/systemd/journal/flushed", F_OK) >= 0)
- return 0;
+ if (arg_machine)
+ return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "%s is not supported in conjunction with --machine=.", option);
- /* OK, let's actually do the full logic, send SIGUSR1 to the
- * daemon and set up inotify to wait for the flushed file to appear */
- r = bus_connect_system_systemd(&bus);
- if (r < 0)
- return log_error_errno(r, "Failed to get D-Bus connection: %m");
-
- r = sd_bus_call_method(
- bus,
- "org.freedesktop.systemd1",
- "/org/freedesktop/systemd1",
- "org.freedesktop.systemd1.Manager",
- "KillUnit",
- &error,
- NULL,
- "ssi", "systemd-journald.service", "main", SIGUSR1);
+ r = varlink_connect_address(&link, "/run/systemd/journal/io.systemd.journal");
if (r < 0)
- return log_error_errno(r, "Failed to kill journal service: %s", bus_error_message(&error, r));
-
- mkdir_p("/run/systemd/journal", 0755);
+ return log_error_errno(r, "Failed to connect to journal: %m");
- watch_fd = inotify_init1(IN_NONBLOCK|IN_CLOEXEC);
- if (watch_fd < 0)
- return log_error_errno(errno, "Failed to create inotify watch: %m");
-
- r = inotify_add_watch(watch_fd, "/run/systemd/journal", IN_CREATE|IN_DONT_FOLLOW|IN_ONLYDIR);
+ r = varlink_call(link, method, NULL, NULL, &error, NULL);
if (r < 0)
- return log_error_errno(errno, "Failed to watch journal directory: %m");
-
- for (;;) {
- if (access("/run/systemd/journal/flushed", F_OK) >= 0)
- break;
-
- if (errno != ENOENT)
- return log_error_errno(errno, "Failed to check for existence of /run/systemd/journal/flushed: %m");
-
- r = fd_wait_for_event(watch_fd, POLLIN, USEC_INFINITY);
- if (r < 0)
- return log_error_errno(r, "Failed to wait for event: %m");
-
- r = flush_fd(watch_fd);
- if (r < 0)
- return log_error_errno(r, "Failed to flush inotify events: %m");
- }
+ return log_error_errno(r, "Failed to execute operation: %s", error);
return 0;
}
-static int send_signal_and_wait(int sig, const char *watch_path) {
- _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
- _cleanup_close_ int watch_fd = -1;
- usec_t start;
- int r;
-
- if (arg_machine) {
- log_error("--sync and --rotate are not supported in conjunction with --machine=.");
- return -EOPNOTSUPP;
- }
-
- start = now(CLOCK_MONOTONIC);
-
- /* This call sends the specified signal to journald, and waits
- * for acknowledgment by watching the mtime of the specified
- * flag file. This is used to trigger syncing or rotation and
- * then wait for the operation to complete. */
-
- for (;;) {
- usec_t tstamp;
-
- /* See if a sync happened by now. */
- r = read_timestamp_file(watch_path, &tstamp);
- if (r < 0 && r != -ENOENT)
- return log_error_errno(r, "Failed to read %s: %m", watch_path);
- if (r >= 0 && tstamp >= start)
- return 0;
-
- /* Let's ask for a sync, but only once. */
- if (!bus) {
- _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
-
- r = bus_connect_system_systemd(&bus);
- if (r < 0)
- return log_error_errno(r, "Failed to get D-Bus connection: %m");
-
- r = sd_bus_call_method(
- bus,
- "org.freedesktop.systemd1",
- "/org/freedesktop/systemd1",
- "org.freedesktop.systemd1.Manager",
- "KillUnit",
- &error,
- NULL,
- "ssi", "systemd-journald.service", "main", sig);
- if (r < 0)
- return log_error_errno(r, "Failed to kill journal service: %s", bus_error_message(&error, r));
-
- continue;
- }
-
- /* Let's install the inotify watch, if we didn't do that yet. */
- if (watch_fd < 0) {
-
- mkdir_p("/run/systemd/journal", 0755);
-
- watch_fd = inotify_init1(IN_NONBLOCK|IN_CLOEXEC);
- if (watch_fd < 0)
- return log_error_errno(errno, "Failed to create inotify watch: %m");
-
- r = inotify_add_watch(watch_fd, "/run/systemd/journal", IN_MOVED_TO|IN_DONT_FOLLOW|IN_ONLYDIR);
- if (r < 0)
- return log_error_errno(errno, "Failed to watch journal directory: %m");
-
- /* Recheck the flag file immediately, so that we don't miss any event since the last check. */
- continue;
- }
-
- /* OK, all preparatory steps done, let's wait until
- * inotify reports an event. */
-
- r = fd_wait_for_event(watch_fd, POLLIN, USEC_INFINITY);
- if (r < 0)
- return log_error_errno(r, "Failed to wait for event: %m");
-
- r = flush_fd(watch_fd);
- if (r < 0)
- return log_error_errno(r, "Failed to flush inotify events: %m");
- }
-
- return 0;
+static int flush_to_var(void) {
+ return simple_varlink_call("--flush", "io.systemd.Journal.FlushToVar");
}
static int rotate(void) {
- return send_signal_and_wait(SIGUSR2, "/run/systemd/journal/rotated");
+ return simple_varlink_call("--rotate", "io.systemd.Journal.Rotate");
}
static int sync_journal(void) {
- return send_signal_and_wait(SIGRTMIN+1, "/run/systemd/journal/synced");
+ return simple_varlink_call("--sync", "io.systemd.Journal.Synchronize");
}
static int wait_for_change(sd_journal *j, int poll_fd) {
diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c
index dc4b259..2aad8e9 100644
--- a/src/journal/journald-server.c
+++ b/src/journal/journald-server.c
@@ -1835,8 +1835,37 @@ static int server_connect_notify(Server *s) {
return 0;
}
+static int synchronize_second_half(sd_event_source *event_source, void *userdata) {
+ Varlink *link = userdata;
+ Server *s;
+ int r;
+
+ assert(link);
+ assert_se(s = varlink_get_userdata(link));
+
+ /* This is the "second half" of the Synchronize() varlink method. This function is called as deferred
+ * event source at a low priority to ensure the synchronization completes after all queued log
+ * messages are processed. */
+ server_full_sync(s);
+
+ /* Let's get rid of the event source now, by marking it as non-floating again. It then has no ref
+ * anymore and is immediately destroyed after we return from this function, i.e. from this event
+ * source handler at the end. */
+ r = sd_event_source_set_floating(event_source, false);
+ if (r < 0)
+ return log_error_errno(r, "Failed to mark event source as non-floating: %m");
+
+ return varlink_reply(link, NULL);
+}
+
+static void synchronize_destroy(void *userdata) {
+ varlink_unref(userdata);
+}
+
static int vl_method_synchronize(Varlink *link, JsonVariant *parameters, VarlinkMethodFlags flags, void *userdata) {
+ _cleanup_(sd_event_source_unrefp) sd_event_source *event_source = NULL;
Server *s = userdata;
+ int r;
assert(link);
assert(s);
@@ -1845,9 +1874,34 @@ static int vl_method_synchronize(Varlink *link, JsonVariant *parameters, Varlink
return varlink_error_invalid_parameter(link, parameters);
log_info("Received client request to rotate journal.");
- server_full_sync(s);
- return varlink_reply(link, NULL);
+ /* We don't do the main work now, but instead enqueue a deferred event loop job which will do
+ * it. That job is scheduled at low priority, so that we return from this method call only after all
+ * queued but not processed log messages are written to disk, so that this method call returning can
+ * be used as nice synchronization point. */
+ r = sd_event_add_defer(s->event, &event_source, synchronize_second_half, link);
+ if (r < 0)
+ return log_error_errno(r, "Failed to allocate defer event source: %m");
+
+ r = sd_event_source_set_destroy_callback(event_source, synchronize_destroy);
+ if (r < 0)
+ return log_error_errno(r, "Failed to set event source destroy callback: %m");
+
+ varlink_ref(link); /* The varlink object is now left to the destroy callack to unref */
+
+ r = sd_event_source_set_priority(event_source, SD_EVENT_PRIORITY_NORMAL+15);
+ if (r < 0)
+ return log_error_errno(r, "Failed to set defer event source priority: %m");
+
+ /* Give up ownership of this event source. It will now be destroyed along with event loop itself,
+ * unless it destroys itself earlier. */
+ r = sd_event_source_set_floating(event_source, true);
+ if (r < 0)
+ return log_error_errno(r, "Failed to mark event source as floating: %m");
+
+ (void) sd_event_source_set_description(event_source, "deferred-sync");
+
+ return 0;
}
static int vl_method_rotate(Varlink *link, JsonVariant *parameters, VarlinkMethodFlags flags, void *userdata) {
From: Lennart Poettering <lennart@poettering.net>
Date: Fri, 5 Apr 2019 18:20:25 +0200
Subject: journald: add API to move logging from /var to /run again
We now have this nice little Varlink API, let's beef it up a bit.
Signed-off-by: Martyn Welch <martyn.welch@collabora.com>
[Martyn Welch: Backported to systemd v241]
---
src/journal/journald-server.c | 76 ++++++++++++++++++++++++++++++++-----------
1 file changed, 57 insertions(+), 19 deletions(-)
diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c
index 2aad8e9..77eecee 100644
--- a/src/journal/journald-server.c
+++ b/src/journal/journald-server.c
@@ -286,13 +286,14 @@ static bool flushed_flag_is_set(void) {
return access("/run/systemd/journal/flushed", F_OK) >= 0;
}
-static int system_journal_open(Server *s, bool flush_requested) {
+static int system_journal_open(Server *s, bool flush_requested, bool relinquish_requested) {
const char *fn;
int r = 0;
if (!s->system_journal &&
IN_SET(s->storage, STORAGE_PERSISTENT, STORAGE_AUTO) &&
- (flush_requested || flushed_flag_is_set())) {
+ (flush_requested || flushed_flag_is_set()) &&
+ !relinquish_requested) {
/* If in auto mode: first try to create the machine
* path, but not the prefix.
@@ -334,7 +335,7 @@ static int system_journal_open(Server *s, bool flush_requested) {
fn = strjoina(s->runtime_storage.path, "/system.journal");
- if (s->system_journal) {
+ if (s->system_journal && !relinquish_requested) {
/* Try to open the runtime journal, but only
* if it already exists, so that we can flush
@@ -389,7 +390,7 @@ static JournalFile* find_journal(Server *s, uid_t uid) {
* else that's left the journals as NULL).
*
* Fixes https://github.com/systemd/systemd/issues/3968 */
- (void) system_journal_open(s, false);
+ (void) system_journal_open(s, false, false);
/* We split up user logs only on /var, not on /run. If the
* runtime file is open, we write to it exclusively, in order
@@ -1117,7 +1118,7 @@ int server_flush_to_var(Server *s, bool require_flag_file) {
char ts[FORMAT_TIMESPAN_MAX];
usec_t start;
unsigned n = 0;
- int r;
+ int r, k;
assert(s);
@@ -1130,7 +1131,7 @@ int server_flush_to_var(Server *s, bool require_flag_file) {
if (require_flag_file && !flushed_flag_is_set())
return 0;
- (void) system_journal_open(s, true);
+ (void) system_journal_open(s, true, false);
if (!s->system_journal)
return 0;
@@ -1209,9 +1210,36 @@ finish:
n),
NULL);
+ k = touch("/run/systemd/journal/flushed");
+ if (k < 0)
+ log_warning_errno(k, "Failed to touch /run/systemd/journal/flushed, ignoring: %m");
+
return r;
}
+static int server_relinquish_var(Server *s) {
+ assert(s);
+
+ if (s->storage == STORAGE_NONE)
+ return 0;
+
+ if (s->runtime_journal && !s->system_journal)
+ return 0;
+
+ log_debug("Relinquishing /var...");
+
+ (void) system_journal_open(s, false, true);
+
+ s->system_journal = journal_file_close(s->system_journal);
+ ordered_hashmap_clear_with_destructor(s->user_journals, journal_file_close);
+ set_clear_with_destructor(s->deferred_closes, journal_file_close);
+
+ if (unlink("/run/systemd/journal/flushed") < 0 && errno != ENOENT)
+ log_warning_errno(errno, "Failed to unlink /run/systemd/journal/flushed, ignoring: %m");
+
+ return 0;
+}
+
int server_process_datagram(sd_event_source *es, int fd, uint32_t revents, void *userdata) {
Server *s = userdata;
struct ucred *ucred = NULL;
@@ -1331,18 +1359,12 @@ int server_process_datagram(sd_event_source *es, int fd, uint32_t revents, void
}
static void server_full_flush(Server *s) {
- int r;
-
assert(s);
(void) server_flush_to_var(s, false);
server_sync(s);
server_vacuum(s, false);
- r = touch("/run/systemd/journal/flushed");
- if (r < 0)
- log_warning_errno(r, "Failed to touch /run/systemd/journal/flushed, ignoring: %m");
-
server_space_usage_message(s, NULL);
}
@@ -1351,7 +1373,7 @@ static int dispatch_sigusr1(sd_event_source *es, const struct signalfd_siginfo *
assert(s);
- log_info("Received request to flush runtime journal from PID " PID_FMT, si->ssi_pid);
+ log_info("Received SIGUSR1 signal from PID " PID_FMT ", as request to flush runtime journal.", si->ssi_pid);
server_full_flush(s);
return 0;
@@ -1381,7 +1403,7 @@ static int dispatch_sigusr2(sd_event_source *es, const struct signalfd_siginfo *
assert(s);
- log_info("Received request to rotate journal from PID " PID_FMT, si->ssi_pid);
+ log_info("Received SIGUSR2 signal from PID " PID_FMT ", as request to rotate journal.", si->ssi_pid);
server_full_rotate(s);
return 0;
@@ -1418,7 +1440,7 @@ static int dispatch_sigrtmin1(sd_event_source *es, const struct signalfd_siginfo
assert(s);
- log_debug("Received request to sync from PID " PID_FMT, si->ssi_pid);
+ log_debug("Received SIGRTMIN1 signal from PID " PID_FMT ", as request to sync.", si->ssi_pid );
server_full_sync(s);
return 0;
@@ -1934,6 +1956,21 @@ static int vl_method_flush_to_var(Varlink *link, JsonVariant *parameters, Varlin
return varlink_reply(link, NULL);
}
+static int vl_method_relinquish_var(Varlink *link, JsonVariant *parameters, VarlinkMethodFlags flags, void *userdata) {
+ Server *s = userdata;
+
+ assert(link);
+ assert(s);
+
+ if (json_variant_elements(parameters) > 0)
+ return varlink_error_invalid_parameter(link, parameters);
+
+ log_info("Received client request to relinquish /var access.");
+ server_relinquish_var(s);
+
+ return varlink_reply(link, NULL);
+}
+
static int server_open_varlink(Server *s) {
int r;
@@ -1947,9 +1984,10 @@ static int server_open_varlink(Server *s) {
r = varlink_server_bind_method_many(
s->varlink_server,
- "io.systemd.Journal.Synchronize", vl_method_synchronize,
- "io.systemd.Journal.Rotate", vl_method_rotate,
- "io.systemd.Journal.FlushToVar", vl_method_flush_to_var);
+ "io.systemd.Journal.Synchronize", vl_method_synchronize,
+ "io.systemd.Journal.Rotate", vl_method_rotate,
+ "io.systemd.Journal.FlushToVar", vl_method_flush_to_var,
+ "io.systemd.Journal.RelinquishVar", vl_method_relinquish_var);
if (r < 0)
return r;
@@ -2164,7 +2202,7 @@ int server_init(Server *s) {
(void) client_context_acquire_default(s);
- return system_journal_open(s, false);
+ return system_journal_open(s, false, false);
}
void server_maybe_append_tags(Server *s) {
From: Lennart Poettering <lennart@poettering.net>
Date: Thu, 4 Apr 2019 19:38:18 +0200
Subject: journald: also offer flush/rotate/sync as varlink method calls
This makes the operations previously available via asynchronous signals
also available as regular varlink method calls, i.e. with sane
completion.
Signed-off-by: Martyn Welch <martyn.welch@collabora.com>
[Martyn Welch: Backported to systemd v241]
---
src/journal/journald-server.c | 125 ++++++++++++++++++++++++++++++++++++++----
src/journal/journald-server.h | 3 +
2 files changed, 117 insertions(+), 11 deletions(-)
diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c
index 7fe0f82..dc4b259 100644
--- a/src/journal/journald-server.c
+++ b/src/journal/journald-server.c
@@ -1330,14 +1330,11 @@ int server_process_datagram(sd_event_source *es, int fd, uint32_t revents, void
return 0;
}
-static int dispatch_sigusr1(sd_event_source *es, const struct signalfd_siginfo *si, void *userdata) {
- Server *s = userdata;
+static void server_full_flush(Server *s) {
int r;
assert(s);
- log_info("Received request to flush runtime journal from PID " PID_FMT, si->ssi_pid);
-
(void) server_flush_to_var(s, false);
server_sync(s);
server_vacuum(s, false);
@@ -1347,16 +1344,24 @@ static int dispatch_sigusr1(sd_event_source *es, const struct signalfd_siginfo *
log_warning_errno(r, "Failed to touch /run/systemd/journal/flushed, ignoring: %m");
server_space_usage_message(s, NULL);
- return 0;
}
-static int dispatch_sigusr2(sd_event_source *es, const struct signalfd_siginfo *si, void *userdata) {
+static int dispatch_sigusr1(sd_event_source *es, const struct signalfd_siginfo *si, void *userdata) {
Server *s = userdata;
+
+ assert(s);
+
+ log_info("Received request to flush runtime journal from PID " PID_FMT, si->ssi_pid);
+ server_full_flush(s);
+
+ return 0;
+}
+
+static void server_full_rotate(Server *s) {
int r;
assert(s);
- log_info("Received request to rotate journal from PID " PID_FMT, si->ssi_pid);
server_rotate(s);
server_vacuum(s, true);
@@ -1369,6 +1374,15 @@ static int dispatch_sigusr2(sd_event_source *es, const struct signalfd_siginfo *
r = write_timestamp_file_atomic("/run/systemd/journal/rotated", now(CLOCK_MONOTONIC));
if (r < 0)
log_warning_errno(r, "Failed to write /run/systemd/journal/rotated, ignoring: %m");
+}
+
+static int dispatch_sigusr2(sd_event_source *es, const struct signalfd_siginfo *si, void *userdata) {
+ Server *s = userdata;
+
+ assert(s);
+
+ log_info("Received request to rotate journal from PID " PID_FMT, si->ssi_pid);
+ server_full_rotate(s);
return 0;
}
@@ -1384,14 +1398,11 @@ static int dispatch_sigterm(sd_event_source *es, const struct signalfd_siginfo *
return 0;
}
-static int dispatch_sigrtmin1(sd_event_source *es, const struct signalfd_siginfo *si, void *userdata) {
- Server *s = userdata;
+static void server_full_sync(Server *s) {
int r;
assert(s);
- log_debug("Received request to sync from PID " PID_FMT, si->ssi_pid);
-
server_sync(s);
/* Let clients know when the most recent sync happened. */
@@ -1399,6 +1410,17 @@ static int dispatch_sigrtmin1(sd_event_source *es, const struct signalfd_siginfo
if (r < 0)
log_warning_errno(r, "Failed to write /run/systemd/journal/synced, ignoring: %m");
+ return;
+}
+
+static int dispatch_sigrtmin1(sd_event_source *es, const struct signalfd_siginfo *si, void *userdata) {
+ Server *s = userdata;
+
+ assert(s);
+
+ log_debug("Received request to sync from PID " PID_FMT, si->ssi_pid);
+ server_full_sync(s);
+
return 0;
}
@@ -1813,6 +1835,81 @@ static int server_connect_notify(Server *s) {
return 0;
}
+static int vl_method_synchronize(Varlink *link, JsonVariant *parameters, VarlinkMethodFlags flags, void *userdata) {
+ Server *s = userdata;
+
+ assert(link);
+ assert(s);
+
+ if (json_variant_elements(parameters) > 0)
+ return varlink_error_invalid_parameter(link, parameters);
+
+ log_info("Received client request to rotate journal.");
+ server_full_sync(s);
+
+ return varlink_reply(link, NULL);
+}
+
+static int vl_method_rotate(Varlink *link, JsonVariant *parameters, VarlinkMethodFlags flags, void *userdata) {
+ Server *s = userdata;
+
+ assert(link);
+ assert(s);
+
+ if (json_variant_elements(parameters) > 0)
+ return varlink_error_invalid_parameter(link, parameters);
+
+ log_info("Received client request to rotate journal.");
+ server_full_rotate(s);
+
+ return varlink_reply(link, NULL);
+}
+
+static int vl_method_flush_to_var(Varlink *link, JsonVariant *parameters, VarlinkMethodFlags flags, void *userdata) {
+ Server *s = userdata;
+
+ assert(link);
+ assert(s);
+
+ if (json_variant_elements(parameters) > 0)
+ return varlink_error_invalid_parameter(link, parameters);
+
+ log_info("Received client request to flush runtime journal.");
+ server_full_flush(s);
+
+ return varlink_reply(link, NULL);
+}
+
+static int server_open_varlink(Server *s) {
+ int r;
+
+ assert(s);
+
+ r = varlink_server_new(&s->varlink_server, VARLINK_SERVER_ROOT_ONLY);
+ if (r < 0)
+ return r;
+
+ varlink_server_set_userdata(s->varlink_server, s);
+
+ r = varlink_server_bind_method_many(
+ s->varlink_server,
+ "io.systemd.Journal.Synchronize", vl_method_synchronize,
+ "io.systemd.Journal.Rotate", vl_method_rotate,
+ "io.systemd.Journal.FlushToVar", vl_method_flush_to_var);
+ if (r < 0)
+ return r;
+
+ r = varlink_server_listen_address(s->varlink_server, "/run/systemd/journal/io.systemd.journal", 0600);
+ if (r < 0)
+ return r;
+
+ r = varlink_server_attach_event(s->varlink_server, s->event, SD_EVENT_PRIORITY_NORMAL);
+ if (r < 0)
+ return r;
+
+ return 0;
+}
+
int server_init(Server *s) {
_cleanup_fdset_free_ FDSet *fds = NULL;
int n, r, fd;
@@ -1973,6 +2070,10 @@ int server_init(Server *s) {
return r;
}
+ r = server_open_varlink(s);
+ if (r < 0)
+ return r;
+
r = server_open_kernel_seqnum(s);
if (r < 0)
return r;
@@ -2046,6 +2147,8 @@ void server_done(Server *s) {
ordered_hashmap_free_with_destructor(s->user_journals, journal_file_close);
+ varlink_server_unref(s->varlink_server);
+
sd_event_source_unref(s->syslog_event_source);
sd_event_source_unref(s->native_event_source);
sd_event_source_unref(s->stdout_event_source);
diff --git a/src/journal/journald-server.h b/src/journal/journald-server.h
index 3f6b42d..b44e658 100644
--- a/src/journal/journald-server.h
+++ b/src/journal/journald-server.h
@@ -16,6 +16,7 @@ typedef struct Server Server;
#include "journald-stream.h"
#include "list.h"
#include "prioq.h"
+#include "varlink.h"
typedef enum Storage {
STORAGE_AUTO,
@@ -165,6 +166,8 @@ struct Server {
ClientContext *my_context; /* the context of journald itself */
ClientContext *pid1_context; /* the context of PID 1 */
+
+ VarlinkServer *varlink_server;
};
#define SERVER_MACHINE_ID(s) ((s)->machine_id_field + STRLEN("_MACHINE_ID="))
From: Lennart Poettering <lennart@poettering.net>
Date: Thu, 11 Apr 2019 18:47:10 +0200
Subject: tests: add varlink test
Signed-off-by: Martyn Welch <martyn.welch@collabora.com>
[Martyn Welch: Backported to systemd v241]
---
src/test/meson.build | 4 +
src/test/test-varlink.c | 239 ++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 243 insertions(+)
create mode 100644 src/test/test-varlink.c
diff --git a/src/test/meson.build b/src/test/meson.build
index 40154cf..9a50dc4 100644
--- a/src/test/meson.build
+++ b/src/test/meson.build
@@ -567,6 +567,10 @@ tests += [
libmount,
libblkid]],
+ [['src/test/test-varlink.c'],
+ [],
+ [threads]],
+
[['src/test/test-cgroup-util.c'],
[],
[]],
diff --git a/src/test/test-varlink.c b/src/test/test-varlink.c
new file mode 100644
index 0000000..fbfc72c
--- /dev/null
+++ b/src/test/test-varlink.c
@@ -0,0 +1,239 @@
+/* SPDX-License-Identifier: LGPL-2.1+ */
+
+#include <fcntl.h>
+#include <poll.h>
+#include <pthread.h>
+
+#include "sd-event.h"
+
+#include "fd-util.h"
+#include "json.h"
+#include "rm-rf.h"
+#include "strv.h"
+#include "tmpfile-util.h"
+#include "user-util.h"
+#include "varlink.h"
+
+/* Let's pick some high value, that is higher than the largest listen() backlog, but leaves enough room below
+ the typical RLIMIT_NOFILE value of 1024 so that we can process both sides of each socket in our
+ process. Or in other words: "OVERLOAD_CONNECTIONS * 2 + x < 1024" should hold, for some small x that
+ should cover any auxiliary fds, the listener server fds, stdin/stdout/stderr and whatever else. */
+#define OVERLOAD_CONNECTIONS 333
+
+static int n_done = 0;
+static int block_write_fd = -1;
+
+static int method_something(Varlink *link, JsonVariant *parameters, VarlinkMethodFlags flags, void *userdata) {
+ _cleanup_(json_variant_unrefp) JsonVariant *ret = NULL;
+ JsonVariant *a, *b;
+ intmax_t x, y;
+ int r;
+
+ a = json_variant_by_key(parameters, "a");
+ if (!a)
+ return varlink_error(link, "io.test.BadParameters", NULL);
+
+ x = json_variant_integer(a);
+
+ b = json_variant_by_key(parameters, "b");
+ if (!b)
+ return varlink_error(link, "io.test.BadParameters", NULL);
+
+ y = json_variant_integer(b);
+
+ r = json_build(&ret, JSON_BUILD_OBJECT(JSON_BUILD_PAIR("sum", JSON_BUILD_INTEGER(x + y))));
+ if (r < 0)
+ return r;
+
+ return varlink_reply(link, ret);
+}
+
+static int method_done(Varlink *link, JsonVariant *parameters, VarlinkMethodFlags flags, void *userdata) {
+
+ if (++n_done == 2)
+ sd_event_exit(varlink_get_event(link), EXIT_FAILURE);
+
+ return 0;
+}
+
+static int reply(Varlink *link, JsonVariant *parameters, const char *error_id, VarlinkReplyFlags flags, void *userdata) {
+ JsonVariant *sum;
+
+ sum = json_variant_by_key(parameters, "sum");
+
+ assert_se(json_variant_integer(sum) == 7+22);
+
+ if (++n_done == 2)
+ sd_event_exit(varlink_get_event(link), EXIT_FAILURE);
+
+ return 0;
+}
+
+static int on_connect(VarlinkServer *s, Varlink *link, void *userdata) {
+ uid_t uid = UID_INVALID;
+
+ assert(s);
+ assert(link);
+
+ assert_se(varlink_get_peer_uid(link, &uid) >= 0);
+ assert_se(getuid() == uid);
+
+ return 0;
+}
+
+static int overload_reply(Varlink *link, JsonVariant *parameters, const char *error_id, VarlinkReplyFlags flags, void *userdata) {
+
+ /* This method call reply should always be called with a disconnection, since the method call should
+ * be talking to an overloaded server */
+
+ log_debug("Over reply triggered with error: %s", strna(error_id));
+ assert_se(streq(error_id, VARLINK_ERROR_DISCONNECTED));
+ sd_event_exit(varlink_get_event(link), 0);
+
+ return 0;
+}
+
+static void flood_test(const char *address) {
+ _cleanup_(varlink_flush_close_unrefp) Varlink *c = NULL;
+ _cleanup_(sd_event_unrefp) sd_event *e = NULL;
+ _cleanup_free_ Varlink **connections = NULL;
+ size_t k;
+ char x = 'x';
+
+ log_debug("Flooding server...");
+
+ /* Block the main event loop while we flood */
+ assert_se(write(block_write_fd, &x, sizeof(x)) == sizeof(x));
+
+ assert_se(sd_event_default(&e) >= 0);
+
+ /* Flood the server with connections */
+ assert_se(connections = new0(Varlink*, OVERLOAD_CONNECTIONS));
+ for (k = 0; k < OVERLOAD_CONNECTIONS; k++) {
+ _cleanup_free_ char *t = NULL;
+ log_debug("connection %zu", k);
+ assert_se(varlink_connect_address(connections + k, address) >= 0);
+
+ assert_se(asprintf(&t, "flood-%zu", k) >= 0);
+ assert_se(varlink_set_description(connections[k], t) >= 0);
+ assert_se(varlink_attach_event(connections[k], e, k) >= 0);
+ assert_se(varlink_sendb(connections[k], "io.test.Rubbish", JSON_BUILD_OBJECT(JSON_BUILD_PAIR("id", JSON_BUILD_INTEGER(k)))) >= 0);
+ }
+
+ /* Then, create one more, which should fail */
+ log_debug("Creating overload connection...");
+ assert_se(varlink_connect_address(&c, address) >= 0);
+ assert_se(varlink_set_description(c, "overload-client") >= 0);
+ assert_se(varlink_attach_event(c, e, k) >= 0);
+ assert_se(varlink_bind_reply(c, overload_reply) >= 0);
+ assert_se(varlink_invokeb(c, "io.test.Overload", JSON_BUILD_OBJECT(JSON_BUILD_PAIR("foo", JSON_BUILD_STRING("bar")))) >= 0);
+
+ /* Unblock it */
+ log_debug("Unblocking server...");
+ block_write_fd = safe_close(block_write_fd);
+
+ /* This loop will terminate as soon as the overload reply callback is called */
+ assert_se(sd_event_loop(e) >= 0);
+
+ /* And close all connections again */
+ for (k = 0; k < OVERLOAD_CONNECTIONS; k++)
+ connections[k] = varlink_unref(connections[k]);
+}
+
+static void *thread(void *arg) {
+ _cleanup_(varlink_flush_close_unrefp) Varlink *c = NULL;
+ _cleanup_(json_variant_unrefp) JsonVariant *i = NULL;
+ JsonVariant *o = NULL;
+ const char *e;
+
+ assert_se(json_build(&i, JSON_BUILD_OBJECT(JSON_BUILD_PAIR("a", JSON_BUILD_INTEGER(88)),
+ JSON_BUILD_PAIR("b", JSON_BUILD_INTEGER(99)))) >= 0);
+
+ assert_se(varlink_connect_address(&c, arg) >= 0);
+ assert_se(varlink_set_description(c, "thread-client") >= 0);
+
+ assert_se(varlink_call(c, "io.test.DoSomething", i, &o, &e, NULL) >= 0);
+ assert_se(json_variant_integer(json_variant_by_key(o, "sum")) == 88 + 99);
+ assert_se(!e);
+
+ assert_se(varlink_callb(c, "io.test.IDontExist", &o, &e, NULL, JSON_BUILD_OBJECT(JSON_BUILD_PAIR("x", JSON_BUILD_REAL(5.5)))) >= 0);
+ assert_se(streq_ptr(json_variant_string(json_variant_by_key(o, "method")), "io.test.IDontExist"));
+ assert_se(streq(e, VARLINK_ERROR_METHOD_NOT_FOUND));
+
+ flood_test(arg);
+
+ assert_se(varlink_send(c, "io.test.Done", NULL) >= 0);
+
+ return NULL;
+}
+
+static int block_fd_handler(sd_event_source *s, int fd, uint32_t revents, void *userdata) {
+ char c;
+
+ assert_se(fd_nonblock(fd, false) >= 0);
+
+ assert_se(read(fd, &c, sizeof(c)) == sizeof(c));
+ /* When a character is written to this pipe we'll block until the pipe is closed. */
+
+ assert_se(read(fd, &c, sizeof(c)) == 0);
+
+ assert_se(fd_nonblock(fd, true) >= 0);
+
+ assert_se(sd_event_source_set_enabled(s, SD_EVENT_OFF) >= 0);
+
+ return 0;
+}
+
+int main(int argc, char *argv[]) {
+ _cleanup_(sd_event_source_unrefp) sd_event_source *block_event = NULL;
+ _cleanup_(varlink_server_unrefp) VarlinkServer *s = NULL;
+ _cleanup_(varlink_flush_close_unrefp) Varlink *c = NULL;
+ _cleanup_(rm_rf_physical_and_freep) char *tmpdir = NULL;
+ _cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
+ _cleanup_(sd_event_unrefp) sd_event *e = NULL;
+ _cleanup_(close_pairp) int block_fds[2] = { -1, -1 };
+ pthread_t t;
+ const char *sp;
+
+ log_set_max_level(LOG_DEBUG);
+ log_open();
+
+ assert_se(mkdtemp_malloc("/tmp/varlink-test-XXXXXX", &tmpdir) >= 0);
+ sp = strjoina(tmpdir, "/socket");
+
+ assert_se(sd_event_default(&e) >= 0);
+
+ assert_se(pipe2(block_fds, O_NONBLOCK|O_CLOEXEC) >= 0);
+ assert_se(sd_event_add_io(e, &block_event, block_fds[0], EPOLLIN, block_fd_handler, NULL) >= 0);
+ assert_se(sd_event_source_set_priority(block_event, SD_EVENT_PRIORITY_IMPORTANT) >= 0);
+ block_write_fd = TAKE_FD(block_fds[1]);
+
+ assert_se(varlink_server_new(&s, VARLINK_SERVER_ACCOUNT_UID) >= 0);
+ assert_se(varlink_server_set_description(s, "our-server") >= 0);
+
+ assert_se(varlink_server_bind_method(s, "io.test.DoSomething", method_something) >= 0);
+ assert_se(varlink_server_bind_method(s, "io.test.Done", method_done) >= 0);
+ assert_se(varlink_server_bind_connect(s, on_connect) >= 0);
+ assert_se(varlink_server_listen_address(s, sp, 0600) >= 0);
+ assert_se(varlink_server_attach_event(s, e, 0) >= 0);
+ assert_se(varlink_server_set_connections_max(s, OVERLOAD_CONNECTIONS) >= 0);
+
+ assert_se(varlink_connect_address(&c, sp) >= 0);
+ assert_se(varlink_set_description(c, "main-client") >= 0);
+ assert_se(varlink_bind_reply(c, reply) >= 0);
+
+ assert_se(json_build(&v, JSON_BUILD_OBJECT(JSON_BUILD_PAIR("a", JSON_BUILD_INTEGER(7)),
+ JSON_BUILD_PAIR("b", JSON_BUILD_INTEGER(22)))) >= 0);
+
+ assert_se(varlink_invoke(c, "io.test.DoSomething", v) >= 0);
+
+ assert_se(varlink_attach_event(c, e, 0) >= 0);
+
+ assert_se(pthread_create(&t, NULL, thread, (void*) sp) == 0);
+
+ assert_se(sd_event_loop(e) >= 0);
+
+ assert_se(pthread_join(t, NULL) == 0);
+
+ return 0;
+}
From: Lennart Poettering <lennart@poettering.net>
Date: Fri, 5 Apr 2019 18:22:31 +0200
Subject: units: automatically revert to /run logging on shutdown if necessary
Fixes: #867
Signed-off-by: Martyn Welch <martyn.welch@collabora.com>
[Martyn Welch: Backported to systemd v241]
---
units/systemd-journal-flush.service.in | 1 +
1 file changed, 1 insertion(+)
diff --git a/units/systemd-journal-flush.service.in b/units/systemd-journal-flush.service.in
index bacfe51..29b006c 100644
--- a/units/systemd-journal-flush.service.in
+++ b/units/systemd-journal-flush.service.in
@@ -18,6 +18,7 @@ RequiresMountsFor=/var/log/journal
[Service]
ExecStart=@rootbindir@/journalctl --flush
+ExecStop=@rootbindir@/journalctl --smart-relinquish-var
Type=oneshot
RemainAfterExit=yes
TimeoutSec=90s
Disable tests: test-stat-util, test-netlink
These tests are reported to fail in Bosch's build setup
--- a/src/test/meson.build
+++ b/src/test/meson.build
@@ -280,10 +280,6 @@
[],
[]],
- [['src/test/test-stat-util.c'],
- [],
- []],
-
[['src/test/test-os-util.c'],
[],
[]],
@@ -919,10 +915,6 @@
[],
[]],
- [['src/libsystemd/sd-netlink/test-netlink.c'],
- [],
- []],
-
[['src/libsystemd/sd-netlink/test-local-addresses.c'],
[],
[]],
From e6190e2882e1d6772a9e586fcc65c91d406e52fb Mon Sep 17 00:00:00 2001
From: Daniel Fullmer <danielrf12@gmail.com>
Date: Thu, 23 Apr 2020 14:47:56 -0400
Subject: sd-boot: fix menu ordering with boot counting
systemd-boot selects the last valid entry by default, not the first.
Fixes: #15256
diff --git a/docs/AUTOMATIC_BOOT_ASSESSMENT.md b/docs/AUTOMATIC_BOOT_ASSESSMENT.md
index aff203b590..83ddf28fdd 100644
--- a/docs/AUTOMATIC_BOOT_ASSESSMENT.md
+++ b/docs/AUTOMATIC_BOOT_ASSESSMENT.md
@@ -99,9 +99,9 @@ Here's an example walkthrough of how this all fits together.
6. If this boot also fails, on the next boot the boot loader will see the the
tag `+0-3`, i.e. the counter reached zero. At this point the entry will be
- considered "bad", and ordered to the end of the list of entries. The next
- newest boot entry is now tried, i.e. the system automatically reverted back
- to an earlier version.
+ considered "bad", and ordered to the beginning of the list of entries. The
+ next newest boot entry is now tried, i.e. the system automatically reverted
+ back to an earlier version.
The above describes the walkthrough when the selected boot entry continuously
fails. Let's have a look at an alternative ending to this walkthrough. In this
diff --git a/man/systemd-boot.xml b/man/systemd-boot.xml
index dacd49cd7b..b666ae1e53 100644
--- a/man/systemd-boot.xml
+++ b/man/systemd-boot.xml
@@ -391,10 +391,10 @@
considered 'good' from then on.</para>
<para>The boot menu takes the 'tries left' counter into account when sorting the menu entries: entries in 'bad'
- state are ordered at the end of the list, and entries in 'good' or 'indeterminate' at the beginning. The user can
+ state are ordered at the beginning of the list, and entries in 'good' or 'indeterminate' at the end. The user can
freely choose to boot any entry of the menu, including those already marked 'bad'. If the menu entry to boot is
- automatically determined, this means that 'good' or 'indeterminate' entries are generally preferred (as the top item of
- the menu is the one booted by default), and 'bad' entries will only be considered if there are no 'good' or
+ automatically determined, this means that 'good' or 'indeterminate' entries are generally preferred (as the bottom
+ item of the menu is the one booted by default), and 'bad' entries will only be considered if there are no 'good' or
'indeterminate' entries left.</para>
<para>The <citerefentry><refentrytitle>kernel-install</refentrytitle><manvolnum>8</manvolnum></citerefentry> kernel
diff --git a/src/boot/efi/boot.c b/src/boot/efi/boot.c
index 380b530fd2..1fe2a2bdc3 100644
--- a/src/boot/efi/boot.c
+++ b/src/boot/efi/boot.c
@@ -1479,11 +1479,11 @@ static VOID config_load_entries(
static INTN config_entry_compare(ConfigEntry *a, ConfigEntry *b) {
INTN r;
- /* Order entries that have no tries left to the end of the list */
+ /* Order entries that have no tries left to the beginning of the list */
if (a->tries_left != 0 && b->tries_left == 0)
- return -1;
- if (a->tries_left == 0 && b->tries_left != 0)
return 1;
+ if (a->tries_left == 0 && b->tries_left != 0)
+ return -1;
r = str_verscmp(a->id, b->id);
if (r != 0)
@@ -1493,17 +1493,17 @@ static INTN config_entry_compare(ConfigEntry *a, ConfigEntry *b) {
b->tries_left == (UINTN) -1)
return 0;
- /* If both items have boot counting, and otherwise are identical, put the entry with more tries left first */
+ /* If both items have boot counting, and otherwise are identical, put the entry with more tries left last */
if (a->tries_left > b->tries_left)
- return -1;
- if (a->tries_left < b->tries_left)
return 1;
+ if (a->tries_left < b->tries_left)
+ return -1;
/* If they have the same number of tries left, then let the one win which was tried fewer times so far */
if (a->tries_done < b->tries_done)
- return -1;
- if (a->tries_done > b->tries_done)
return 1;
+ if (a->tries_done > b->tries_done)
+ return -1;
return 0;
}
......@@ -21,19 +21,7 @@ debian/Keep-journal-files-compatible-with-older-versions.patch
debian/Move-sysusers.d-sysctl.d-binfmt.d-modules-load.d-back-to-.patch
debian/systemctl-do-not-shutdown-immediately-on-scheduled-shutdo.patch
debian/test-disable-DnsmasqClientTest.test_resolved_etc_hosts-in.patch
apertis/0001-Remove-bashisms-from-the-depmod-wrapper.patch
apertis/0002-Remove-bashisms-from-the-UEFI-entries-generator.patch
apertis/0003-Reworked-kernel-install-script.patch
disable-failing-tests.patch
apertis/shared-add-minimal-varlink-implementation.patch
apertis/tests-add-varlink-test.patch
apertis/fuzzer-add-varlink-fuzzer.patch
apertis/journald-also-offer-flush-rotate-sync-as-varlink-method-c.patch
apertis/journalctl-port-flush-sync-rotate-to-use-varlink-method-c.patch
apertis/journald-add-API-to-move-logging-from-var-to-run-again.patch
apertis/journalctl-add-new-relinquish-and-smart-relinquish-option.patch
apertis/units-automatically-revert-to-run-logging-on-shutdown-if-.patch
sd-boot-fix-menu-ordering-with-boot-counting.patch
apertis/Force-the-call-of-systemd-journal-flush-before-var-u.patch
apertis/Add-usr-to-non-unmountable-list.patch
apertis/Remove-bashisms-from-the-depmod-wrapper.patch
apertis/Remove-bashisms-from-the-UEFI-entries-generator.patch
apertis/Reworked-kernel-install-script.patch
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment