From 26871bf7120c0da1e29c1ce5a3629b7c0250a0f1 Mon Sep 17 00:00:00 2001 From: licunlong Date: Sat, 29 Jan 2022 16:47:34 +0800 Subject: [PATCH] Tell systemd when dbus is ready/shutting down/reloading config --- ...lso-tell-systemd-before-we-shut-down.patch | 75 +++++++++++++ ...so-tell-systemd-when-we-re-reloading.patch | 104 ++++++++++++++++++ ...TION_ID-when-carrying-out-traditiona.patch | 45 ++++++++ ...ystemd-environment-variables-to-acti.patch | 57 ++++++++++ ...bus-Notify-systemd-when-we-are-ready.patch | 103 +++++++++++++++++ dbus.spec | 9 ++ 6 files changed, 393 insertions(+) create mode 100644 backport-bus-Also-tell-systemd-before-we-shut-down.patch create mode 100644 backport-bus-Also-tell-systemd-when-we-re-reloading.patch create mode 100644 backport-bus-Clear-INVOCATION_ID-when-carrying-out-traditiona.patch create mode 100644 backport-bus-Don-t-pass-systemd-environment-variables-to-acti.patch create mode 100644 backport-bus-Notify-systemd-when-we-are-ready.patch diff --git a/backport-bus-Also-tell-systemd-before-we-shut-down.patch b/backport-bus-Also-tell-systemd-before-we-shut-down.patch new file mode 100644 index 0000000..d8377a0 --- /dev/null +++ b/backport-bus-Also-tell-systemd-before-we-shut-down.patch @@ -0,0 +1,75 @@ +From 03c0db9ff51dedeb98f42c715a70a1bd10c7f595 Mon Sep 17 00:00:00 2001 +From: Simon McVittie +Date: Mon, 15 Jan 2018 15:31:55 +0000 +Subject: [PATCH] bus: Also tell systemd before we shut down + +Signed-off-by: Simon McVittie +Reviewed-by: Philip Withnall +Bug: https://bugs.freedesktop.org/show_bug.cgi?id=104641 +--- + bus/main.c | 1 + + dbus/dbus-sysdeps-util-unix.c | 12 ++++++++++++ + dbus/dbus-sysdeps-util-win.c | 5 +++++ + dbus/dbus-sysdeps.h | 1 + + 4 files changed, 19 insertions(+) + +diff --git a/bus/main.c b/bus/main.c +index 578aa989..28223899 100644 +--- a/bus/main.c ++++ b/bus/main.c +@@ -320,6 +320,7 @@ handle_reload_watch (DBusWatch *watch, + loop = bus_context_get_loop (context); + if (loop != NULL) + { ++ _dbus_daemon_report_stopping (); + _dbus_loop_quit (loop); + } + } +diff --git a/dbus/dbus-sysdeps-util-unix.c b/dbus/dbus-sysdeps-util-unix.c +index 8a7c9278..24eba4e3 100644 +--- a/dbus/dbus-sysdeps-util-unix.c ++++ b/dbus/dbus-sysdeps-util-unix.c +@@ -1556,3 +1556,15 @@ _dbus_daemon_report_reloaded (void) + _dbus_daemon_report_ready (); + #endif + } ++ ++/** ++ * Report to a service manager that the daemon calling this function is ++ * shutting down. This is currently only implemented for systemd. ++ */ ++void ++_dbus_daemon_report_stopping (void) ++{ ++#ifdef HAVE_SYSTEMD ++ sd_notify (0, "STOPPING=1"); ++#endif ++} +diff --git a/dbus/dbus-sysdeps-util-win.c b/dbus/dbus-sysdeps-util-win.c +index 917dd05e..a5c3bba6 100644 +--- a/dbus/dbus-sysdeps-util-win.c ++++ b/dbus/dbus-sysdeps-util-win.c +@@ -1669,3 +1669,8 @@ void + _dbus_daemon_report_reloaded (void) + { + } ++ ++void ++_dbus_daemon_report_stopping (void) ++{ ++} +diff --git a/dbus/dbus-sysdeps.h b/dbus/dbus-sysdeps.h +index d8e69589..0d1ff7c4 100644 +--- a/dbus/dbus-sysdeps.h ++++ b/dbus/dbus-sysdeps.h +@@ -690,6 +690,7 @@ void _dbus_rlimit_free (DBusRLimit *lim); + void _dbus_daemon_report_ready (void); + void _dbus_daemon_report_reloading (void); + void _dbus_daemon_report_reloaded (void); ++void _dbus_daemon_report_stopping (void); + + /** @} */ + +-- +2.27.0 + diff --git a/backport-bus-Also-tell-systemd-when-we-re-reloading.patch b/backport-bus-Also-tell-systemd-when-we-re-reloading.patch new file mode 100644 index 0000000..a51dcc6 --- /dev/null +++ b/backport-bus-Also-tell-systemd-when-we-re-reloading.patch @@ -0,0 +1,104 @@ +From c937a39e4ba1e297518edbd78feeb6f1cc764bd1 Mon Sep 17 00:00:00 2001 +From: Simon McVittie +Date: Mon, 15 Jan 2018 15:31:41 +0000 +Subject: [PATCH] bus: Also tell systemd when we're reloading + +Signed-off-by: Simon McVittie +Reviewed-by: Philip Withnall +Bug: https://bugs.freedesktop.org/show_bug.cgi?id=104641 +--- + bus/bus.c | 4 ++++ + dbus/dbus-sysdeps-util-unix.c | 25 +++++++++++++++++++++++++ + dbus/dbus-sysdeps-util-win.c | 10 ++++++++++ + dbus/dbus-sysdeps.h | 2 ++ + 4 files changed, 41 insertions(+) + +diff --git a/bus/bus.c b/bus/bus.c +index abb2ea2f..9fd9820b 100644 +--- a/bus/bus.c ++++ b/bus/bus.c +@@ -1065,6 +1065,8 @@ bus_context_reload_config (BusContext *context, + DBusString config_file; + dbus_bool_t ret; + ++ _dbus_daemon_report_reloading (); ++ + /* Flush the user database cache */ + _dbus_flush_caches (); + +@@ -1095,6 +1097,8 @@ bus_context_reload_config (BusContext *context, + bus_context_log (context, DBUS_SYSTEM_LOG_INFO, "Unable to reload configuration: %s", error->message); + if (parser != NULL) + bus_config_parser_unref (parser); ++ ++ _dbus_daemon_report_reloaded (); + return ret; + } + +diff --git a/dbus/dbus-sysdeps-util-unix.c b/dbus/dbus-sysdeps-util-unix.c +index 838cd932..8a7c9278 100644 +--- a/dbus/dbus-sysdeps-util-unix.c ++++ b/dbus/dbus-sysdeps-util-unix.c +@@ -1531,3 +1531,28 @@ _dbus_daemon_report_ready (void) + sd_notify (0, "READY=1"); + #endif + } ++ ++/** ++ * Report to a service manager that the daemon calling this function is ++ * reloading configuration. This is currently only implemented for systemd. ++ */ ++void ++_dbus_daemon_report_reloading (void) ++{ ++#ifdef HAVE_SYSTEMD ++ sd_notify (0, "RELOADING=1"); ++#endif ++} ++ ++/** ++ * Report to a service manager that the daemon calling this function is ++ * reloading configuration. This is currently only implemented for systemd. ++ */ ++void ++_dbus_daemon_report_reloaded (void) ++{ ++#ifdef HAVE_SYSTEMD ++ /* For systemd, this is the same code */ ++ _dbus_daemon_report_ready (); ++#endif ++} +diff --git a/dbus/dbus-sysdeps-util-win.c b/dbus/dbus-sysdeps-util-win.c +index f613130e..917dd05e 100644 +--- a/dbus/dbus-sysdeps-util-win.c ++++ b/dbus/dbus-sysdeps-util-win.c +@@ -1659,3 +1659,13 @@ void + _dbus_daemon_report_ready (void) + { + } ++ ++void ++_dbus_daemon_report_reloading (void) ++{ ++} ++ ++void ++_dbus_daemon_report_reloaded (void) ++{ ++} +diff --git a/dbus/dbus-sysdeps.h b/dbus/dbus-sysdeps.h +index b2943906..d8e69589 100644 +--- a/dbus/dbus-sysdeps.h ++++ b/dbus/dbus-sysdeps.h +@@ -688,6 +688,8 @@ dbus_bool_t _dbus_test_append_different_username (DBusString *username); + #endif /* DBUS_ENABLE_EMBEDDED_TESTS */ + + void _dbus_daemon_report_ready (void); ++void _dbus_daemon_report_reloading (void); ++void _dbus_daemon_report_reloaded (void); + + /** @} */ + +-- +2.27.0 + diff --git a/backport-bus-Clear-INVOCATION_ID-when-carrying-out-traditiona.patch b/backport-bus-Clear-INVOCATION_ID-when-carrying-out-traditiona.patch new file mode 100644 index 0000000..8c1d14f --- /dev/null +++ b/backport-bus-Clear-INVOCATION_ID-when-carrying-out-traditiona.patch @@ -0,0 +1,45 @@ +From 66246fff2a0bd005817fb9d108544da86973a81e Mon Sep 17 00:00:00 2001 +From: Simon McVittie +Date: Tue, 20 Mar 2018 12:33:51 +0000 +Subject: [PATCH] bus: Clear INVOCATION_ID when carrying out traditional + activation + +We weren't sure whether this one should be inherited or not, so I +asked on systemd-devel, and Lennart thought it shouldn't. + +Signed-off-by: Simon McVittie +Bug: https://bugs.freedesktop.org/show_bug.cgi?id=104641 +Reviewed-by: Philip Withnall +--- + bus/activation.c | 8 +++++++- + 1 file changed, 7 insertions(+), 1 deletion(-) + +diff --git a/bus/activation.c b/bus/activation.c +index 66640ba6..2a427d9c 100644 +--- a/bus/activation.c ++++ b/bus/activation.c +@@ -862,7 +862,6 @@ populate_environment (BusActivation *activation) + * - TERM, WATCHDOG_*: Should not be set for dbus-daemon, so not applicable + * - MAINPID, SERVICE_RESULT, EXIT_CODE, EXIT_STATUS: Not set for ExecStart, + * so not applicable +- * - INVOCATION_ID: TODO: Do we want to clear this or not? It isn't clear. + */ + + /* We give activated services their own Journal stream to avoid their +@@ -878,6 +877,13 @@ populate_environment (BusActivation *activation) + * (and NotifyAccess wouldn't let it write here anyway) */ + _dbus_hash_table_remove_string (activation->environment, "NOTIFY_SOCKET"); + ++ /* This identifies the dbus-daemon invocation. Whether it should be ++ * inherited by "smaller" services isn't entirely clear-cut, but not ++ * inheriting it makes traditional D-Bus activation under systemd a ++ * little more consistent with systemd activation. ++ * https://lists.freedesktop.org/archives/systemd-devel/2018-March/040467.html */ ++ _dbus_hash_table_remove_string (activation->environment, "INVOCATION_ID"); ++ + return retval; + } + +-- +2.27.0 + diff --git a/backport-bus-Don-t-pass-systemd-environment-variables-to-acti.patch b/backport-bus-Don-t-pass-systemd-environment-variables-to-acti.patch new file mode 100644 index 0000000..0cdc14a --- /dev/null +++ b/backport-bus-Don-t-pass-systemd-environment-variables-to-acti.patch @@ -0,0 +1,57 @@ +From be4670767377a08b0c6cabbca1000ca614174c2c Mon Sep 17 00:00:00 2001 +From: Simon McVittie +Date: Mon, 15 Jan 2018 15:26:33 +0000 +Subject: [PATCH] bus: Don't pass systemd environment variables to activated + services + +Signed-off-by: Simon McVittie +Bug: https://bugs.freedesktop.org/show_bug.cgi?id=104641 +Reviewed-by: Philip Withnall +--- + bus/activation.c | 30 ++++++++++++++++++++++++++++++ + 1 file changed, 30 insertions(+) + +diff --git a/bus/activation.c b/bus/activation.c +index edf96a2c..66640ba6 100644 +--- a/bus/activation.c ++++ b/bus/activation.c +@@ -848,6 +848,36 @@ populate_environment (BusActivation *activation) + retval = _dbus_hash_table_from_array (activation->environment, environment, '='); + dbus_free_string_array (environment); + ++ /* ++ * These environment variables are set by systemd for the dbus-daemon ++ * itself, and are not applicable to our child processes. ++ * ++ * Of the other environment variables listed in systemd.exec(5): ++ * ++ * - XDG_RUNTIME_DIR, XDG_SESSION_ID, XDG_SEAT, XDG_VTNR: Properties of ++ * the session and equally true for the activated service, should not ++ * be reset ++ * - PATH, LANG, USER, LOGNAME, HOME, SHELL, MANAGERPID: Equally true for ++ * the activated service, should not be reset ++ * - TERM, WATCHDOG_*: Should not be set for dbus-daemon, so not applicable ++ * - MAINPID, SERVICE_RESULT, EXIT_CODE, EXIT_STATUS: Not set for ExecStart, ++ * so not applicable ++ * - INVOCATION_ID: TODO: Do we want to clear this or not? It isn't clear. ++ */ ++ ++ /* We give activated services their own Journal stream to avoid their ++ * logging being attributed to dbus-daemon */ ++ _dbus_hash_table_remove_string (activation->environment, "JOURNAL_STREAM"); ++ ++ /* This is dbus-daemon's listening socket, not the activatable service's */ ++ _dbus_hash_table_remove_string (activation->environment, "LISTEN_FDNAMES"); ++ _dbus_hash_table_remove_string (activation->environment, "LISTEN_FDS"); ++ _dbus_hash_table_remove_string (activation->environment, "LISTEN_PID"); ++ ++ /* This is dbus-daemon's status notification, not the activatable service's ++ * (and NotifyAccess wouldn't let it write here anyway) */ ++ _dbus_hash_table_remove_string (activation->environment, "NOTIFY_SOCKET"); ++ + return retval; + } + +-- +2.27.0 + diff --git a/backport-bus-Notify-systemd-when-we-are-ready.patch b/backport-bus-Notify-systemd-when-we-are-ready.patch new file mode 100644 index 0000000..b100c22 --- /dev/null +++ b/backport-bus-Notify-systemd-when-we-are-ready.patch @@ -0,0 +1,103 @@ +From 18a0a8892b99f235e3897d9e5c600da00c61ef0a Mon Sep 17 00:00:00 2001 +From: Simon McVittie +Date: Mon, 15 Jan 2018 15:15:52 +0000 +Subject: [PATCH] bus: Notify systemd when we are ready + +Signed-off-by: Simon McVittie +Bug: https://bugs.freedesktop.org/show_bug.cgi?id=104641 +Reviewed-by: Philip Withnall +--- + bus/dbus.service.in | 2 ++ + bus/main.c | 1 + + bus/systemd-user/dbus.service.in | 2 ++ + dbus/dbus-sysdeps-util-unix.c | 12 ++++++++++++ + dbus/dbus-sysdeps-util-win.c | 5 +++++ + dbus/dbus-sysdeps.h | 2 ++ + 6 files changed, 24 insertions(+) + +diff --git a/bus/dbus.service.in b/bus/dbus.service.in +index ca0b7e96..3713810b 100644 +--- a/bus/dbus.service.in ++++ b/bus/dbus.service.in +@@ -4,6 +4,8 @@ Documentation=man:dbus-daemon(1) + Requires=dbus.socket + + [Service] ++Type=notify ++NotifyAccess=main + ExecStart=@EXPANDED_BINDIR@/dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activation --syslog-only + ExecReload=@EXPANDED_BINDIR@/dbus-send --print-reply --system --type=method_call --dest=org.freedesktop.DBus / org.freedesktop.DBus.ReloadConfig + OOMScoreAdjust=-900 +diff --git a/bus/main.c b/bus/main.c +index b3fcddd0..578aa989 100644 +--- a/bus/main.c ++++ b/bus/main.c +@@ -716,6 +716,7 @@ main (int argc, char **argv) + #endif /* DBUS_UNIX */ + + _dbus_verbose ("We are on D-Bus...\n"); ++ _dbus_daemon_report_ready (); + _dbus_loop_run (bus_context_get_loop (context)); + + bus_context_shutdown (context); +diff --git a/bus/systemd-user/dbus.service.in b/bus/systemd-user/dbus.service.in +index 7ceffbee..b291b923 100644 +--- a/bus/systemd-user/dbus.service.in ++++ b/bus/systemd-user/dbus.service.in +@@ -4,5 +4,7 @@ Documentation=man:dbus-daemon(1) + Requires=dbus.socket + + [Service] ++Type=notify ++NotifyAccess=main + ExecStart=@EXPANDED_BINDIR@/dbus-daemon --session --address=systemd: --nofork --nopidfile --systemd-activation --syslog-only + ExecReload=@EXPANDED_BINDIR@/dbus-send --print-reply --session --type=method_call --dest=org.freedesktop.DBus / org.freedesktop.DBus.ReloadConfig +diff --git a/dbus/dbus-sysdeps-util-unix.c b/dbus/dbus-sysdeps-util-unix.c +index b841bf63..838cd932 100644 +--- a/dbus/dbus-sysdeps-util-unix.c ++++ b/dbus/dbus-sysdeps-util-unix.c +@@ -1564,3 +1564,15 @@ _dbus_test_append_different_username (DBusString *username) + } + + #endif ++ ++/** ++ * Report to a service manager that the daemon calling this function is ++ * ready for use. This is currently only implemented for systemd. ++ */ ++void ++_dbus_daemon_report_ready (void) ++{ ++#ifdef HAVE_SYSTEMD ++ sd_notify (0, "READY=1"); ++#endif ++} +diff --git a/dbus/dbus-sysdeps-util-win.c b/dbus/dbus-sysdeps-util-win.c +index 1ef4ae6c..f613130e 100644 +--- a/dbus/dbus-sysdeps-util-win.c ++++ b/dbus/dbus-sysdeps-util-win.c +@@ -1678,3 +1678,8 @@ _dbus_test_append_different_uid (DBusString *uid) + } + + #endif ++ ++void ++_dbus_daemon_report_ready (void) ++{ ++} +diff --git a/dbus/dbus-sysdeps.h b/dbus/dbus-sysdeps.h +index b9b0c440..b2943906 100644 +--- a/dbus/dbus-sysdeps.h ++++ b/dbus/dbus-sysdeps.h +@@ -687,6 +687,8 @@ dbus_bool_t _dbus_test_append_different_username (DBusString *username); + #endif + #endif /* DBUS_ENABLE_EMBEDDED_TESTS */ + ++void _dbus_daemon_report_ready (void); ++ + /** @} */ + + DBUS_END_DECLS +-- +2.27.0 + diff --git a/dbus.spec b/dbus.spec index f95d478..499a8e5 100644 --- a/dbus.spec +++ b/dbus.spec @@ -10,6 +10,12 @@ Source1: 00-start-message-bus.sh Patch0001: bugfix-let-systemd-restart-dbus-when-the-it-enters-failed.patch +Patch6000: backport-bus-Notify-systemd-when-we-are-ready.patch +Patch6001: backport-bus-Also-tell-systemd-when-we-re-reloading.patch +Patch6002: backport-bus-Also-tell-systemd-before-we-shut-down.patch +Patch6003: backport-bus-Don-t-pass-systemd-environment-variables-to-acti.patch +Patch6004: backport-bus-Clear-INVOCATION_ID-when-carrying-out-traditiona.patch + BuildRequires: systemd-devel expat-devel libselinux-devel audit-libs-devel doxygen xmlto cmake BuildRequires: autoconf-archive libtool libX11-devel libcap-ng-devel libxslt @@ -221,6 +227,9 @@ fi %exclude %{_pkgdocdir}/README %changelog +* Sat Jan 29 2022 licunlong - 1:1.12.20-5 +- Tell systemd when dbus is ready/shutting down/reloading config. + * Thu Jul 22 2021 yangmingtai - 1:1.12.20-4 - remove build requires of gdb -- Gitee