Projects
openEuler:Mainline
systemd
Sign Up
Log In
Username
Password
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
Expand all
Collapse all
Changes of Revision 10
View file
_service:tar_scm:systemd.spec
Changed
@@ -21,7 +21,7 @@ Name: systemd Url: https://www.freedesktop.org/wiki/Software/systemd Version: 253 -Release: 1 +Release: 3 License: MIT and LGPLv2+ and GPLv2+ Summary: System and Service Manager @@ -46,6 +46,65 @@ Source106: write_net_rules Source107: detect_virt +Patch6001: backport-Revert-sysctl.d-switch-net.ipv4.conf.all.rp_filter-f.patch +Patch6002: backport-Avoid-tmp-being-mounted-as-tmpfs-without-the-user-s-.patch +Patch6003: backport-temporarily-disable-test-seccomp.patch +Patch6004: backport-sd-event-always-initialize-sd_event.perturb.patch +Patch6005: backport-sd-event-fix-error-handling.patch +Patch6006: backport-core-refuse-dbus-activation-if-dbus-is-not-running.patch +Patch6007: backport-core-only-refuse-Type-dbus-service-enqueuing-if-dbus.patch + +Patch9008: update-rtc-with-system-clock-when-shutdown.patch +Patch9009: udev-add-actions-while-rename-netif-failed.patch +Patch9010: fix-two-VF-virtual-machines-have-same-mac-address.patch +Patch9011: logind-set-RemoveIPC-to-false-by-default.patch +Patch9012: rules-add-rule-for-naming-Dell-iDRAC-USB-Virtual-NIC.patch +Patch9013: unit-don-t-add-Requires-for-tmp.mount.patch +Patch9014: rules-add-elevator-kernel-command-line-parameter.patch +Patch9015: rules-add-the-rule-that-adds-elevator-kernel-command.patch +Patch9016: units-add-Install-section-to-tmp.mount.patch +Patch9017: Make-systemd-udevd.service-start-after-systemd-remou.patch +Patch9018: udev-virsh-shutdown-vm.patch +Patch9019: sd-bus-properly-initialize-containers.patch +Patch9020: Revert-core-one-step-back-again-for-nspawn-we-actual.patch +Patch9021: systemd-change-time-log-level.patch +Patch9022: fix-capsh-drop-but-ping-success.patch +Patch9023: resolved-create-etc-resolv.conf-symlink-at-runtime.patch +Patch9024: pid1-bump-DefaultTasksMax-to-80-of-the-kernel-pid.ma.patch +Patch9025: fix-journal-file-descriptors-leak-problems.patch +Patch9026: activation-service-must-be-restarted-when-reactivated.patch +Patch9027: systemd-core-fix-problem-of-dbus-service-can-not-be-started.patch +Patch9028: delay-to-restart-when-a-service-can-not-be-auto-restarted.patch +Patch9029: disable-initialize_clock.patch +Patch9030: systemd-solve-that-rsyslog-reads-journal-s-object-of.patch +Patch9031: check-whether-command_prev-is-null-before-assigning-.patch +Patch9032: revert-rpm-restart-services-in-posttrans.patch +Patch9033: Don-t-set-AlternativeNamesPolicy-by-default.patch +Patch9034: change-NTP-server-to-x.pool.ntp.org.patch +Patch9035: keep-weight-consistent-with-the-set-value.patch +Patch9036: Systemd-Add-sw64-architecture.patch +Patch9037: core-update-arg_default_rlimit-in-bump_rlimit.patch +Patch9038: set-forwardtowall-no-to-avoid-emerg-log-shown-on-she.patch +Patch9039: core-cgroup-support-cpuset.patch +Patch9040: core-cgroup-support-freezer.patch +Patch9041: core-cgroup-support-memorysw.patch +Patch9042: systemd-core-Add-new-rules-for-lower-priority-events.patch +Patch9043: bugfix-also-stop-machine-when-a-machine-un.patch +Patch9044: print-the-process-status-to-console-when-shutdown.patch +Patch9045: Retry-to-handle-the-uevent-when-worker-is-terminated.patch +Patch9046: treat-hyphen-as-valid-hostname-char.patch +Patch9047: process-util-log-more-information-when-runnin.patch +Patch9048: fuser-print-umount-message-to-reboot-umount-msg.patch +Patch9049: shutdown-reboot-when-recieve-crash-signal.patch +Patch9050: core-add-OptionalLog-to-allow-users-change-log-level.patch +Patch9051: core-cgroup-support-default-slice-for-all-uni.patch +Patch9052: core-add-invalidate-cgroup-config.patch +Patch9053: let-the-child-of-one-unit-don-t-affect-each-other.patch +Patch9054: support-disable-cgroup-controllers-we-don-t-want.patch +Patch9055: bugfix-for-cgroup-Swap-cgroup-v1-deletion-and-migration.patch +Patch9056: delete-journal-files-except-system.journal-when-jour.patch +Patch9057: set-the-cpuset.cpus-mems-of-machine.slice-to-all-by-.patch + BuildRequires: gcc, gcc-c++ BuildRequires: libcap-devel, libmount-devel, pam-devel, libselinux-devel BuildRequires: audit-libs-devel, dbus-devel, libacl-devel @@ -228,6 +287,9 @@ %prep %autosetup -n %{name}-%{version} -p1 -Sgit +%ifnarch sw_64 +%patch9029 -R -p1 +%endif %build @@ -420,9 +482,9 @@ fi fi done -# add rpath path /usr/lib/systemd in ld.so.conf.d +# add rpath path _libdir/systemd in ld.so.conf.d mkdir -p %{buildroot}%{_sysconfdir}/ld.so.conf.d -echo "/usr/lib/systemd" > %{buildroot}%{_sysconfdir}/ld.so.conf.d/%{name}-%{_arch}.conf +echo "%{_libdir}/systemd" > %{buildroot}%{_sysconfdir}/ld.so.conf.d/%{name}-%{_arch}.conf %check %ifnarch loongarch64 @@ -880,6 +942,8 @@ /usr/lib/sysusers.d/basic.conf /usr/lib/sysusers.d/systemd-coredump.conf /usr/lib/sysusers.d/systemd-journal.conf +/usr/lib/systemd/system/hwclock-save.service +/usr/lib/systemd/system/sysinit.target.wants/hwclock-save.service %{_systemddir}/systemd-update-done %{_systemddir}/systemd-update-utmp %{_systemddir}/systemd-initctl @@ -905,8 +969,8 @@ %dir %{_systemddir}/system-preset %dir %{_systemddir}/user-environment-generators %{_systemddir}/systemd-shutdown -/usr/lib64/systemd/libsystemd-core-*.so -/usr/lib64/systemd/libsystemd-shared*.so +%{_libdir}/systemd/libsystemd-core-*.so +%{_libdir}/systemd/libsystemd-shared*.so %{_systemddir}/systemd-reply-password %dir %{_systemddir}/system-generators %dir %{_systemddir}/system @@ -1344,6 +1408,8 @@ %dir /usr/lib/udev/rules.d %{_udevrulesdir}/60-autosuspend.rules %{_udevrulesdir}/40-%{vendor}.rules +%{_udevrulesdir}/40-elevator.rules +%{_udevrulesdir}/73-idrac.rules %{_udevrulesdir}/60-block.rules %{_udevrulesdir}/60-input-id.rules %{_udevrulesdir}/71-seat.rules @@ -1498,6 +1564,12 @@ %{_libdir}/security/pam_systemd.so %changelog +* Mon Jul 31 2023 huyubiao <huyubiao@huawei.com> - 253-3 +- sync the patch from v249 + +* Sat Jul 29 2023 huyubiao <huyubiao@huawei.com> - 253-2 +- fix the dynamic library cannot be found + * Thu Jul 20 2023 huyubiao <huyubiao@huawei.com> - 253-1 - systemd update to v253
View file
_service:tar_scm:Don-t-set-AlternativeNamesPolicy-by-default.patch
Added
@@ -0,0 +1,26 @@ +From 1e3f74b7ca5ead53c10e5b37cf8660651f32d181 Mon Sep 17 00:00:00 2001 +From: xujing <xujing125@huawei.com> +Date: Thu, 11 Aug 2022 19:53:35 +0800 +Subject: PATCH Don't set AlternativeNamesPolicy by default + +When a network adapter is renamed, the altname of the network adapter may be +set based on AlternativeNamesPolicy. As a result, the network adapter name +fails to be restored. For example, after enp4s0 is renamed tmp, udev sets the +altname of tmp to enp4s0. If you want to restore tmp to enp4s0, it will fail. +--- + network/99-default.link | 1 - + 1 file changed, 1 deletion(-) + +diff --git a/network/99-default.link b/network/99-default.link +index 31aee37..db48c4d 100644 +--- a/network/99-default.link ++++ b/network/99-default.link +@@ -12,5 +12,4 @@ OriginalName=* + + Link + NamePolicy=keep kernel database onboard slot path +-AlternativeNamesPolicy=database onboard slot path + MACAddressPolicy=none +-- +2.23.0 +
View file
_service:tar_scm:Make-systemd-udevd.service-start-after-systemd-remou.patch
Added
@@ -0,0 +1,24 @@ +From 4c230d1d73e9f9a6d1fe654599a63881c344a00c Mon Sep 17 00:00:00 2001 +From: openEuler Buildteam <buildteam@openeuler.org> +Date: Tue, 29 Jan 2019 22:54:34 -0500 +Subject: PATCH Make systemd-udevd.service start after systemd-remount-fs.service. +--- + units/systemd-udevd.service.in | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/units/systemd-udevd.service.in b/units/systemd-udevd.service.in +index 9ada3a6a74..17f15bba83 100644 +--- a/units/systemd-udevd.service.in ++++ b/units/systemd-udevd.service.in +@@ -11,7 +11,7 @@ + Description=Rule-based Manager for Device Events and Files + Documentation=man:systemd-udevd.service(8) man:udev(7) + DefaultDependencies=no +-After=systemd-sysusers.service systemd-hwdb-update.service ++After=systemd-sysusers.service systemd-hwdb-update.service systemd-remount-fs.service + Before=sysinit.target + ConditionPathIsReadWrite=/sys + +-- +2.23.0 +
View file
_service:tar_scm:Retry-to-handle-the-uevent-when-worker-is-terminated.patch
Added
@@ -0,0 +1,87 @@ +From a3d2f4261ef9a953904e3e21abafba0dad7daa77 Mon Sep 17 00:00:00 2001 +From: gaoyi <gaoyi15@huawei.com> +Date: Mon, 28 Sep 2020 22:36:37 +0800 +Subject: PATCH Retry to handle the uevent when worker is terminated abnormal + +When processing uevent events fails, retry it. +--- + src/udev/udevd.c | 35 +++++++++++++++++++++++++++++++++-- + 1 file changed, 33 insertions(+), 2 deletions(-) + +diff --git a/src/udev/udevd.c b/src/udev/udevd.c +index c6d24d9..512192e 100644 +--- a/src/udev/udevd.c ++++ b/src/udev/udevd.c +@@ -74,6 +74,7 @@ + #include "version.h" + + #define WORKER_NUM_MAX 2048U ++#define UEVENT_MAX_RETRY_TIMES 3 + #define EVENT_RETRY_INTERVAL_USEC (200 * USEC_PER_MSEC) + #define EVENT_RETRY_TIMEOUT_USEC (3 * USEC_PER_MINUTE) + +@@ -129,6 +130,7 @@ typedef struct Event { + Manager *manager; + Worker *worker; + EventState state; ++ int retry; + + sd_device *dev; + +@@ -182,6 +184,32 @@ typedef enum EventResult { + _EVENT_RESULT_INVALID = -EINVAL, + } EventResult; + ++static bool event_retry(Event *event) { ++ if (!event) ++ return false; ++ ++ assert(event->manager); ++ ++ if (--event->retry < 0) { ++ log_device_error(event->dev, "Retry failed."); ++ return false; ++ } ++ ++ log_device_info(event->dev, "Retry %d times.", UEVENT_MAX_RETRY_TIMES - event->retry); ++ ++ event->timeout_warning_event = sd_event_source_unref(event->timeout_warning_event); ++ event->timeout_event = sd_event_source_unref(event->timeout_event); ++ ++ if (event->worker) { ++ event->worker->event = NULL; ++ event->worker = NULL; ++ } ++ ++ event->state = EVENT_QUEUED; ++ ++ return true; ++} ++ + static Event *event_free(Event *event) { + if (!event) + return NULL; +@@ -1140,6 +1168,7 @@ static int event_queue_insert(Manager *manager, sd_device *dev) { + .devpath_old = devpath_old, + .devnode = devnode, + .state = EVENT_QUEUED, ++ .retry = UEVENT_MAX_RETRY_TIMES, + }; + + if (!manager->events) { +@@ -1513,8 +1542,10 @@ static int on_sigchld(sd_event_source *s, const siginfo_t *si, void *userdata) { + device_delete_db(dev); + device_tag_index(dev, NULL, false); + +- /* Forward kernel event to libudev listeners */ +- device_broadcast(manager->monitor, dev, result); ++ if (event_retry(worker->event) == false) { ++ /* Forward kernel event to libudev listeners */ ++ device_broadcast(manager->monitor, worker->event->dev, result); ++ } + } + + worker_free(worker); +-- +2.33.0 +
View file
_service:tar_scm:Revert-core-one-step-back-again-for-nspawn-we-actual.patch
Added
@@ -0,0 +1,43 @@ +From 9d0046ceca10911361137d6496987cb15ffff132 Mon Sep 17 00:00:00 2001 +From: Lukas Nykryn <lnykryn@redhat.com> +Date: Thu, 25 Jun 2015 09:20:59 +0200 +Subject: PATCH Revert "core: one step back again, for nspawn we + actually can't wait for cgroups running empty since systemd will get exactly + zero notifications about it" + +This reverts commit 743970d2ea6d08aa7c7bff8220f6b7702f2b1db7. + +https://bugzilla.redhat.com/show_bug.cgi?id=1141137 +https://github.com/systemd/systemd/pull/350 + +Resolves: #1703485 + +--- + src/core/unit.c | 11 +---------- + 1 file changed, 1 insertion(+), 10 deletions(-) + +diff --git a/src/core/unit.c b/src/core/unit.c +index 1cadcd4..10e314f 100644 +--- a/src/core/unit.c ++++ b/src/core/unit.c +@@ -4799,16 +4799,7 @@ int unit_kill_context( + + } else if (r > 0) { + +- /* FIXME: For now, on the legacy hierarchy, we will not wait for the cgroup members to die if +- * we are running in a container or if this is a delegation unit, simply because cgroup +- * notification is unreliable in these cases. It doesn't work at all in containers, and outside +- * of containers it can be confused easily by left-over directories in the cgroup — which +- * however should not exist in non-delegated units. On the unified hierarchy that's different, +- * there we get proper events. Hence rely on them. */ +- +- if (cg_unified_controller(SYSTEMD_CGROUP_CONTROLLER) > 0 || +- (detect_container() == 0 && !unit_cgroup_delegate(u))) +- wait_for_exit = true; ++ wait_for_exit = true; + + if (send_sighup) { + set_free(pid_set); +-- +2.19.1 +
View file
_service:tar_scm:Systemd-Add-sw64-architecture.patch
Added
@@ -0,0 +1,864 @@ +From b9043cf1d074497cf77272dd9bf24c2098e56265 Mon Sep 17 00:00:00 2001 +From: rpm-build <rpm-build> +Date: Tue, 25 Oct 2022 15:26:32 +0800 +Subject: PATCH Systemd Add sw64 architecture + +Signed-off-by: rpm-build <rpm-build> +--- + src/basic/architecture.c | 4 + + src/basic/architecture.h | 4 + + src/basic/meson.build | 1 + + src/basic/missing_fcntl.h | 2 + + src/basic/missing_syscall_def.h | 33 ++ + src/basic/missing_syscalls.py | 2 + + src/basic/syscalls-sw_64.txt | 600 ++++++++++++++++++++++++++++++++ + 7 files changed, 646 insertions(+) + create mode 100644 src/basic/syscalls-sw_64.txt + +diff --git a/src/basic/architecture.c b/src/basic/architecture.c +index 773ee3c..59a4e31 100644 +--- a/src/basic/architecture.c ++++ b/src/basic/architecture.c +@@ -49,6 +49,9 @@ Architecture uname_architecture(void) { + #elif defined(__alpha__) + { "alpha" , ARCHITECTURE_ALPHA }, + ++#elif defined(__sw_64__) ++ { "sw_64" , ARCHITECTURE_SW_64 }, ++ + #elif defined(__arc__) + { "arc", ARCHITECTURE_ARC }, + { "arceb", ARCHITECTURE_ARC_BE }, +@@ -145,6 +148,7 @@ static const char *const architecture_table_ARCHITECTURE_MAX = { + ARCHITECTURE_ARM = "arm", + ARCHITECTURE_ARM_BE = "arm-be", + ARCHITECTURE_ALPHA = "alpha", ++ ARCHITECTURE_SW_64 = "sw_64", + ARCHITECTURE_ARC = "arc", + ARCHITECTURE_ARC_BE = "arc-be", + ARCHITECTURE_CRIS = "cris", +diff --git a/src/basic/architecture.h b/src/basic/architecture.h +index 096526a..4c4be03 100644 +--- a/src/basic/architecture.h ++++ b/src/basic/architecture.h +@@ -11,6 +11,7 @@ + + typedef enum { + ARCHITECTURE_ALPHA, ++ ARCHITECTURE_SW_64, + ARCHITECTURE_ARC, + ARCHITECTURE_ARC_BE, + ARCHITECTURE_ARM, +@@ -142,6 +143,9 @@ Architecture uname_architecture(void); + #elif defined(__alpha__) + # define native_architecture() ARCHITECTURE_ALPHA + # define LIB_ARCH_TUPLE "alpha-linux-gnu" ++#elif defined(__sw_64__) ++# define native_architecture() ARCHITECTURE_SW_64 ++# define LIB_ARCH_TUPLE "sw_64-linux-gnu" + #elif defined(__aarch64__) + # if __BYTE_ORDER == __BIG_ENDIAN + # define native_architecture() ARCHITECTURE_ARM64_BE +diff --git a/src/basic/meson.build b/src/basic/meson.build +index 7aae031..f0a0282 100644 +--- a/src/basic/meson.build ++++ b/src/basic/meson.build +@@ -177,6 +177,7 @@ basic_sources += generated_gperf_headers + + arch_list = + 'alpha', ++ 'sw_64', + 'arc', + 'arm', + 'arm64', +diff --git a/src/basic/missing_fcntl.h b/src/basic/missing_fcntl.h +index 00937d2..fff662b 100644 +--- a/src/basic/missing_fcntl.h ++++ b/src/basic/missing_fcntl.h +@@ -45,6 +45,8 @@ + #ifndef __O_TMPFILE + #if defined(__alpha__) + #define __O_TMPFILE 0100000000 ++#elif defined(__sw_64__) ++#define __O_TMPFILE 0100000000 + #elif defined(__parisc__) || defined(__hppa__) + #define __O_TMPFILE 0400000000 + #elif defined(__sparc__) || defined(__sparc64__) +diff --git a/src/basic/missing_syscall_def.h b/src/basic/missing_syscall_def.h +index 402fdd0..9680923 100644 +--- a/src/basic/missing_syscall_def.h ++++ b/src/basic/missing_syscall_def.h +@@ -10,6 +10,7 @@ + * template as the per-syscall blocks below. */ + # if defined(__aarch64__) + # elif defined(__alpha__) ++# elif defined(__sw_64__) + # elif defined(__arc__) || defined(__tilegx__) + # elif defined(__arm__) + # elif defined(__i386__) +@@ -47,6 +48,8 @@ + # define systemd_NR_bpf 280 + # elif defined(__alpha__) + # define systemd_NR_bpf 515 ++# elif defined(__sw_64__) ++# define systemd_NR_bpf 170 + # elif defined(__arc__) || defined(__tilegx__) + # define systemd_NR_bpf 280 + # elif defined(__arm__) +@@ -115,6 +118,8 @@ assert_cc(__NR_bpf == systemd_NR_bpf); + # define systemd_NR_close_range 436 + # elif defined(__alpha__) + # define systemd_NR_close_range 546 ++# elif defined(__sw_64__) ++# define systemd_NR_close_range 283 + # elif defined(__arc__) || defined(__tilegx__) + # define systemd_NR_close_range 436 + # elif defined(__arm__) +@@ -183,6 +188,8 @@ assert_cc(__NR_close_range == systemd_NR_close_range); + # define systemd_NR_copy_file_range 285 + # elif defined(__alpha__) + # define systemd_NR_copy_file_range 519 ++# elif defined(__sw_64__) ++# define systemd_NR_copy_file_range 515 + # elif defined(__arc__) || defined(__tilegx__) + # define systemd_NR_copy_file_range 285 + # elif defined(__arm__) +@@ -251,6 +258,8 @@ assert_cc(__NR_copy_file_range == systemd_NR_copy_file_range); + # define systemd_NR_getrandom 278 + # elif defined(__alpha__) + # define systemd_NR_getrandom 511 ++# elif defined(__sw_64__) ++# define systemd_NR_getrandom 511 + # elif defined(__arc__) || defined(__tilegx__) + # define systemd_NR_getrandom 278 + # elif defined(__arm__) +@@ -319,6 +328,8 @@ assert_cc(__NR_getrandom == systemd_NR_getrandom); + # define systemd_NR_memfd_create 279 + # elif defined(__alpha__) + # define systemd_NR_memfd_create 512 ++# elif defined(__sw_64__) ++# define systemd_NR_memfd_create 512 + # elif defined(__arc__) || defined(__tilegx__) + # define systemd_NR_memfd_create 279 + # elif defined(__arm__) +@@ -387,6 +398,8 @@ assert_cc(__NR_memfd_create == systemd_NR_memfd_create); + # define systemd_NR_mount_setattr 442 + # elif defined(__alpha__) + # define systemd_NR_mount_setattr 552 ++# elif defined(__sw_64__) ++# define systemd_NR_mount_setattr 552 + # elif defined(__arc__) || defined(__tilegx__) + # define systemd_NR_mount_setattr 442 + # elif defined(__arm__) +@@ -455,6 +468,8 @@ assert_cc(__NR_mount_setattr == systemd_NR_mount_setattr); + # define systemd_NR_move_mount 429 + # elif defined(__alpha__) + # define systemd_NR_move_mount 539 ++# elif defined(__sw_64__) ++# define systemd_NR_move_mount 276 + # elif defined(__arc__) || defined(__tilegx__) + # define systemd_NR_move_mount 429 + # elif defined(__arm__) +@@ -523,6 +538,8 @@ assert_cc(__NR_move_mount == systemd_NR_move_mount); + # define systemd_NR_name_to_handle_at 264 + # elif defined(__alpha__) + # define systemd_NR_name_to_handle_at 497 ++# elif defined(__sw_64__) ++# define systemd_NR_name_to_handle_at 497 + # elif defined(__arc__) || defined(__tilegx__) + # define systemd_NR_name_to_handle_at 264 + # elif defined(__arm__) +@@ -591,6 +608,8 @@ assert_cc(__NR_name_to_handle_at == systemd_NR_name_to_handle_at); + # define systemd_NR_open_tree 428 + # elif defined(__alpha__) + # define systemd_NR_open_tree 538 ++# elif defined(__sw_64__) ++# define systemd_NR_open_tree 275 + # elif defined(__arc__) || defined(__tilegx__) + # define systemd_NR_open_tree 428 + # elif defined(__arm__) +@@ -659,6 +678,8 @@ assert_cc(__NR_open_tree == systemd_NR_open_tree); + # define systemd_NR_openat2 437 + # elif defined(__alpha__) + # define systemd_NR_openat2 547 ++# elif defined(__sw_64__) ++# define systemd_NR_openat2 284 + # elif defined(__arc__) || defined(__tilegx__) + # define systemd_NR_openat2 437 + # elif defined(__arm__) +@@ -727,6 +748,8 @@ assert_cc(__NR_openat2 == systemd_NR_openat2); + # define systemd_NR_pidfd_open 434 + # elif defined(__alpha__) + # define systemd_NR_pidfd_open 544 ++# elif defined(__sw_64__) ++# define systemd_NR_pidfd_open 281 + # elif defined(__arc__) || defined(__tilegx__) + # define systemd_NR_pidfd_open 434 + # elif defined(__arm__) +@@ -795,6 +818,8 @@ assert_cc(__NR_pidfd_open == systemd_NR_pidfd_open); + # define systemd_NR_pidfd_send_signal 424 + # elif defined(__alpha__) + # define systemd_NR_pidfd_send_signal 534 ++# elif defined(__sw_64__) ++# define systemd_NR_pidfd_send_signal 271 + # elif defined(__arc__) || defined(__tilegx__) + # define systemd_NR_pidfd_send_signal 424 + # elif defined(__arm__) +@@ -863,6 +888,8 @@ assert_cc(__NR_pidfd_send_signal == systemd_NR_pidfd_send_signal); + # define systemd_NR_pkey_mprotect 288 + # elif defined(__alpha__) + # define systemd_NR_pkey_mprotect 524 ++# elif defined(__sw_64__) ++# define systemd_NR_pkey_mprotect 288 + # elif defined(__arc__) || defined(__tilegx__) + # define systemd_NR_pkey_mprotect 288 + # elif defined(__arm__) +@@ -931,6 +958,8 @@ assert_cc(__NR_pkey_mprotect == systemd_NR_pkey_mprotect); + # define systemd_NR_renameat2 276 + # elif defined(__alpha__) + # define systemd_NR_renameat2 510 ++# elif defined(__sw_64__) ++# define systemd_NR_renameat2 510 + # elif defined(__arc__) || defined(__tilegx__) + # define systemd_NR_renameat2 276 + # elif defined(__arm__) +@@ -999,6 +1028,8 @@ assert_cc(__NR_renameat2 == systemd_NR_renameat2); + # define systemd_NR_setns 268 + # elif defined(__alpha__) + # define systemd_NR_setns 501 ++# elif defined(__sw_64__) ++# define systemd_NR_setns 501 + # elif defined(__arc__) || defined(__tilegx__) + # define systemd_NR_setns 268 + # elif defined(__arm__) +@@ -1067,6 +1098,8 @@ assert_cc(__NR_setns == systemd_NR_setns); + # define systemd_NR_statx 291 + # elif defined(__alpha__) + # define systemd_NR_statx 522 ++# elif defined(__sw_64__) ++# define systemd_NR_statx 518 + # elif defined(__arc__) || defined(__tilegx__) + # define systemd_NR_statx 291 + # elif defined(__arm__) +diff --git a/src/basic/missing_syscalls.py b/src/basic/missing_syscalls.py +index 5ccf02a..a7bfe7e 100644 +--- a/src/basic/missing_syscalls.py ++++ b/src/basic/missing_syscalls.py +@@ -51,6 +51,8 @@ DEF_TEMPLATE_B = '''\ + # define systemd_NR_{syscall} {nr_arm64} + # elif defined(__alpha__) + # define systemd_NR_{syscall} {nr_alpha} ++# elif defined(__sw_64__) ++# define systemd_NR_{syscall} {nr_sw_64} + # elif defined(__arc__) || defined(__tilegx__) + # define systemd_NR_{syscall} {nr_arc} + # elif defined(__arm__) +diff --git a/src/basic/syscalls-sw_64.txt b/src/basic/syscalls-sw_64.txt +new file mode 100644 +index 0000000..5aef86b +--- /dev/null ++++ b/src/basic/syscalls-sw_64.txt +@@ -0,0 +1,600 @@ ++_llseek ++_newselect ++_sysctl 319 ++accept 99 ++accept4 502 ++access 33 ++acct 51 ++add_key 439 ++adjtimex 366 ++alarm ++arc_gettls ++arc_settls ++arc_usr_cmpxchg ++arch_prctl ++arm_fadvise64_64 ++atomic_barrier ++atomic_cmpxchg_32 ++bdflush 300 ++bind 104 ++bpf 515 ++brk 17 ++cachectl ++cacheflush ++capget 368 ++capset 369 ++chdir 12 ++chmod 15 ++chown 16 ++chown32 ++chroot 61 ++clock_adjtime 499 ++clock_adjtime64 ++clock_getres 421 ++clock_getres_time64 ++clock_gettime 420 ++clock_gettime64 ++clock_nanosleep 422 ++clock_nanosleep_time64 ++clock_settime 419 ++clock_settime64 ++clone 312 ++clone2 ++clone3 ++close 6 ++close_range 546 ++connect 98 ++copy_file_range 519 ++creat ++create_module 306 ++delete_module 308 ++dipc 373 ++dup 41 ++dup2 90 ++dup3 487 ++epoll_create 407 ++epoll_create1 486 ++epoll_ctl 408 ++epoll_ctl_old ++epoll_pwait 474 ++epoll_pwait2 551 ++epoll_wait 409 ++epoll_wait_old ++eventfd 478 ++eventfd2 485 ++exec_with_loader 25 ++execv ++execve 59 ++execveat 513 ++exit 1 ++exit_group 405 ++faccessat 462 ++faccessat2 549 ++fadvise64 413 ++fadvise64_64 ++fallocate 480 ++fanotify_init 494 ++fanotify_mark 495 ++fchdir 13 ++fchmod 124 ++fchmodat 461 ++fchown 123 ++fchown32 ++fchownat 453 ++fcntl 92 ++fcntl64 ++fdatasync 447 ++fgetxattr 387 ++finit_module 507 ++flistxattr 390 ++flock 131 ++fork 2 ++fp_udfiex_crtl ++fremovexattr 393 ++fsconfig 541 ++fsetxattr 384 ++fsmount 542 ++fsopen 540 ++fspick 543 ++fstat 91 ++fstat64 427 ++fstatat64 455 ++fstatfs 329 ++fstatfs64 529 ++fsync 95 ++ftruncate 130 ++ftruncate64 ++futex 394 ++futex_time64 ++futex_waitv 559 ++futimesat 454 ++get_kernel_syms 309 ++get_mempolicy 430 ++get_robust_list 467 ++get_thread_area ++getcpu 473 ++getcwd 367 ++getdents 305 ++getdents64 377 ++getdomainname ++getdtablesize 89 ++getegid 530 ++getegid32 ++geteuid 531 ++geteuid32 ++getgid 47 ++getgid32 ++getgroups 79 ++getgroups32 ++gethostname 87 ++getitimer 361 ++getpagesize 64 ++getpeername 141 ++getpgid 233 ++getpgrp 63 ++getpid 20 ++getpmsg ++getppid 532 ++getpriority 100 ++getrandom 511 ++getresgid 372 ++getresgid32 ++getresuid 344 ++getresuid32 ++getrlimit 144 ++getrusage 364 ++getsid 234 ++getsockname 150 ++getsockopt 118 ++gettid 378 ++gettimeofday 359 ++getuid 24 ++getuid32 ++getunwind ++getxattr 385 ++getxgid 47 ++getxpid 20 ++getxuid 24 ++idle ++init_module 307 ++inotify_add_watch 445 ++inotify_init 444 ++inotify_init1 489 ++inotify_rm_watch 446 ++io_cancel 402 ++io_destroy 399 ++io_getevents 400 ++io_pgetevents 523 ++io_pgetevents_time64 ++io_setup 398 ++io_submit 401 ++io_uring_enter 536 ++io_uring_register 537 ++io_uring_setup 535 ++ioctl 54 ++ioperm ++iopl ++ioprio_get 443 ++ioprio_set 442 ++ipc ++kcmp 506 ++kern_features ++kexec_file_load ++kexec_load 448 ++keyctl 441 ++kill 37 ++landlock_add_rule 555 ++landlock_create_ruleset 554 ++landlock_restrict_self 556 ++lchown 208 ++lchown32 ++lgetxattr 386 ++link 9 ++linkat 458 ++listen 106 ++listxattr 388 ++llistxattr 389 ++lookup_dcookie 406 ++lremovexattr 392 ++lseek 19 ++lsetxattr 383 ++lstat 68 ++lstat64 426 ++madvise 75 ++mbind 429 ++membarrier 517 ++memfd_create 512 ++memfd_secret ++memory_ordering ++migrate_pages 449 ++mincore 375 ++mkdir 136 ++mkdirat 451 ++mknod 14 ++mknodat 452 ++mlock 314 ++mlock2 518 ++mlockall 316 ++mmap 71 ++mmap2 ++modify_ldt ++mount 302 ++mount_setattr 552 ++move_mount 539 ++move_pages 472 ++mprotect 74 ++mq_getsetattr 437 ++mq_notify 436 ++mq_open 432 ++mq_timedreceive 435 ++mq_timedreceive_time64 ++mq_timedsend 434 ++mq_timedsend_time64 ++mq_unlink 433 ++mremap 341 ++msgctl 200 ++msgget 201 ++msgrcv 202 ++msgsnd 203 ++msync 217 ++multiplexer ++munlock 315 ++munlockall 317 ++munmap 73 ++name_to_handle_at 497 ++nanosleep 340 ++newfstatat ++nfsservctl 342 ++nice ++old_adjtimex 303 ++old_getpagesize ++oldfstat ++oldlstat ++oldolduname ++oldstat ++oldumount 321 ++olduname ++open 45 ++open_by_handle_at 498 ++open_tree 538 ++openat 450 ++openat2 547 ++or1k_atomic ++osf_adjtime 140 ++osf_afs_syscall 258 ++osf_alt_plock 181 ++osf_alt_setsid 188 ++osf_alt_sigpending 187 ++osf_asynch_daemon 163 ++osf_audcntl 252 ++osf_audgen 253 ++osf_chflags 34 ++osf_execve 11 ++osf_exportfs 169 ++osf_fchflags 35 ++osf_fdatasync 261 ++osf_fpathconf 248 ++osf_fstat 226 ++osf_fstatfs 161 ++osf_fstatfs64 228 ++osf_fuser 243 ++osf_getaddressconf 214 ++osf_getdirentries 159 ++osf_getdomainname 165 ++osf_getfh 164 ++osf_getfsstat 18 ++osf_gethostid 142 ++osf_getitimer 86 ++osf_getlogin 49 ++osf_getmnt 184 ++osf_getrusage 117 ++osf_getsysinfo 256 ++osf_gettimeofday 116 ++osf_kloadcall 223 ++osf_kmodcall 77 ++osf_lstat 225 ++osf_memcntl 260 ++osf_mincore 78 ++osf_mount 21 ++osf_mremap 65 ++osf_msfs_syscall 240 ++osf_msleep 215 ++osf_mvalid 213 ++osf_mwakeup 216 ++osf_naccept 30 ++osf_nfssvc 158 ++osf_ngetpeername 31 ++osf_ngetsockname 32 ++osf_nrecvfrom 29 ++osf_nrecvmsg 27 ++osf_nsendmsg 28 ++osf_ntp_adjtime 245 ++osf_ntp_gettime 246 ++osf_old_creat 8 ++osf_old_fstat 62 ++osf_old_getpgrp 81 ++osf_old_killpg 146 ++osf_old_lstat 40 ++osf_old_open 5 ++osf_old_sigaction 46 ++osf_old_sigblock 109 ++osf_old_sigreturn 139 ++osf_old_sigsetmask 110 ++osf_old_sigvec 108 ++osf_old_stat 38 ++osf_old_vadvise 72 ++osf_old_vtrace 115 ++osf_old_wait 84 ++osf_oldquota 149 ++osf_pathconf 247 ++osf_pid_block 153 ++osf_pid_unblock 154 ++osf_plock 107 ++osf_priocntlset 237 ++osf_profil 44 ++osf_proplist_syscall 244 ++osf_reboot 55 ++osf_revoke 56 ++osf_sbrk 69 ++osf_security 222 ++osf_select 93 ++osf_set_program_attributes 43 ++osf_set_speculative 239 ++osf_sethostid 143 ++osf_setitimer 83 ++osf_setlogin 50 ++osf_setsysinfo 257 ++osf_settimeofday 122 ++osf_shmat 209 ++osf_signal 218 ++osf_sigprocmask 48 ++osf_sigsendset 238 ++osf_sigstack 112 ++osf_sigwaitprim 157 ++osf_sstk 70 ++osf_stat 224 ++osf_statfs 160 ++osf_statfs64 227 ++osf_subsys_info 255 ++osf_swapctl 259 ++osf_swapon 199 ++osf_syscall 0 ++osf_sysinfo 241 ++osf_table 85 ++osf_uadmin 242 ++osf_usleep_thread 251 ++osf_uswitch 250 ++osf_utc_adjtime 220 ++osf_utc_gettime 219 ++osf_utimes 138 ++osf_utsname 207 ++osf_wait4 7 ++osf_waitid 236 ++pause ++pciconfig_iobase 376 ++pciconfig_read 345 ++pciconfig_write 346 ++perf_event_open 493 ++perfctr ++personality 324 ++pidfd_getfd 548 ++pidfd_open 544 ++pidfd_send_signal 534 ++pipe 42 ++pipe2 488 ++pivot_root 374 ++pkey_alloc 525 ++pkey_free 526 ++pkey_mprotect 524 ++poll 94 ++ppoll 464 ++ppoll_time64 ++prctl 348 ++pread64 349 ++preadv 490 ++preadv2 520 ++prlimit64 496 ++process_madvise 550 ++process_mrelease 558 ++process_vm_readv 504 ++process_vm_writev 505 ++pselect6 463 ++pselect6_time64 ++ptrace 26 ++pwrite64 350 ++pwritev 491 ++pwritev2 521 ++query_module 347 ++quotactl 148 ++quotactl_fd 553 ++read 3 ++readahead 379 ++readdir ++readlink 58 ++readlinkat 460 ++readv 120 ++reboot 311 ++recv 102 ++recvfrom 125 ++recvmmsg 479 ++recvmmsg_time64 ++recvmsg 113 ++remap_file_pages 410 ++removexattr 391 ++rename 128 ++renameat 457 ++renameat2 510 ++request_key 440 ++restart_syscall 412 ++riscv_flush_icache ++rmdir 137 ++rseq 527 ++rt_sigaction 352 ++rt_sigpending 354 ++rt_sigprocmask 353 ++rt_sigqueueinfo 356 ++rt_sigreturn 351 ++rt_sigsuspend 357 ++rt_sigtimedwait 355 ++rt_sigtimedwait_time64 ++rt_tgsigqueueinfo 492 ++rtas ++s390_guarded_storage ++s390_pci_mmio_read ++s390_pci_mmio_write ++s390_runtime_instr ++s390_sthyi ++sched_get_affinity ++sched_get_priority_max 335 ++sched_get_priority_min 336 ++sched_getaffinity 396 ++sched_getattr 509 ++sched_getparam 331 ++sched_getscheduler 333 ++sched_rr_get_interval 337 ++sched_rr_get_interval_time64 ++sched_set_affinity ++sched_setaffinity 395 ++sched_setattr 508 ++sched_setparam 330 ++sched_setscheduler 332 ++sched_yield 334 ++seccomp 514 ++select 358 ++semctl 204 ++semget 205 ++semop 206 ++semtimedop 423 ++semtimedop_time64 ++send 101 ++sendfile 370 ++sendfile64 ++sendmmsg 503 ++sendmsg 114 ++sendto 133 ++set_mempolicy 431 ++set_robust_list 466 ++set_thread_area ++set_tid_address 411 ++setdomainname 166 ++setfsgid 326 ++setfsgid32 ++setfsuid 325 ++setfsuid32 ++setgid 132 ++setgid32 ++setgroups 80 ++setgroups32 ++sethae 301 ++sethostname 88 ++setitimer 362 ++setns 501 ++setpgid 39 ++setpgrp 82 ++setpriority 96 ++setregid 127 ++setregid32 ++setresgid 371 ++setresgid32 ++setresuid 343 ++setresuid32 ++setreuid 126 ++setreuid32 ++setrlimit 145 ++setsid 147 ++setsockopt 105 ++settimeofday 360 ++setuid 23 ++setuid32 ++setxattr 382 ++sgetmask ++shmat 209 ++shmctl 210 ++shmdt 211 ++shmget 212 ++shutdown 134 ++sigaction 156 ++sigaltstack 235 ++signal ++signalfd 476 ++signalfd4 484 ++sigpending 52 ++sigprocmask ++sigreturn 103 ++sigsuspend 111 ++socket 97 ++socketcall ++socketpair 135 ++splice 468 ++spu_create ++spu_run ++ssetmask ++stat 67 ++stat64 425 ++statfs 328 ++statfs64 528 ++statx 522 ++stime ++subpage_prot ++swapcontext ++swapoff 304 ++swapon 322 ++switch_endian ++symlink 57 ++symlinkat 459 ++sync 36 ++sync_file_range 469 ++sync_file_range2 ++syncfs 500 ++sys_debug_setcontext ++syscall ++sysfs 254 ++sysinfo 318 ++syslog 310 ++sysmips ++tee 470 ++tgkill 424 ++time ++timer_create 414 ++timer_delete 418 ++timer_getoverrun 417 ++timer_gettime 416 ++timer_gettime64 ++timer_settime 415 ++timer_settime64 ++timerfd 477 ++timerfd_create 481 ++timerfd_gettime 483 ++timerfd_gettime64 ++timerfd_settime 482 ++timerfd_settime64 ++times 323 ++tkill 381 ++truncate 129 ++truncate64 ++ugetrlimit ++umask 60 ++umount 22 ++umount2 22 ++uname 339 ++unlink 10 ++unlinkat 456 ++unshare 465 ++uselib 313 ++userfaultfd 516 ++ustat 327 ++utime ++utimensat 475 ++utimensat_time64 ++utimes 363 ++utrap_install ++vfork 66 ++vhangup 76 ++vm86 ++vm86old ++vmsplice 471 ++wait4 365 ++waitid 438 ++waitpid ++write 4 ++writev 121 +-- +2.33.0 +
View file
_service:tar_scm:activation-service-must-be-restarted-when-reactivated.patch
Added
@@ -0,0 +1,44 @@ +From 4acc8a3168e5f11b5308cf8558d68bf2a0503444 Mon Sep 17 00:00:00 2001 +From: huangkaibin <huangkaibin@huawei.com> +Date: Mon, 7 Aug 2017 17:06:30 +0800 +Subject: PATCH systemd: Activation service must be restarted when it is already started and re-actived +by dbus + +When dbus-daemon service is killed, every activation service must be restarted +to reestblished dbus connection between dbus-daemon and the service. +Otherwise, there will be problem on the dbus connection. This patch fix this +problem by set JobType to JOB_RESTART when it is re-actived in signal_activation_request function. +--- + src/core/dbus.c | 10 +++++++++- + 1 file changed, 9 insertions(+), 1 deletion(-) + +diff --git a/src/core/dbus.c b/src/core/dbus.c +index 29524d4..38940ef 100644 +--- a/src/core/dbus.c ++++ b/src/core/dbus.c +@@ -152,6 +152,8 @@ static int signal_activation_request(sd_bus_message *message, void *userdata, sd + const char *name; + Unit *u; + int r; ++ int jobtype; ++ Service *s = NULL; + + assert(message); + +@@ -177,7 +179,13 @@ static int signal_activation_request(sd_bus_message *message, void *userdata, sd + goto failed; + } + +- r = manager_add_job(m, JOB_START, u, JOB_REPLACE, NULL, &error, NULL); ++ jobtype = JOB_START; ++ s = SERVICE(u); ++ if(s && s->state != SERVICE_DEAD) { ++ jobtype = JOB_RESTART; ++ log_unit_info(u, "Service '%s' will be restarted to activate the service. The current service state is %d.", u->id, s->state); ++ } ++ r = manager_add_job(m, jobtype, u, JOB_REPLACE, NULL, &error, NULL); + if (r < 0) + goto failed; + +-- +1.8.3.1
View file
_service:tar_scm:backport-Avoid-tmp-being-mounted-as-tmpfs-without-the-user-s-.patch
Added
@@ -0,0 +1,36 @@ +From f58c5ced373c2532b5cc44ba2e0c3a28b41472f2 Mon Sep 17 00:00:00 2001 +From: Jan Synacek <jsynacek@redhat.com> +Date: Tue, 15 May 2018 09:24:20 +0200 +Subject: PATCH Avoid /tmp being mounted as tmpfs without the user's + will + +Conflict:adapt context; modify unit_add_dependency_by_name para because of +35d8c19ace6; don't modify because we need tmp.mount to be started when +basic.target is started. +Reference:https://git.centos.org/rpms/systemd/blob/4b8c80a811af8258c136f5e7000fc0cd0adf8dc5/f/SOURCES/0004-Avoid-tmp-being-mounted-as-tmpfs-without-the-user-s-.patch + +Ensure PrivateTmp doesn't require tmpfs through tmp.mount, but rather +adds an After relationship. + +Resolves: #1578772 + +--- + src/core/unit.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/core/unit.c b/src/core/unit.c +index fd84818..e30c14b 100644 +--- a/src/core/unit.c ++++ b/src/core/unit.c +@@ -1271,7 +1271,7 @@ int unit_add_exec_dependencies(Unit *u, ExecContext *c) { + * tmp.mount so /tmp being masked is supported. However there's no reason to treat + * /tmp specifically and masking other mount units should be handled more + * gracefully too, see PR#16894. */ +- r = unit_add_two_dependencies_by_name(u, UNIT_AFTER, UNIT_WANTS, "tmp.mount", true, UNIT_DEPENDENCY_FILE); ++ r = unit_add_dependency_by_name(u, UNIT_AFTER, "tmp.mount", true, UNIT_DEPENDENCY_FILE); + if (r < 0) + return r; + +-- +2.23.0 +
View file
_service:tar_scm:backport-Revert-sysctl.d-switch-net.ipv4.conf.all.rp_filter-f.patch
Added
@@ -0,0 +1,35 @@ +From 47b256d63ac092137fe44e27560a14ee4aa5b7c8 Mon Sep 17 00:00:00 2001 +From: Lukas Nykryn <lnykryn@redhat.com> +Date: Fri, 8 Feb 2019 10:54:34 +0100 +Subject: Revert "sysctl.d: switch net.ipv4.conf.all.rp_filter + from 1 to 2" + +Conflict:according def94437934 and 5d4fc0e665a, modify default.rp_filter +and *.rp_filter +Reference:https://github.com/systemd/systemd/commit/230450d4e4f1f5fc9fa4295ed9185eea5b6ea16e + +This reverts commit 75c9af80cf3529c76988451e63f98010c86f48f1. + +Resolves: #1653824 +--- + sysctl.d/50-default.conf | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/sysctl.d/50-default.conf b/sysctl.d/50-default.conf +index 1b76b9d..2717a4d 100644 +--- a/sysctl.d/50-default.conf ++++ b/sysctl.d/50-default.conf +@@ -26,8 +26,8 @@ kernel.core_uses_pid = 1 + kernel.core_uses_pid = 1 + + # Source route verification +-net.ipv4.conf.default.rp_filter = 2 +-net.ipv4.conf.*.rp_filter = 2 ++net.ipv4.conf.default.rp_filter = 1 ++net.ipv4.conf.*.rp_filter = 1 + -net.ipv4.conf.all.rp_filter + + # Do not accept source routing +-- +2.23.0 +
View file
_service:tar_scm:backport-core-only-refuse-Type-dbus-service-enqueuing-if-dbus.patch
Added
@@ -0,0 +1,83 @@ +From bee6e755bb8e53a7a436e221b015ce0232ed87c0 Mon Sep 17 00:00:00 2001 +From: Mike Yuan <me@yhndnzj.com> +Date: Wed, 10 May 2023 13:54:15 +0800 +Subject: PATCH core: only refuse Type=dbus service enqueuing if dbus has + stop job + +Follow-up for #27579 + +In #27579 we refused all StartUnit requests for Type=dbus units +if dbus is not running, which means if dbus is manually stopped, +user can't use systemctl to start Type=dbus units again, which +is incorrect. + +The only culprit that leads to the cancellation of the whole +transaction mentioned in #26799 is job type conflict on dbus. +So let's relax the restriction and only refuse job enqueuing +if dbus has a stop job. + +To summarize, the case we want to avoid is: + +1. dbus has a stop job installed +2. StartUnit/ActivationRequest is received +3. Type=dbus service gets started, which has Requires=dbus.socket +4. dbus is pulled in again, resulting in job type conflict + +What we can support is: + +1. dbus is already stopped +2. StartUnit is received (possibly through systemctl, i.e. on private bus) +3. Type=dbus service gets started, which will wait for dbus to start +4. dbus is started again, thus the job for Type=dbus service + +Replaces #27590 +Fixes #27588 +--- + src/core/dbus-unit.c | 31 ++++++++++++++++++++++++------- + 1 file changed, 24 insertions(+), 7 deletions(-) + +diff --git a/src/core/dbus-unit.c b/src/core/dbus-unit.c +index 5b89c76586..59d541ebfe 100644 +--- a/src/core/dbus-unit.c ++++ b/src/core/dbus-unit.c +@@ -1875,13 +1875,30 @@ int bus_unit_queue_job( + (type == JOB_STOP && u->refuse_manual_stop) || + (IN_SET(type, JOB_RESTART, JOB_TRY_RESTART) && (u->refuse_manual_start || u->refuse_manual_stop)) || + (type == JOB_RELOAD_OR_START && job_type_collapse(type, u) == JOB_START && u->refuse_manual_start)) +- return sd_bus_error_setf(error, BUS_ERROR_ONLY_BY_DEPENDENCY, "Operation refused, unit %s may be requested by dependency only (it is configured to refuse manual start/stop).", u->id); +- +- /* dbus-broker issues StartUnit for activation requests, so let's apply the same check +- * used in signal_activation_request(). */ +- if (type == JOB_START && u->type == UNIT_SERVICE && +- SERVICE(u)->type == SERVICE_DBUS && !manager_dbus_is_running(u->manager)) +- return sd_bus_error_set(error, BUS_ERROR_SHUTTING_DOWN, "Refusing activation, D-Bus is not running."); ++ return sd_bus_error_setf(error, ++ BUS_ERROR_ONLY_BY_DEPENDENCY, ++ "Operation refused, unit %s may be requested by dependency only (it is configured to refuse manual start/stop).", ++ u->id); ++ ++ /* dbus-broker issues StartUnit for activation requests, and Type=dbus services automatically ++ * gain dependency on dbus.socket. Therefore, if dbus has a pending stop job, the new start ++ * job that pulls in dbus again would cause job type conflict. Let's avoid that by rejecting ++ * job enqueuing early. ++ * ++ * Note that unlike signal_activation_request(), we can't use unit_inactive_or_pending() ++ * here. StartUnit is a more generic interface, and thus users are allowed to use e.g. systemctl ++ * to start Type=dbus services even when dbus is inactive. */ ++ if (type == JOB_START && u->type == UNIT_SERVICE && SERVICE(u)->type == SERVICE_DBUS) ++ FOREACH_STRING(dbus_unit, SPECIAL_DBUS_SOCKET, SPECIAL_DBUS_SERVICE) { ++ Unit *dbus; ++ ++ dbus = manager_get_unit(u->manager, dbus_unit); ++ if (dbus && unit_stop_pending(dbus)) ++ return sd_bus_error_setf(error, ++ BUS_ERROR_SHUTTING_DOWN, ++ "Operation for unit %s refused, D-Bus is shutting down.", ++ u->id); ++ } + + r = sd_bus_message_new_method_return(message, &reply); + if (r < 0) +-- +2.33.0 +
View file
_service:tar_scm:backport-core-refuse-dbus-activation-if-dbus-is-not-running.patch
Added
@@ -0,0 +1,43 @@ +From 53964fd26b4a01191609ffc064aa8ccccd28e377 Mon Sep 17 00:00:00 2001 +From: Mike Yuan <me@yhndnzj.com> +Date: Tue, 9 May 2023 00:07:45 +0800 +Subject: PATCH core: refuse dbus activation if dbus is not running + +dbus-broker issues StartUnit directly for activation requests, +so let's add a check on bus state in bus_unit_queue_job to refuse +that if dbus is not running. + +Replaces #27570 +Closes #26799 +--- + src/core/dbus-unit.c | 7 +++++++ + 1 file changed, 7 insertions(+) + +diff --git a/src/core/dbus-unit.c b/src/core/dbus-unit.c +index c42ae5e..295e271 100644 +--- a/src/core/dbus-unit.c ++++ b/src/core/dbus-unit.c +@@ -21,6 +21,7 @@ + #include "path-util.h" + #include "process-util.h" + #include "selinux-access.h" ++#include "service.h" + #include "signal-util.h" + #include "special.h" + #include "string-table.h" +@@ -1880,6 +1881,12 @@ int bus_unit_queue_job( + (type == JOB_RELOAD_OR_START && job_type_collapse(type, u) == JOB_START && u->refuse_manual_start)) + return sd_bus_error_setf(error, BUS_ERROR_ONLY_BY_DEPENDENCY, "Operation refused, unit %s may be requested by dependency only (it is configured to refuse manual start/stop).", u->id); + ++ /* dbus-broker issues StartUnit for activation requests, so let's apply the same check ++ * used in signal_activation_request(). */ ++ if (type == JOB_START && u->type == UNIT_SERVICE && ++ SERVICE(u)->type == SERVICE_DBUS && !manager_dbus_is_running(u->manager)) ++ return sd_bus_error_set(error, BUS_ERROR_SHUTTING_DOWN, "Refusing activation, D-Bus is not running."); ++ + r = sd_bus_message_new_method_return(message, &reply); + if (r < 0) + return r; +-- +2.33.0 +
View file
_service:tar_scm:backport-sd-event-always-initialize-sd_event.perturb.patch
Added
@@ -0,0 +1,59 @@ +From f1a8b69808777aff37c036fd94a0275873d12407 Mon Sep 17 00:00:00 2001 +From: Yu Watanabe <watanabe.yu+github@gmail.com> +Date: Thu, 23 Feb 2023 07:31:01 +0900 +Subject: PATCH sd-event: always initialize sd_event.perturb + +If the boot ID cannot be obtained, let's first fallback to the machine +ID, and if still cannot, then let's use 0. +Otherwise, no timer event source cannot be triggered. + +Fixes #26549. + +(cherry picked from commit 6d2326e036ceed30f9ccdb0266713c10a44dcf6c) +(cherry picked from commit 58c821af607b61738b7b72ad1452e70f648689a6) +(cherry picked from commit 78976199b2e016600c3f7cf8f39747c9ef6c853b) +(cherry picked from commit ac04d804c30f519918866fb4eeb3bc4a9cbadd43) +--- + src/libsystemd/sd-event/sd-event.c | 21 ++++++++++----------- + 1 file changed, 10 insertions(+), 11 deletions(-) + +diff --git a/src/libsystemd/sd-event/sd-event.c b/src/libsystemd/sd-event/sd-event.c +index 89accdce00..37565b17be 100644 +--- a/src/libsystemd/sd-event/sd-event.c ++++ b/src/libsystemd/sd-event/sd-event.c +@@ -1126,22 +1126,21 @@ _public_ int sd_event_add_io( + } + + static void initialize_perturb(sd_event *e) { +- sd_id128_t bootid = {}; ++ sd_id128_t id = {}; + +- /* When we sleep for longer, we try to realign the wakeup to +- the same time within each minute/second/250ms, so that +- events all across the system can be coalesced into a single +- CPU wakeup. However, let's take some system-specific +- randomness for this value, so that in a network of systems +- with synced clocks timer events are distributed a +- bit. Here, we calculate a perturbation usec offset from the +- boot ID. */ ++ /* When we sleep for longer, we try to realign the wakeup to the same time within each ++ * minute/second/250ms, so that events all across the system can be coalesced into a single CPU ++ * wakeup. However, let's take some system-specific randomness for this value, so that in a network ++ * of systems with synced clocks timer events are distributed a bit. Here, we calculate a ++ * perturbation usec offset from the boot ID (or machine ID if failed, e.g. /proc is not mounted). */ + + if (_likely_(e->perturb != USEC_INFINITY)) + return; + +- if (sd_id128_get_boot(&bootid) >= 0) +- e->perturb = (bootid.qwords0 ^ bootid.qwords1) % USEC_PER_MINUTE; ++ if (sd_id128_get_boot(&id) >= 0 || sd_id128_get_machine(&id) > 0) ++ e->perturb = (id.qwords0 ^ id.qwords1) % USEC_PER_MINUTE; ++ else ++ e->perturb = 0; /* This is a super early process without /proc and /etc ?? */ + } + + static int event_setup_timer_fd( +-- +2.33.0 +
View file
_service:tar_scm:backport-sd-event-fix-error-handling.patch
Added
@@ -0,0 +1,31 @@ +From 056fbe84ef67168adcaf41baa37de1b712f6fb74 Mon Sep 17 00:00:00 2001 +From: Yu Watanabe <watanabe.yu+github@gmail.com> +Date: Thu, 23 Feb 2023 07:31:01 +0900 +Subject: PATCH sd-event: fix error handling + +Follow-up for 6d2326e036ceed30f9ccdb0266713c10a44dcf6c. + +(cherry picked from commit 1912f790fee9e0182acd77b77496f500094a140d) +(cherry picked from commit a719c2ec2f410f8b979cec04dcdac9af470ee52b) +(cherry picked from commit dd6561ff3e12314d41954b7ea8e3627101931a18) +(cherry picked from commit 8be4af42044969bc268b32ffe9570cee733fecf6) +--- + src/libsystemd/sd-event/sd-event.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/libsystemd/sd-event/sd-event.c b/src/libsystemd/sd-event/sd-event.c +index 37565b17be..df4d9037ac 100644 +--- a/src/libsystemd/sd-event/sd-event.c ++++ b/src/libsystemd/sd-event/sd-event.c +@@ -1137,7 +1137,7 @@ static void initialize_perturb(sd_event *e) { + if (_likely_(e->perturb != USEC_INFINITY)) + return; + +- if (sd_id128_get_boot(&id) >= 0 || sd_id128_get_machine(&id) > 0) ++ if (sd_id128_get_boot(&id) >= 0 || sd_id128_get_machine(&id) >= 0) + e->perturb = (id.qwords0 ^ id.qwords1) % USEC_PER_MINUTE; + else + e->perturb = 0; /* This is a super early process without /proc and /etc ?? */ +-- +2.33.0 +
View file
_service:tar_scm:backport-temporarily-disable-test-seccomp.patch
Added
@@ -0,0 +1,24 @@ +From 03a991c00674787d649240adda11f2506f2fcedc Mon Sep 17 00:00:00 2001 +From: xujing <xujing99@huawei.com> +Date: Tue, 22 Feb 2022 20:33:40 +0800 +Subject: PATCH temporarily disable test-seccomp + +--- + src/test/test-seccomp.c | 4 +++- + 1 file changed, 3 insertions(+), 1 deletion(-) + +diff --git a/src/test/test-seccomp.c b/src/test/test-seccomp.c +index 2d06098..a95deb8 100644 +--- a/src/test/test-seccomp.c ++++ b/src/test/test-seccomp.c +@@ -1199,4 +1199,6 @@ TEST(restrict_suid_sgid) { + assert_se(wait_for_terminate_and_check("suidsgidseccomp", pid, WAIT_LOG) == EXIT_SUCCESS); + } + +-DEFINE_TEST_MAIN(LOG_DEBUG); ++int main(int argc, char *argv) { ++ return 77; ++} +-- +2.33.0 +
View file
_service:tar_scm:bugfix-also-stop-machine-when-a-machine-un.patch
Added
@@ -0,0 +1,145 @@ +From 89110c823f246d3d2c398652999826107da446bf Mon Sep 17 00:00:00 2001 +From: yangbin <robin.yb@huawei.com> +Date: Tue, 7 Apr 2020 12:01:39 +0800 +Subject: PATCH systemd-machined: Also stop machine when a machine unit is + active but the leader process is exited + +When a VM machine is created in a scenario as below, it will remain in systemd-machined even though it has already been terminated by libvirtd. +1. libvirtd sends a request to systemd-machined with the leader(the PID of the vm) to create a machine. +2. systemd-machined directs the request to systemd +3. systemd constructs a scope and creates cgroup for the machine. the scope unit is then added to job queue and will be started later. +4. the leader process(the PID of the vm) is terminated by libvirtd(due some reason) before the scope is started. +5. Since the scope unit is yet not started, systemd will not destroy the scope althrough it is noticed with the signal event. +6. systemd starts the scope, and now the scope and machine is in active but no leader process exist. +7. systemd-machined will not stop and destroy the machine, and remains in system until the scope is stopped by others or the OS is restarted. + +This patch fix this problem by ansering yes to stop machine in machine_check_gc +when the machine unit is active but the leader process has already exited. + +Change-Id: I80e3c32832f4ecf08b6cb149735978730ce1d1c0 +--- + src/machine/machine.c | 37 ++++++++++++++++++++++++++++++++++++- + src/machine/machined-dbus.c | 35 +++++++++++++++++++++++++++++++++++ + src/machine/machined.h | 1 + + 3 files changed, 72 insertions(+), 1 deletion(-) + +diff --git a/src/machine/machine.c b/src/machine/machine.c +index c08a645..02fd9f7 100644 +--- a/src/machine/machine.c ++++ b/src/machine/machine.c +@@ -32,6 +32,7 @@ + #include "tmpfile-util.h" + #include "unit-name.h" + #include "user-util.h" ++#include "cgroup-util.h" + + DEFINE_TRIVIAL_CLEANUP_FUNC(Machine*, machine_free); + +@@ -520,6 +521,40 @@ int machine_finalize(Machine *m) { + return 0; + } + ++static bool machine_validate_unit(Machine *m) { ++ int r; ++ _cleanup_free_ char *unit = NULL; ++ _cleanup_free_ char *cgroup = NULL; ++ ++ r = cg_pid_get_unit(m->leader, &unit); ++ if (!r && streq(m->unit, unit)) ++ return true; ++ ++ if (r == -ESRCH) { ++ /* the original leader may exit and be replaced with a new leader when qemu hotreplace is performed. ++ * so we don't return true here, otherwise the vm will be added to the gc list. ++ * */ ++ log_info("Machine unit is in active, but the leader process is exited. " ++ "machine: %s, leader: "PID_FMT", unit: %s.", m->name, m->leader, m->unit); ++ } else if (r) { ++ log_info_errno(r, "Can not get unit from cgroup. " ++ "machine: %s, leader: "PID_FMT", unit: %s, error: %m", m->name, m->leader, m->unit); ++ } else if (unit && !streq(m->unit, unit)) { ++ log_info("Machine unit name not match. " ++ "machine: %s, leader: "PID_FMT", machine unit: %s, real unit: %s", m->name, m->leader, m->unit, unit); ++ } ++ ++ r = manager_get_unit_cgroup_path(m->manager, m->unit, &cgroup); ++ if (!r && !isempty(cgroup) && cg_is_empty_recursive(SYSTEMD_CGROUP_CONTROLLER, cgroup) > 0) { ++ log_info("Cgroup is empty in the machine unit. " ++ "machine: %s, leader: "PID_FMT", machine unit: %s.", m->name, m->leader, m->unit); ++ /*The vm will be added to gc list only when there is no any process in the scope*/ ++ return false; ++ } ++ ++ return true; ++} ++ + bool machine_may_gc(Machine *m, bool drop_not_started) { + assert(m); + +@@ -532,7 +567,7 @@ bool machine_may_gc(Machine *m, bool drop_not_started) { + if (m->scope_job && manager_job_is_active(m->manager, m->scope_job)) + return false; + +- if (m->unit && manager_unit_is_active(m->manager, m->unit)) ++ if (m->unit && manager_unit_is_active(m->manager, m->unit) && machine_validate_unit(m)) + return false; + + return true; +diff --git a/src/machine/machined-dbus.c b/src/machine/machined-dbus.c +index 0c157a9..10d370f 100644 +--- a/src/machine/machined-dbus.c ++++ b/src/machine/machined-dbus.c +@@ -1509,3 +1509,38 @@ int manager_add_machine(Manager *m, const char *name, Machine **_machine) { + + return 0; + } ++ ++int manager_get_unit_cgroup_path(Manager *manager, const char *unit, char **cgroup) { ++ _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; ++ _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; ++ _cleanup_free_ char *path = NULL; ++ const char *cgroup_path = NULL; ++ int r; ++ ++ assert(manager); ++ assert(unit); ++ ++ path = unit_dbus_path_from_name(unit); ++ if (!path) ++ return -ENOMEM; ++ ++ r = sd_bus_get_property( ++ manager->bus, ++ "org.freedesktop.systemd1", ++ path, ++ endswith(unit, ".scope") ? "org.freedesktop.systemd1.Scope" : "org.freedesktop.systemd1.Service", ++ "ControlGroup", ++ &error, ++ &reply, ++ "s"); ++ if (r < 0) { ++ return r; ++ } ++ ++ r = sd_bus_message_read(reply, "s", &cgroup_path); ++ if (r < 0) ++ return -EINVAL; ++ *cgroup = strdup(cgroup_path); ++ ++ return 0; ++} +diff --git a/src/machine/machined.h b/src/machine/machined.h +index 280c32b..6b8d98b 100644 +--- a/src/machine/machined.h ++++ b/src/machine/machined.h +@@ -58,6 +58,7 @@ int manager_kill_unit(Manager *manager, const char *unit, int signo, sd_bus_erro + int manager_unref_unit(Manager *m, const char *unit, sd_bus_error *error); + int manager_unit_is_active(Manager *manager, const char *unit); + int manager_job_is_active(Manager *manager, const char *path); ++int manager_get_unit_cgroup_path(Manager *manager, const char *unit, char **cgroup); + + #if ENABLE_NSCD + int manager_enqueue_nscd_cache_flush(Manager *m); +-- +2.33.0 +
View file
_service:tar_scm:bugfix-for-cgroup-Swap-cgroup-v1-deletion-and-migration.patch
Added
@@ -0,0 +1,40 @@ +From c003873099e47dccf2e57816291bd6b7de4a5790 Mon Sep 17 00:00:00 2001 +From: jiangchuangang <jiangchuangang@huawei.com> +Date: Wed, 13 Jul 2022 21:39:06 +0800 +Subject: PATCH bugfix for cpuset and Delegate + +--- + src/core/cgroup.c | 10 +++++++--- + 1 file changed, 7 insertions(+), 3 deletions(-) + +diff --git a/src/core/cgroup.c b/src/core/cgroup.c +index 0e4c94d..e887d49 100644 +--- a/src/core/cgroup.c ++++ b/src/core/cgroup.c +@@ -1963,6 +1963,8 @@ static int unit_update_cgroup( + u->cgroup_enabled_mask = result_mask; + + migrate_mask = u->cgroup_realized_mask ^ target_mask; ++ if (u->type != UNIT_SLICE && FLAGS_SET(target_mask, CGROUP_MASK_CPUSET)) ++ migrate_mask |= CGROUP_MASK_CPUSET; + } + + /* Keep track that this is now realized */ +@@ -1977,9 +1979,11 @@ static int unit_update_cgroup( + * delegated units. + */ + if (cg_all_unified() == 0) { +- r = cg_migrate_v1_controllers(u->manager->cgroup_supported, migrate_mask, u->cgroup_path, migrate_callback, u); +- if (r < 0) +- log_unit_warning_errno(u, r, "Failed to migrate controller cgroups from %s, ignoring: %m", empty_to_root(u->cgroup_path)); ++ if (!unit_cgroup_delegate(u)) { ++ r = cg_migrate_v1_controllers(u->manager->cgroup_supported, migrate_mask, u->cgroup_path, migrate_callback, u); ++ if (r < 0) ++ log_unit_warning_errno(u, r, "Failed to migrate controller cgroups from %s, ignoring: %m", empty_to_root(u->cgroup_path)); ++ } + + is_root_slice = unit_has_name(u, SPECIAL_ROOT_SLICE); + r = cg_trim_v1_controllers(u->manager->cgroup_supported, ~target_mask, u->cgroup_path, !is_root_slice); +-- +2.33.0 +
View file
_service:tar_scm:change-NTP-server-to-x.pool.ntp.org.patch
Added
@@ -0,0 +1,25 @@ +From bdf0536bace233a0da7e1ff094c8cb81ded18c38 Mon Sep 17 00:00:00 2001 +From: licunlong <licunlong1@huawei.com> +Date: Tue, 23 Feb 2021 15:07:17 +0800 +Subject: PATCH change NTP server to x.pool.ntp.org + +--- + meson_options.txt | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/meson_options.txt b/meson_options.txt +index 163c8df..ba7adf9 100644 +--- a/meson_options.txt ++++ b/meson_options.txt +@@ -312,7 +312,7 @@ option('dns-servers', type : 'string', + value : '1.1.1.1#cloudflare-dns.com 8.8.8.8#dns.google 1.0.0.1#cloudflare-dns.com 8.8.4.4#dns.google 2606:4700:4700::1111#cloudflare-dns.com 2001:4860:4860::8888#dns.google 2606:4700:4700::1001#cloudflare-dns.com 2001:4860:4860::8844#dns.google') + option('ntp-servers', type : 'string', + description : 'space-separated list of default NTP servers', +- value : 'time1.google.com time2.google.com time3.google.com time4.google.com') ++ value : '0.pool.ntp.org 1.pool.ntp.org 2.pool.ntp.org 3.pool.ntp.org') + option('support-url', type : 'string', + description : 'the support URL to show in catalog entries included in systemd', + value : 'https://lists.freedesktop.org/mailman/listinfo/systemd-devel') +-- +2.27.0 +
View file
_service:tar_scm:check-whether-command_prev-is-null-before-assigning-.patch
Added
@@ -0,0 +1,35 @@ +From 5fe226b4378a2466d906ae45b8544f1003e9885a Mon Sep 17 00:00:00 2001 +From: yefei25 <yefei25@huawei.com> +Date: Wed, 8 Apr 2020 23:10:58 -0400 +Subject: PATCH 1/2 check whether command_prev is null before assigning value + +--- + src/core/service.c | 8 ++++++-- + 1 file changed, 6 insertions(+), 2 deletions(-) + +diff --git a/src/core/service.c b/src/core/service.c +index 9a26271f72..3c255b3bcc 100644 +--- a/src/core/service.c ++++ b/src/core/service.c +@@ -2569,12 +2569,16 @@ static unsigned service_exec_command_index(Unit *u, ServiceExecCommand id, ExecC + assert(s); + assert(id >= 0); + assert(id < _SERVICE_EXEC_COMMAND_MAX); +- ++ if (!current) ++ return 0; + const ExecCommand *first = s->exec_commandid; + + /* Figure out where we are in the list by walking back to the beginning */ +- for (const ExecCommand *c = current; c != first; c = c->command_prev) ++ for (const ExecCommand *c = current; c != first; c = c->command_prev) { + idx++; ++ if (!c->command_prev) ++ return idx; ++ } + + return idx; + } +-- +2.19.1 +
View file
_service:tar_scm:core-add-OptionalLog-to-allow-users-change-log-level.patch
Added
@@ -0,0 +1,144 @@ +From 637310cf1903f9072a391074a65855fc1c41ae2b Mon Sep 17 00:00:00 2001 +From: licunlong <licunlong1@huawei.com> +Date: Fri, 15 Apr 2022 09:28:15 +0800 +Subject: PATCH core: add OptionalLog to allow users change log level. +This adds log_optional* log_unit_optional* to log messages in LOG_INFO +or LOG_DEBUG. Set "OptionalLog=yes" to log in LOG_INFO. Defaults to no. + +--- + src/basic/log.h | 2 ++ + src/core/dbus-manager.c | 1 + + src/core/main.c | 4 ++++ + src/core/manager.h | 1 + + src/core/mount.c | 2 +- + src/core/system.conf.in | 1 + + src/core/unit.h | 2 ++ + 7 files changed, 12 insertions(+), 1 deletion(-) + +diff --git a/src/basic/log.h b/src/basic/log.h +index f73d4c4..d341681 100644 +--- a/src/basic/log.h ++++ b/src/basic/log.h +@@ -243,6 +243,7 @@ int log_emergency_level(void); + #define log_warning(...) log_full(LOG_WARNING, __VA_ARGS__) + #define log_error(...) log_full(LOG_ERR, __VA_ARGS__) + #define log_emergency(...) log_full(log_emergency_level(), __VA_ARGS__) ++#define log_optional(use_info, ...) log_full(((use_info) ? LOG_INFO : LOG_DEBUG), __VA_ARGS__) + + /* Logging triggered by an errno-like error */ + #define log_debug_errno(error, ...) log_full_errno(LOG_DEBUG, error, __VA_ARGS__) +@@ -251,6 +252,7 @@ int log_emergency_level(void); + #define log_warning_errno(error, ...) log_full_errno(LOG_WARNING, error, __VA_ARGS__) + #define log_error_errno(error, ...) log_full_errno(LOG_ERR, error, __VA_ARGS__) + #define log_emergency_errno(error, ...) log_full_errno(log_emergency_level(), error, __VA_ARGS__) ++#define log_optional_errno(error, use_info, ...) log_full_errno(((use_info) ? LOG_INFO : LOG_DEBUG), error, __VA_ARGS__) + + /* This logs at the specified level the first time it is called, and then + * logs at debug. If the specified level is debug, this logs only the first +diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c +index 7e57a32..9ca392b 100644 +--- a/src/core/dbus-manager.c ++++ b/src/core/dbus-manager.c +@@ -2870,6 +2870,7 @@ const sd_bus_vtable bus_manager_vtable = { + BUS_PROPERTY_DUAL_TIMESTAMP("InitRDUnitsLoadFinishTimestamp", offsetof(Manager, timestampsMANAGER_TIMESTAMP_INITRD_UNITS_LOAD_FINISH), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_WRITABLE_PROPERTY("LogLevel", "s", bus_property_get_log_level, property_set_log_level, 0, 0), + SD_BUS_WRITABLE_PROPERTY("LogTarget", "s", bus_property_get_log_target, property_set_log_target, 0, 0), ++ SD_BUS_PROPERTY("OptionalLog", "b", bus_property_get_bool, offsetof(Manager, optional_log), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("NNames", "u", property_get_hashmap_size, offsetof(Manager, units), 0), + SD_BUS_PROPERTY("NFailedUnits", "u", property_get_set_size, offsetof(Manager, failed_units), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), + SD_BUS_PROPERTY("NJobs", "u", property_get_hashmap_size, offsetof(Manager, jobs), 0), +diff --git a/src/core/main.c b/src/core/main.c +index eaae658..809ed76 100644 +--- a/src/core/main.c ++++ b/src/core/main.c +@@ -119,6 +119,7 @@ static const char *arg_bus_introspect = NULL; + * defaults are assigned in reset_arguments() below. */ + static char *arg_default_unit; + static bool arg_system; ++static bool arg_optional_log; + bool arg_dump_core; + int arg_crash_chvt; + bool arg_crash_shell; +@@ -626,6 +627,7 @@ static int parse_config_file(void) { + { "Manager", "LogColor", config_parse_color, 0, NULL }, + { "Manager", "LogLocation", config_parse_location, 0, NULL }, + { "Manager", "LogTime", config_parse_time, 0, NULL }, ++ { "Manager", "OptionalLog", config_parse_bool, 0, &arg_optional_log }, + { "Manager", "DumpCore", config_parse_bool, 0, &arg_dump_core }, + { "Manager", "CrashChVT", /* legacy */ config_parse_crash_chvt, 0, &arg_crash_chvt }, + { "Manager", "CrashChangeVT", config_parse_crash_chvt, 0, &arg_crash_chvt }, +@@ -745,6 +747,7 @@ static void set_manager_defaults(Manager *m) { + * affect the manager itself, but are just what newly allocated units will have set if they haven't set + * anything else. (Also see set_manager_settings() for the settings that affect the manager's own behaviour) */ + ++ m->optional_log = arg_optional_log; + m->default_timer_accuracy_usec = arg_default_timer_accuracy_usec; + m->default_std_output = arg_default_std_output; + m->default_std_error = arg_default_std_error; +@@ -2423,6 +2426,7 @@ static void reset_arguments(void) { + + /* arg_system — ignore */ + ++ arg_optional_log = false; + arg_dump_core = true; + arg_crash_chvt = -1; + arg_crash_shell = false; +diff --git a/src/core/manager.h b/src/core/manager.h +index d3f6aa2..814421f 100644 +--- a/src/core/manager.h ++++ b/src/core/manager.h +@@ -385,6 +385,7 @@ struct Manager { + LogTarget original_log_target; + bool log_level_overridden; + bool log_target_overridden; ++ bool optional_log; + + struct rlimit *rlimit_RLIMIT_MAX; + +diff --git a/src/core/mount.c b/src/core/mount.c +index af0eae6..3751cb4 100644 +--- a/src/core/mount.c ++++ b/src/core/mount.c +@@ -756,7 +756,7 @@ static void mount_set_state(Mount *m, MountState state) { + } + + if (state != old_state) +- log_unit_debug(UNIT(m), "Changed %s -> %s", mount_state_to_string(old_state), mount_state_to_string(state)); ++ log_unit_optional(UNIT(m), UNIT(m)->manager->optional_log, "Changed %s -> %s", mount_state_to_string(old_state), mount_state_to_string(state)); + + unit_notify(UNIT(m), state_translation_tableold_state, state_translation_tablestate, + m->reload_result == MOUNT_SUCCESS ? 0 : UNIT_NOTIFY_RELOAD_FAILURE); +diff --git a/src/core/system.conf.in b/src/core/system.conf.in +index 066a9a7..564d146 100644 +--- a/src/core/system.conf.in ++++ b/src/core/system.conf.in +@@ -20,6 +20,7 @@ + #LogColor=yes + #LogLocation=no + #LogTime=no ++#OptionalLog=no + #DumpCore=yes + #ShowStatus=yes + #CrashChangeVT=no +diff --git a/src/core/unit.h b/src/core/unit.h +index 58417eb..cc65d93 100644 +--- a/src/core/unit.h ++++ b/src/core/unit.h +@@ -1097,12 +1097,14 @@ Condition *unit_find_failed_condition(Unit *u); + #define log_unit_notice(unit, ...) log_unit_full(unit, LOG_NOTICE, __VA_ARGS__) + #define log_unit_warning(unit, ...) log_unit_full(unit, LOG_WARNING, __VA_ARGS__) + #define log_unit_error(unit, ...) log_unit_full(unit, LOG_ERR, __VA_ARGS__) ++#define log_unit_optional(unit, use_info, ...) log_unit_full(unit, ((use_info) ? LOG_INFO : LOG_DEBUG), __VA_ARGS__) + + #define log_unit_debug_errno(unit, error, ...) log_unit_full_errno(unit, LOG_DEBUG, error, __VA_ARGS__) + #define log_unit_info_errno(unit, error, ...) log_unit_full_errno(unit, LOG_INFO, error, __VA_ARGS__) + #define log_unit_notice_errno(unit, error, ...) log_unit_full_errno(unit, LOG_NOTICE, error, __VA_ARGS__) + #define log_unit_warning_errno(unit, error, ...) log_unit_full_errno(unit, LOG_WARNING, error, __VA_ARGS__) + #define log_unit_error_errno(unit, error, ...) log_unit_full_errno(unit, LOG_ERR, error, __VA_ARGS__) ++#define log_unit_optional_errno(unit, use_info, error, ...) log_unit_full_errno(unit, ((use_info) ? LOG_INFO : LOG_DEBUG), error, __VA_ARGS__) + + #if LOG_TRACE + # define log_unit_trace(...) log_unit_debug(__VA_ARGS__) +-- +2.33.0 +
View file
_service:tar_scm:core-add-invalidate-cgroup-config.patch
Added
@@ -0,0 +1,118 @@ +From d56b3978bbcd28246b3e3ce3f8c958ac95785dd7 Mon Sep 17 00:00:00 2001 +From: fangxiuning <fangxiuning@huawei.com> +Date: Wed, 22 Apr 2020 11:55:18 +0800 +Subject: + After systemd 239 version, a new feature is added to cgroups. +The processes started by users default to the cgroup group belonging +to user.slice, and the processes started by the system default to +system.slice. This is the direction of github systemd evolution. +However, there are still a large number of operations downstream +that systemd does not perceive to modify the cgroup group, +such as directly echo the process number to system.slice. + +For example: +1. sleep 1000 & +2. echo sleep pid > /sys/fs/cgroup/memory/system.slice/task +3. systemctl daemon-reload +4. cat /proc/sleep pid/cgroup +this kind of operation, systemd is not aware of it. +When systemctl disable service or systemctl daemon-reload operation +is executed, systemd will re-attach each process to its original +Under the group(user.slice). + +--- + src/core/main.c | 4 ++++ + src/core/manager.c | 1 + + src/core/manager.h | 1 + + src/core/system.conf.in | 1 + + src/core/unit-serialize.c | 2 +- + 5 files changed, 8 insertions(+), 1 deletion(-) + +diff --git a/src/core/main.c b/src/core/main.c +index 500691a..c6638a0 100644 +--- a/src/core/main.c ++++ b/src/core/main.c +@@ -166,6 +166,7 @@ static bool arg_default_cpuset_accounting; + static bool arg_default_freezer_accounting; + static bool arg_default_tasks_accounting; + static TasksMax arg_default_tasks_max; ++static bool arg_default_invalidate_cgroup; + static sd_id128_t arg_machine_id; + static EmergencyAction arg_cad_burst_action; + static OOMPolicy arg_default_oom_policy; +@@ -692,6 +693,7 @@ static int parse_config_file(void) { + { "Manager", "DefaultFreezerAccounting", config_parse_bool, 0, &arg_default_freezer_accounting }, + { "Manager", "DefaultTasksAccounting", config_parse_bool, 0, &arg_default_tasks_accounting }, + { "Manager", "DefaultTasksMax", config_parse_tasks_max, 0, &arg_default_tasks_max }, ++ { "Manager", "DefaultInvalidateCgroup", config_parse_bool, 0, &arg_default_invalidate_cgroup }, + { "Manager", "CtrlAltDelBurstAction", config_parse_emergency_action, arg_system, &arg_cad_burst_action }, + { "Manager", "DefaultOOMPolicy", config_parse_oom_policy, 0, &arg_default_oom_policy }, + { "Manager", "DefaultOOMScoreAdjust", config_parse_oom_score_adjust, 0, NULL }, +@@ -778,6 +780,7 @@ static void set_manager_defaults(Manager *m) { + m->default_freezer_accounting = arg_default_freezer_accounting; + m->default_tasks_accounting = arg_default_tasks_accounting; + m->default_tasks_max = arg_default_tasks_max; ++ m->default_invalidate_cgroup = arg_default_invalidate_cgroup; + m->default_oom_policy = arg_default_oom_policy; + m->default_oom_score_adjust_set = arg_default_oom_score_adjust_set; + m->default_oom_score_adjust = arg_default_oom_score_adjust; +@@ -2500,6 +2503,7 @@ static void reset_arguments(void) { + arg_default_freezer_accounting = false; + arg_default_tasks_accounting = true; + arg_default_tasks_max = DEFAULT_TASKS_MAX; ++ arg_default_invalidate_cgroup = true; + arg_machine_id = (sd_id128_t) {}; + arg_cad_burst_action = EMERGENCY_ACTION_REBOOT_FORCE; + arg_default_oom_policy = OOM_STOP; +diff --git a/src/core/manager.c b/src/core/manager.c +index 4fa20f8..1a5dcd8 100644 +--- a/src/core/manager.c ++++ b/src/core/manager.c +@@ -837,6 +837,7 @@ int manager_new(LookupScope scope, ManagerTestRunFlags test_run_flags, Manager * + .default_cpuset_accounting = false, + .default_tasks_accounting = true, + .default_tasks_max = TASKS_MAX_UNSET, ++ .default_invalidate_cgroup = true, + .default_timeout_start_usec = manager_default_timeout(scope == LOOKUP_SCOPE_SYSTEM), + .default_timeout_stop_usec = manager_default_timeout(scope == LOOKUP_SCOPE_SYSTEM), + .default_restart_usec = DEFAULT_RESTART_USEC, +diff --git a/src/core/manager.h b/src/core/manager.h +index 9e391b1..ea95efe 100644 +--- a/src/core/manager.h ++++ b/src/core/manager.h +@@ -377,6 +377,7 @@ struct Manager { + + TasksMax default_tasks_max; + usec_t default_timer_accuracy_usec; ++ bool default_invalidate_cgroup; + + OOMPolicy default_oom_policy; + int default_oom_score_adjust; +diff --git a/src/core/system.conf.in b/src/core/system.conf.in +index 564d146..11936cd 100644 +--- a/src/core/system.conf.in ++++ b/src/core/system.conf.in +@@ -76,6 +76,7 @@ DefaultLimitMEMLOCK=64M + #DefaultLimitNICE= + #DefaultLimitRTPRIO= + #DefaultLimitRTTIME= ++#DefaultInvalidateCgroup=yes + #DefaultOOMPolicy=stop + DefaultDFXReboot=yes + #DefaultSmackProcessLabel= +diff --git a/src/core/unit-serialize.c b/src/core/unit-serialize.c +index 21457dc..0398ec8 100644 +--- a/src/core/unit-serialize.c ++++ b/src/core/unit-serialize.c +@@ -548,7 +548,7 @@ int unit_deserialize(Unit *u, FILE *f, FDSet *fds) { + /* Let's make sure that everything that is deserialized also gets any potential new cgroup settings + * applied after we are done. For that we invalidate anything already realized, so that we can + * realize it again. */ +- if (u->cgroup_realized) { ++ if (u->cgroup_realized && u->manager->default_invalidate_cgroup) { + unit_invalidate_cgroup(u, _CGROUP_MASK_ALL); + unit_invalidate_cgroup_bpf(u); + } +-- +2.33.0 +
View file
_service:tar_scm:core-cgroup-support-cpuset.patch
Added
@@ -0,0 +1,845 @@ +From 2ea8175b3d8ec118fa0f42392485ce0f4308456a Mon Sep 17 00:00:00 2001 +From: licunlong <licunlong1@huawei.com> +Date: Thu, 6 May 2021 09:38:54 +0800 +Subject: PATCH core-cgroup: support cpuset + +This patch add support for cpuset subsystem. +--- + src/basic/cgroup-util.c | 3 +- + src/basic/cgroup-util.h | 10 +- + src/basic/string-util.c | 42 +++++++ + src/basic/string-util.h | 1 + + src/core/cgroup.c | 112 ++++++++++++++---- + src/core/cgroup.h | 14 ++- + src/core/dbus-cgroup.c | 60 ++++++++-- + src/core/dbus-manager.c | 1 + + src/core/load-fragment-gperf.gperf.in | 13 +- + src/core/load-fragment.c | 69 +++++++++++ + src/core/load-fragment.h | 1 + + src/core/main.c | 4 + + src/core/manager.c | 1 + + src/core/manager.h | 1 + + src/core/system.conf.in | 1 + + src/core/unit.c | 1 + + src/shared/bus-unit-util.c | 15 ++- + src/shared/cpu-set-util.c | 1 + + src/test/test-cgroup-mask.c | 5 +- + .../fuzz-unit-file/directives-all.service | 5 + + 20 files changed, 309 insertions(+), 51 deletions(-) + +diff --git a/src/basic/cgroup-util.c b/src/basic/cgroup-util.c +index feda596..1bb07f7 100644 +--- a/src/basic/cgroup-util.c ++++ b/src/basic/cgroup-util.c +@@ -2248,12 +2248,13 @@ bool fd_is_cgroup_fs(int fd) { + static const char *const cgroup_controller_table_CGROUP_CONTROLLER_MAX = { + CGROUP_CONTROLLER_CPU = "cpu", + CGROUP_CONTROLLER_CPUACCT = "cpuacct", +- CGROUP_CONTROLLER_CPUSET = "cpuset", ++ CGROUP_CONTROLLER_CPUSET2 = "cpuset2", + CGROUP_CONTROLLER_IO = "io", + CGROUP_CONTROLLER_BLKIO = "blkio", + CGROUP_CONTROLLER_MEMORY = "memory", + CGROUP_CONTROLLER_DEVICES = "devices", + CGROUP_CONTROLLER_PIDS = "pids", ++ CGROUP_CONTROLLER_CPUSET = "cpuset", + CGROUP_CONTROLLER_BPF_FIREWALL = "bpf-firewall", + CGROUP_CONTROLLER_BPF_DEVICES = "bpf-devices", + CGROUP_CONTROLLER_BPF_FOREIGN = "bpf-foreign", +diff --git a/src/basic/cgroup-util.h b/src/basic/cgroup-util.h +index b69f168..764d47a 100644 +--- a/src/basic/cgroup-util.h ++++ b/src/basic/cgroup-util.h +@@ -21,12 +21,13 @@ typedef enum CGroupController { + /* Original cgroup controllers */ + CGROUP_CONTROLLER_CPU, + CGROUP_CONTROLLER_CPUACCT, /* v1 only */ +- CGROUP_CONTROLLER_CPUSET, /* v2 only */ ++ CGROUP_CONTROLLER_CPUSET2, /* v2 only */ + CGROUP_CONTROLLER_IO, /* v2 only */ + CGROUP_CONTROLLER_BLKIO, /* v1 only */ + CGROUP_CONTROLLER_MEMORY, + CGROUP_CONTROLLER_DEVICES, /* v1 only */ + CGROUP_CONTROLLER_PIDS, ++ CGROUP_CONTROLLER_CPUSET, + + /* BPF-based pseudo-controllers, v2 only */ + CGROUP_CONTROLLER_BPF_FIREWALL, +@@ -48,12 +49,13 @@ typedef enum CGroupController { + typedef enum CGroupMask { + CGROUP_MASK_CPU = CGROUP_CONTROLLER_TO_MASK(CGROUP_CONTROLLER_CPU), + CGROUP_MASK_CPUACCT = CGROUP_CONTROLLER_TO_MASK(CGROUP_CONTROLLER_CPUACCT), +- CGROUP_MASK_CPUSET = CGROUP_CONTROLLER_TO_MASK(CGROUP_CONTROLLER_CPUSET), ++ CGROUP_MASK_CPUSET2 = CGROUP_CONTROLLER_TO_MASK(CGROUP_CONTROLLER_CPUSET2), + CGROUP_MASK_IO = CGROUP_CONTROLLER_TO_MASK(CGROUP_CONTROLLER_IO), + CGROUP_MASK_BLKIO = CGROUP_CONTROLLER_TO_MASK(CGROUP_CONTROLLER_BLKIO), + CGROUP_MASK_MEMORY = CGROUP_CONTROLLER_TO_MASK(CGROUP_CONTROLLER_MEMORY), + CGROUP_MASK_DEVICES = CGROUP_CONTROLLER_TO_MASK(CGROUP_CONTROLLER_DEVICES), + CGROUP_MASK_PIDS = CGROUP_CONTROLLER_TO_MASK(CGROUP_CONTROLLER_PIDS), ++ CGROUP_MASK_CPUSET = CGROUP_CONTROLLER_TO_MASK(CGROUP_CONTROLLER_CPUSET), + CGROUP_MASK_BPF_FIREWALL = CGROUP_CONTROLLER_TO_MASK(CGROUP_CONTROLLER_BPF_FIREWALL), + CGROUP_MASK_BPF_DEVICES = CGROUP_CONTROLLER_TO_MASK(CGROUP_CONTROLLER_BPF_DEVICES), + CGROUP_MASK_BPF_FOREIGN = CGROUP_CONTROLLER_TO_MASK(CGROUP_CONTROLLER_BPF_FOREIGN), +@@ -61,10 +63,10 @@ typedef enum CGroupMask { + CGROUP_MASK_BPF_RESTRICT_NETWORK_INTERFACES = CGROUP_CONTROLLER_TO_MASK(CGROUP_CONTROLLER_BPF_RESTRICT_NETWORK_INTERFACES), + + /* All real cgroup v1 controllers */ +- CGROUP_MASK_V1 = CGROUP_MASK_CPU|CGROUP_MASK_CPUACCT|CGROUP_MASK_BLKIO|CGROUP_MASK_MEMORY|CGROUP_MASK_DEVICES|CGROUP_MASK_PIDS, ++ CGROUP_MASK_V1 = CGROUP_MASK_CPU|CGROUP_MASK_CPUACCT|CGROUP_MASK_BLKIO|CGROUP_MASK_MEMORY|CGROUP_MASK_CPUSET|CGROUP_MASK_DEVICES|CGROUP_MASK_PIDS, + + /* All real cgroup v2 controllers */ +- CGROUP_MASK_V2 = CGROUP_MASK_CPU|CGROUP_MASK_CPUSET|CGROUP_MASK_IO|CGROUP_MASK_MEMORY|CGROUP_MASK_PIDS, ++ CGROUP_MASK_V2 = CGROUP_MASK_CPU|CGROUP_MASK_CPUSET2|CGROUP_MASK_IO|CGROUP_MASK_MEMORY|CGROUP_MASK_PIDS, + + /* All cgroup v2 BPF pseudo-controllers */ + CGROUP_MASK_BPF = CGROUP_MASK_BPF_FIREWALL|CGROUP_MASK_BPF_DEVICES|CGROUP_MASK_BPF_FOREIGN|CGROUP_MASK_BPF_SOCKET_BIND|CGROUP_MASK_BPF_RESTRICT_NETWORK_INTERFACES, +diff --git a/src/basic/string-util.c b/src/basic/string-util.c +index ad8c986..755ad11 100644 +--- a/src/basic/string-util.c ++++ b/src/basic/string-util.c +@@ -1159,6 +1159,48 @@ int string_contains_word_strv(const char *string, const char *separators, char * + return !!found; + } + ++int string_isvalid_interval(const char *instr) ++{ ++ const char *pstr = instr; /* tmp */ ++ const char *pstr_front = instr; /* front char */ ++ const char *pstr_behind = instr; /* behind char */ ++ ++ if (isempty(instr)) ++ { ++ return 1; ++ } ++ ++ while (*pstr != '\0') ++ { ++ /* behind */ ++ pstr_behind = pstr + 1; ++ ++ /* 0-3,4,6,7-10 */ ++ if (((*pstr < '0') || (*pstr > '9')) && ++ (*pstr != '-') && ++ (*pstr != ',')) ++ { ++ return 2; ++ } ++ ++ /* - , must is a num */ ++ if (('-' == *pstr) || (',' == *pstr)) ++ { ++ if ((*pstr_front < '0') || (*pstr_front > '9') || ++ (*pstr_behind < '0') || (*pstr_behind > '9')) ++ { ++ return 3; ++ } ++ } ++ ++ /* front */ ++ pstr_front = pstr; ++ pstr++; ++ } ++ ++ return 0; ++} ++ + bool streq_skip_trailing_chars(const char *s1, const char *s2, const char *ok) { + if (!s1 && !s2) + return true; +diff --git a/src/basic/string-util.h b/src/basic/string-util.h +index e0a47a2..b025c06 100644 +--- a/src/basic/string-util.h ++++ b/src/basic/string-util.h +@@ -235,6 +235,7 @@ static inline int string_contains_word(const char *string, const char *separator + return string_contains_word_strv(string, separators, STRV_MAKE(word), NULL); + } + ++int string_isvalid_interval(const char *instr); + bool streq_skip_trailing_chars(const char *s1, const char *s2, const char *ok); + + char *string_replace_char(char *str, char old_char, char new_char); +diff --git a/src/core/cgroup.c b/src/core/cgroup.c +index f6ae2ab..a6396e1 100644 +--- a/src/core/cgroup.c ++++ b/src/core/cgroup.c +@@ -90,8 +90,8 @@ bool unit_has_startup_cgroup_constraints(Unit *u) { + return c->startup_cpu_shares != CGROUP_CPU_SHARES_INVALID || + c->startup_io_weight != CGROUP_WEIGHT_INVALID || + c->startup_blockio_weight != CGROUP_BLKIO_WEIGHT_INVALID || +- c->startup_cpuset_cpus.set || +- c->startup_cpuset_mems.set; ++ c->startup_cpuset_cpus2.set || ++ c->startup_cpuset_mems2.set; + } + + bool unit_has_host_root_cgroup(Unit *u) { +@@ -277,10 +277,16 @@ void cgroup_context_done(CGroupContext *c) { + + c->restrict_network_interfaces = set_free(c->restrict_network_interfaces); + +- cpu_set_reset(&c->cpuset_cpus); +- cpu_set_reset(&c->startup_cpuset_cpus); +- cpu_set_reset(&c->cpuset_mems); +- cpu_set_reset(&c->startup_cpuset_mems); ++ if (c->cpuset_cpus) ++ c->cpuset_cpus = mfree(c->cpuset_cpus); ++ ++ if (c->cpuset_mems) ++ c->cpuset_mems = mfree(c->cpuset_mems); ++ ++ cpu_set_reset(&c->cpuset_cpus2); ++ cpu_set_reset(&c->startup_cpuset_cpus2); ++ cpu_set_reset(&c->cpuset_mems2); ++ cpu_set_reset(&c->startup_cpuset_mems2); + } + + static int unit_get_kernel_memory_limit(Unit *u, const char *file, uint64_t *ret) { +@@ -415,7 +421,7 @@ static char *format_cgroup_memory_limit_comparison(char *buf, size_t l, Unit *u, + } + + void cgroup_context_dump(Unit *u, FILE* f, const char *prefix) { +- _cleanup_free_ char *disable_controllers_str = NULL, *cpuset_cpus = NULL, *cpuset_mems = NULL, *startup_cpuset_cpus = NULL, *startup_cpuset_mems = NULL; ++ _cleanup_free_ char *disable_controllers_str = NULL, *cpuset_cpus2 = NULL, *cpuset_mems2 = NULL, *startup_cpuset_cpus2 = NULL, *startup_cpuset_mems2 = NULL; + CGroupContext *c; + struct in_addr_prefix *iaai; + +@@ -434,16 +440,17 @@ void cgroup_context_dump(Unit *u, FILE* f, const char *prefix) { + + (void) cg_mask_to_string(c->disable_controllers, &disable_controllers_str); + +- cpuset_cpus = cpu_set_to_range_string(&c->cpuset_cpus); +- startup_cpuset_cpus = cpu_set_to_range_string(&c->startup_cpuset_cpus); +- cpuset_mems = cpu_set_to_range_string(&c->cpuset_mems); +- startup_cpuset_mems = cpu_set_to_range_string(&c->startup_cpuset_mems); ++ cpuset_cpus2 = cpu_set_to_range_string(&c->cpuset_cpus2); ++ startup_cpuset_cpus2 = cpu_set_to_range_string(&c->startup_cpuset_cpus2); ++ cpuset_mems2 = cpu_set_to_range_string(&c->cpuset_mems2); ++ startup_cpuset_mems2 = cpu_set_to_range_string(&c->startup_cpuset_mems2); + + fprintf(f, + "%sCPUAccounting: %s\n" + "%sIOAccounting: %s\n" + "%sBlockIOAccounting: %s\n" + "%sMemoryAccounting: %s\n" ++ "%sCPUSetAccounting: %s\n" + "%sTasksAccounting: %s\n" + "%sIPAccounting: %s\n" + "%sCPUWeight: %" PRIu64 "\n" +@@ -469,6 +476,10 @@ void cgroup_context_dump(Unit *u, FILE* f, const char *prefix) { + "%sMemorySwapMax: %" PRIu64 "%s\n" + "%sMemoryZSwapMax: %" PRIu64 "%s\n" + "%sMemoryLimit: %" PRIu64 "\n" ++ "%sCPUSetCpus=%s\n" ++ "%sCPUSetMems=%s\n" ++ "%sCPUSetCloneChildren=%s\n" ++ "%sCPUSetMemMigrate=%s\n" + "%sTasksMax: %" PRIu64 "\n" + "%sDevicePolicy: %s\n" + "%sDisableControllers: %s\n" +@@ -481,6 +492,7 @@ void cgroup_context_dump(Unit *u, FILE* f, const char *prefix) { + prefix, yes_no(c->io_accounting), + prefix, yes_no(c->blockio_accounting), + prefix, yes_no(c->memory_accounting), ++ prefix, yes_no(c->cpuset_accounting), + prefix, yes_no(c->tasks_accounting), + prefix, yes_no(c->ip_accounting), + prefix, c->cpu_weight, +@@ -489,10 +501,10 @@ void cgroup_context_dump(Unit *u, FILE* f, const char *prefix) { + prefix, c->startup_cpu_shares, + prefix, FORMAT_TIMESPAN(c->cpu_quota_per_sec_usec, 1), + prefix, FORMAT_TIMESPAN(c->cpu_quota_period_usec, 1), +- prefix, strempty(cpuset_cpus), +- prefix, strempty(startup_cpuset_cpus), +- prefix, strempty(cpuset_mems), +- prefix, strempty(startup_cpuset_mems), ++ prefix, strempty(cpuset_cpus2), ++ prefix, strempty(startup_cpuset_cpus2), ++ prefix, strempty(cpuset_mems2), ++ prefix, strempty(startup_cpuset_mems2), + prefix, c->io_weight, + prefix, c->startup_io_weight, + prefix, c->blockio_weight, +@@ -506,6 +518,10 @@ void cgroup_context_dump(Unit *u, FILE* f, const char *prefix) { + prefix, c->memory_swap_max, format_cgroup_memory_limit_comparison(cde, sizeof(cde), u, "MemorySwapMax"), + prefix, c->memory_zswap_max, format_cgroup_memory_limit_comparison(cde, sizeof(cde), u, "MemoryZSwapMax"), + prefix, c->memory_limit, ++ prefix, c->cpuset_cpus, ++ prefix, c->cpuset_mems, ++ prefix, yes_no(c->cpuset_clone_children), ++ prefix, yes_no(c->cpuset_memory_migrate), + prefix, tasks_max_resolve(&c->tasks_max), + prefix, cgroup_device_policy_to_string(c->device_policy), + prefix, strempty(disable_controllers_str), +@@ -921,11 +937,11 @@ static bool cgroup_context_has_cpu_shares(CGroupContext *c) { + } + + static bool cgroup_context_has_allowed_cpus(CGroupContext *c) { +- return c->cpuset_cpus.set || c->startup_cpuset_cpus.set; ++ return c->cpuset_cpus2.set || c->startup_cpuset_cpus2.set; + } + + static bool cgroup_context_has_allowed_mems(CGroupContext *c) { +- return c->cpuset_mems.set || c->startup_cpuset_mems.set; ++ return c->cpuset_mems2.set || c->startup_cpuset_mems2.set; + } + + static uint64_t cgroup_context_cpu_weight(CGroupContext *c, ManagerState state) { +@@ -950,18 +966,18 @@ static uint64_t cgroup_context_cpu_shares(CGroupContext *c, ManagerState state) + + static CPUSet *cgroup_context_allowed_cpus(CGroupContext *c, ManagerState state) { + if (IN_SET(state, MANAGER_STARTING, MANAGER_INITIALIZING, MANAGER_STOPPING) && +- c->startup_cpuset_cpus.set) +- return &c->startup_cpuset_cpus; ++ c->startup_cpuset_cpus2.set) ++ return &c->startup_cpuset_cpus2; + else +- return &c->cpuset_cpus; ++ return &c->cpuset_cpus2; + } + + static CPUSet *cgroup_context_allowed_mems(CGroupContext *c, ManagerState state) { + if (IN_SET(state, MANAGER_STARTING, MANAGER_INITIALIZING, MANAGER_STOPPING) && +- c->startup_cpuset_mems.set) +- return &c->startup_cpuset_mems; ++ c->startup_cpuset_mems2.set) ++ return &c->startup_cpuset_mems2; + else +- return &c->cpuset_mems; ++ return &c->cpuset_mems2; + } + + usec_t cgroup_cpu_adjust_period(usec_t period, usec_t quota, usec_t resolution, usec_t max_period) { +@@ -1495,7 +1511,7 @@ static void cgroup_context_apply( + } + } + +- if ((apply_mask & CGROUP_MASK_CPUSET) && !is_local_root) { ++ if ((apply_mask & CGROUP_MASK_CPUSET2) && !is_local_root) { + cgroup_apply_unified_cpuset(u, cgroup_context_allowed_cpus(c, state), "cpuset.cpus"); + cgroup_apply_unified_cpuset(u, cgroup_context_allowed_mems(c, state), "cpuset.mems"); + } +@@ -1667,6 +1683,45 @@ static void cgroup_context_apply( + } + } + ++ if ((apply_mask & CGROUP_MASK_CPUSET) && !is_local_root) { ++ (void) set_attribute_and_warn(u, "cpuset", "cgroup.clone_children", one_zero(c->cpuset_clone_children)); ++ (void) set_attribute_and_warn(u, "cpuset", "cpuset.memory_migrate", one_zero(c->cpuset_memory_migrate)); ++ if (c->cpuset_cpus) { ++ if (streq(c->cpuset_cpus, "all")) { ++ _cleanup_free_ char *str_cpuset_cpus = NULL; ++ _cleanup_free_ char *cg_root_path_cpus = NULL; ++ r = cg_get_root_path(&cg_root_path_cpus); ++ if (r < 0) ++ log_info_errno(r, "Failed to determine root cgroup, ignoring cgroup cpuset cpus: %m"); ++ if (cg_root_path_cpus) { ++ r = cg_get_attribute("cpuset", cg_root_path_cpus, "cpuset.cpus", &str_cpuset_cpus); ++ if (r < 0) ++ log_error("cgroup context apply: cg get attribute is error(%d), path=%s.", r, cg_root_path_cpus); ++ if (str_cpuset_cpus) ++ (void) set_attribute_and_warn(u, "cpuset", "cpuset.cpus", str_cpuset_cpus); ++ } ++ } else ++ (void) set_attribute_and_warn(u, "cpuset", "cpuset.cpus", c->cpuset_cpus); ++ } ++ if (c->cpuset_mems) { ++ if (streq(c->cpuset_mems, "all")) { ++ _cleanup_free_ char *str_cpuset_mems = NULL; ++ _cleanup_free_ char *cg_root_path_mems = NULL; ++ r = cg_get_root_path(&cg_root_path_mems); ++ if (r < 0) ++ log_info_errno(r, "Failed to determine root cgroup, ignoring cgroup cpuset mems: %m"); ++ if (cg_root_path_mems) { ++ r = cg_get_attribute("cpuset", cg_root_path_mems, "cpuset.mems", &str_cpuset_mems); ++ if (r < 0) ++ log_error("cgroup context apply: cg get attribute is error(%d), path=%s.", r, cg_root_path_mems); ++ if (str_cpuset_mems) ++ (void) set_attribute_and_warn(u, "cpuset", "cpuset.mems", str_cpuset_mems); ++ } ++ } else ++ (void) set_attribute_and_warn(u, "cpuset", "cpuset.mems", c->cpuset_mems); ++ } ++ } ++ + /* On cgroup v2 we can apply BPF everywhere. On cgroup v1 we apply it everywhere except for the root of + * containers, where we leave this to the manager */ + if ((apply_mask & (CGROUP_MASK_DEVICES | CGROUP_MASK_BPF_DEVICES)) && +@@ -1808,7 +1863,7 @@ static CGroupMask unit_get_cgroup_mask(Unit *u) { + mask |= CGROUP_MASK_CPU; + + if (cgroup_context_has_allowed_cpus(c) || cgroup_context_has_allowed_mems(c)) +- mask |= CGROUP_MASK_CPUSET; ++ mask |= CGROUP_MASK_CPUSET2; + + if (cgroup_context_has_io_config(c) || cgroup_context_has_blockio_config(c)) + mask |= CGROUP_MASK_IO | CGROUP_MASK_BLKIO; +@@ -1818,6 +1873,11 @@ static CGroupMask unit_get_cgroup_mask(Unit *u) { + unit_has_unified_memory_config(u)) + mask |= CGROUP_MASK_MEMORY; + ++ if (c->cpuset_accounting || ++ c->cpuset_cpus || ++ c->cpuset_mems) ++ mask |= CGROUP_MASK_CPUSET; ++ + if (c->device_allow || + c->device_policy != CGROUP_DEVICE_POLICY_AUTO) + mask |= CGROUP_MASK_DEVICES | CGROUP_MASK_BPF_DEVICES; +@@ -4286,7 +4346,7 @@ int unit_get_cpuset(Unit *u, CPUSet *cpus, const char *name) { + if (!u->cgroup_path) + return -ENODATA; + +- if ((u->cgroup_realized_mask & CGROUP_MASK_CPUSET) == 0) ++ if ((u->cgroup_realized_mask & CGROUP_MASK_CPUSET2) == 0) + return -ENODATA; + + r = cg_all_unified(); +diff --git a/src/core/cgroup.h b/src/core/cgroup.h +index d137e3a..501cba4 100644 +--- a/src/core/cgroup.h ++++ b/src/core/cgroup.h +@@ -115,6 +115,7 @@ struct CGroupContext { + bool io_accounting; + bool blockio_accounting; + bool memory_accounting; ++ bool cpuset_accounting; + bool tasks_accounting; + bool ip_accounting; + +@@ -131,10 +132,10 @@ struct CGroupContext { + usec_t cpu_quota_per_sec_usec; + usec_t cpu_quota_period_usec; + +- CPUSet cpuset_cpus; +- CPUSet startup_cpuset_cpus; +- CPUSet cpuset_mems; +- CPUSet startup_cpuset_mems; ++ CPUSet cpuset_cpus2; ++ CPUSet startup_cpuset_cpus2; ++ CPUSet cpuset_mems2; ++ CPUSet startup_cpuset_mems2; + + uint64_t io_weight; + uint64_t startup_io_weight; +@@ -151,6 +152,11 @@ struct CGroupContext { + uint64_t memory_swap_max; + uint64_t memory_zswap_max; + ++ char *cpuset_cpus; ++ char *cpuset_mems; ++ bool cpuset_clone_children; ++ bool cpuset_memory_migrate; ++ + bool default_memory_min_set:1; + bool default_memory_low_set:1; + bool memory_min_set:1; +diff --git a/src/core/dbus-cgroup.c b/src/core/dbus-cgroup.c +index b5484ed..c3b140e 100644 +--- a/src/core/dbus-cgroup.c ++++ b/src/core/dbus-cgroup.c +@@ -441,10 +441,10 @@ const sd_bus_vtable bus_cgroup_vtable = { + SD_BUS_PROPERTY("StartupCPUShares", "t", NULL, offsetof(CGroupContext, startup_cpu_shares), 0), + SD_BUS_PROPERTY("CPUQuotaPerSecUSec", "t", bus_property_get_usec, offsetof(CGroupContext, cpu_quota_per_sec_usec), 0), + SD_BUS_PROPERTY("CPUQuotaPeriodUSec", "t", bus_property_get_usec, offsetof(CGroupContext, cpu_quota_period_usec), 0), +- SD_BUS_PROPERTY("AllowedCPUs", "ay", property_get_cpuset, offsetof(CGroupContext, cpuset_cpus), 0), +- SD_BUS_PROPERTY("StartupAllowedCPUs", "ay", property_get_cpuset, offsetof(CGroupContext, startup_cpuset_cpus), 0), +- SD_BUS_PROPERTY("AllowedMemoryNodes", "ay", property_get_cpuset, offsetof(CGroupContext, cpuset_mems), 0), +- SD_BUS_PROPERTY("StartupAllowedMemoryNodes", "ay", property_get_cpuset, offsetof(CGroupContext, startup_cpuset_mems), 0), ++ SD_BUS_PROPERTY("AllowedCPUs", "ay", property_get_cpuset, offsetof(CGroupContext, cpuset_cpus2), 0), ++ SD_BUS_PROPERTY("StartupAllowedCPUs", "ay", property_get_cpuset, offsetof(CGroupContext, startup_cpuset_cpus2), 0), ++ SD_BUS_PROPERTY("AllowedMemoryNodes", "ay", property_get_cpuset, offsetof(CGroupContext, cpuset_mems2), 0), ++ SD_BUS_PROPERTY("StartupAllowedMemoryNodes", "ay", property_get_cpuset, offsetof(CGroupContext, startup_cpuset_mems2), 0), + SD_BUS_PROPERTY("IOAccounting", "b", bus_property_get_bool, offsetof(CGroupContext, io_accounting), 0), + SD_BUS_PROPERTY("IOWeight", "t", NULL, offsetof(CGroupContext, io_weight), 0), + SD_BUS_PROPERTY("StartupIOWeight", "t", NULL, offsetof(CGroupContext, startup_io_weight), 0), +@@ -470,6 +470,11 @@ const sd_bus_vtable bus_cgroup_vtable = { + SD_BUS_PROPERTY("MemorySwapMax", "t", NULL, offsetof(CGroupContext, memory_swap_max), 0), + SD_BUS_PROPERTY("MemoryZSwapMax", "t", NULL, offsetof(CGroupContext, memory_zswap_max), 0), + SD_BUS_PROPERTY("MemoryLimit", "t", NULL, offsetof(CGroupContext, memory_limit), 0), ++ SD_BUS_PROPERTY("CPUSetAccounting", "b", bus_property_get_bool, offsetof(CGroupContext, cpuset_accounting), 0), ++ SD_BUS_PROPERTY("CPUSetCpus", "s", NULL, offsetof(CGroupContext, cpuset_cpus), 0), ++ SD_BUS_PROPERTY("CPUSetMems", "s", NULL, offsetof(CGroupContext, cpuset_mems), 0), ++ SD_BUS_PROPERTY("CPUSetCloneChildren", "b", bus_property_get_bool, offsetof(CGroupContext, cpuset_clone_children), 0), ++ SD_BUS_PROPERTY("CPUSetMemMigrate", "b", bus_property_get_bool, offsetof(CGroupContext, cpuset_memory_migrate), 0), + SD_BUS_PROPERTY("DevicePolicy", "s", property_get_cgroup_device_policy, offsetof(CGroupContext, device_policy), 0), + SD_BUS_PROPERTY("DeviceAllow", "a(ss)", property_get_device_allow, 0, 0), + SD_BUS_PROPERTY("TasksAccounting", "b", bus_property_get_bool, offsetof(CGroupContext, tasks_accounting), 0), +@@ -1129,6 +1134,43 @@ int bus_cgroup_set_property( + if (streq(name, "MemoryLimitScale")) + return bus_cgroup_set_memory_scale(u, name, &c->memory_limit, message, flags, error); + ++ if (streq(name, "CPUSetAccounting")) ++ return bus_cgroup_set_boolean(u, name, &c->cpuset_accounting, CGROUP_MASK_CPUSET, message, flags, error); ++ ++ if (STR_IN_SET(name, "CPUSetCpus", "CPUSetMems")) { ++ const char *cpuset_str = NULL; ++ ++ r = sd_bus_message_read(message, "s", &cpuset_str); ++ if (r < 0) ++ return r; ++ ++ if (!UNIT_WRITE_FLAGS_NOOP(flags)) { ++ unit_invalidate_cgroup(u, CGROUP_MASK_CPUSET); ++ if (streq(name, "CPUSetCpus")) { ++ if (c->cpuset_cpus) ++ c->cpuset_cpus = mfree(c->cpuset_cpus); ++ c->cpuset_cpus = strdup(cpuset_str); ++ if (!c->cpuset_cpus) ++ return -ENOMEM; ++ unit_write_settingf(u, flags, name, "CPUSetCpus=%s", cpuset_str); ++ } else { ++ if (c->cpuset_mems) ++ c->cpuset_mems = mfree(c->cpuset_mems); ++ c->cpuset_mems = strdup(cpuset_str); ++ if (!c->cpuset_mems) ++ return -ENOMEM; ++ unit_write_settingf(u, flags, name, "CPUSetMems=%s", cpuset_str); ++ } ++ } ++ return 1; ++ } ++ ++ if (streq(name, "CPUSetCloneChildren")) ++ return bus_cgroup_set_boolean(u, name, &c->cpuset_clone_children, CGROUP_MASK_CPUSET, message, flags, error); ++ ++ if (streq(name, "CPUSetMemMigrate")) ++ return bus_cgroup_set_boolean(u, name, &c->cpuset_memory_migrate, CGROUP_MASK_CPUSET, message, flags, error); ++ + if (streq(name, "TasksAccounting")) + return bus_cgroup_set_boolean(u, name, &c->tasks_accounting, CGROUP_MASK_PIDS, message, flags, error); + +@@ -1208,13 +1250,13 @@ int bus_cgroup_set_property( + return -ENOMEM; + + if (streq(name, "AllowedCPUs")) +- set = &c->cpuset_cpus; ++ set = &c->cpuset_cpus2; + else if (streq(name, "StartupAllowedCPUs")) +- set = &c->startup_cpuset_cpus; ++ set = &c->startup_cpuset_cpus2; + else if (streq(name, "AllowedMemoryNodes")) +- set = &c->cpuset_mems; ++ set = &c->cpuset_mems2; + else if (streq(name, "StartupAllowedMemoryNodes")) +- set = &c->startup_cpuset_mems; ++ set = &c->startup_cpuset_mems2; + + assert(set); + +@@ -1222,7 +1264,7 @@ int bus_cgroup_set_property( + *set = new_set; + new_set = (CPUSet) {}; + +- unit_invalidate_cgroup(u, CGROUP_MASK_CPUSET); ++ unit_invalidate_cgroup(u, CGROUP_MASK_CPUSET2); + unit_write_settingf(u, flags, name, "%s=%s", name, setstr); + } + +diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c +index c4f205b..d6f45a7 100644 +--- a/src/core/dbus-manager.c ++++ b/src/core/dbus-manager.c +@@ -2910,6 +2910,7 @@ const sd_bus_vtable bus_manager_vtable = { + SD_BUS_PROPERTY("DefaultCPUAccounting", "b", bus_property_get_bool, offsetof(Manager, default_cpu_accounting), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("DefaultBlockIOAccounting", "b", bus_property_get_bool, offsetof(Manager, default_blockio_accounting), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("DefaultMemoryAccounting", "b", bus_property_get_bool, offsetof(Manager, default_memory_accounting), SD_BUS_VTABLE_PROPERTY_CONST), ++ SD_BUS_PROPERTY("DefaultCpusetAccounting", "b", bus_property_get_bool, offsetof(Manager, default_cpuset_accounting), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("DefaultTasksAccounting", "b", bus_property_get_bool, offsetof(Manager, default_tasks_accounting), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("DefaultLimitCPU", "t", bus_property_get_rlimit, offsetof(Manager, rlimitRLIMIT_CPU), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("DefaultLimitCPUSoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimitRLIMIT_CPU), SD_BUS_VTABLE_PROPERTY_CONST), +diff --git a/src/core/load-fragment-gperf.gperf.in b/src/core/load-fragment-gperf.gperf.in +index 3ea3ca3..8600faa 100644 +--- a/src/core/load-fragment-gperf.gperf.in ++++ b/src/core/load-fragment-gperf.gperf.in +@@ -187,10 +187,10 @@ + + {%- macro CGROUP_CONTEXT_CONFIG_ITEMS(type) -%} + {{type}}.Slice, config_parse_unit_slice, 0, 0 +-{{type}}.AllowedCPUs, config_parse_allowed_cpuset, 0, offsetof({{type}}, cgroup_context.cpuset_cpus) +-{{type}}.StartupAllowedCPUs, config_parse_allowed_cpuset, 0, offsetof({{type}}, cgroup_context.startup_cpuset_cpus) +-{{type}}.AllowedMemoryNodes, config_parse_allowed_cpuset, 0, offsetof({{type}}, cgroup_context.cpuset_mems) +-{{type}}.StartupAllowedMemoryNodes, config_parse_allowed_cpuset, 0, offsetof({{type}}, cgroup_context.startup_cpuset_mems) ++{{type}}.AllowedCPUs, config_parse_allowed_cpuset, 0, offsetof({{type}}, cgroup_context.cpuset_cpus2) ++{{type}}.StartupAllowedCPUs, config_parse_allowed_cpuset, 0, offsetof({{type}}, cgroup_context.startup_cpuset_cpus2) ++{{type}}.AllowedMemoryNodes, config_parse_allowed_cpuset, 0, offsetof({{type}}, cgroup_context.cpuset_mems2) ++{{type}}.StartupAllowedMemoryNodes, config_parse_allowed_cpuset, 0, offsetof({{type}}, cgroup_context.startup_cpuset_mems2) + {{type}}.CPUAccounting, config_parse_bool, 0, offsetof({{type}}, cgroup_context.cpu_accounting) + {{type}}.CPUWeight, config_parse_cg_cpu_weight, 0, offsetof({{type}}, cgroup_context.cpu_weight) + {{type}}.StartupCPUWeight, config_parse_cg_cpu_weight, 0, offsetof({{type}}, cgroup_context.startup_cpu_weight) +@@ -208,6 +208,11 @@ + {{type}}.MemorySwapMax, config_parse_memory_limit, 0, offsetof({{type}}, cgroup_context) + {{type}}.MemoryZSwapMax, config_parse_memory_limit, 0, offsetof({{type}}, cgroup_context) + {{type}}.MemoryLimit, config_parse_memory_limit, 0, offsetof({{type}}, cgroup_context) ++{{type}}.CPUSetAccounting, config_parse_bool, 0, offsetof({{type}}, cgroup_context.cpuset_accounting) ++{{type}}.CPUSetCpus, config_parse_cpuset_cpumems, 0, offsetof({{type}}, cgroup_context.cpuset_cpus) ++{{type}}.CPUSetMems, config_parse_cpuset_cpumems, 0, offsetof({{type}}, cgroup_context.cpuset_mems) ++{{type}}.CPUSetCloneChildren, config_parse_bool, 0, offsetof({{type}}, cgroup_context.cpuset_clone_children) ++{{type}}.CPUSetMemMigrate, config_parse_bool, 0, offsetof({{type}}, cgroup_context.cpuset_memory_migrate) + {{type}}.DeviceAllow, config_parse_device_allow, 0, offsetof({{type}}, cgroup_context) + {{type}}.DevicePolicy, config_parse_device_policy, 0, offsetof({{type}}, cgroup_context.device_policy) + {{type}}.IOAccounting, config_parse_bool, 0, offsetof({{type}}, cgroup_context.io_accounting) +diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c +index ce15758..b0feac7 100644 +--- a/src/core/load-fragment.c ++++ b/src/core/load-fragment.c +@@ -3864,6 +3864,75 @@ int config_parse_memory_limit( + return 0; + } + ++int config_parse_cpuset_cpumems( ++ const char *unit, ++ const char *filename, ++ unsigned line, ++ const char *section, ++ unsigned section_line, ++ const char *lvalue, ++ int ltype, ++ const char *rvalue, ++ void *data, ++ void *userdata) ++{ ++ char **pcpumems = data; ++ char *pinstr = NULL; ++ int iret = 0; ++ ++ assert(filename); ++ assert(lvalue); ++ assert(rvalue); ++ assert(data); ++ (void)section; ++ (void)section_line; ++ (void)ltype; ++ (void)userdata; ++ ++ if (!utf8_is_valid(rvalue)) ++ { ++ log_syntax_invalid_utf8(unit, LOG_ERR, filename, line, rvalue); ++ return 0; ++ } ++ ++ if (0 == strcmp(rvalue, "all")) ++ { ++ pinstr = strdup(rvalue); ++ if (!pinstr) ++ { ++ return log_oom(); ++ } ++ ++ free(*pcpumems); ++ *pcpumems = pinstr; ++ ++ return 0; ++ } ++ ++ /* 0-2,4 */ ++ iret = string_isvalid_interval(rvalue); ++ if (0 != iret) ++ { ++ pinstr = NULL; ++ log_syntax(unit, LOG_ERR, filename, line, EINVAL, ++ "cpuset cpumems '%s' is invalid, Ignoring(%d).", ++ rvalue, iret); ++ } ++ else ++ { ++ pinstr = strdup(rvalue); ++ if (!pinstr) ++ { ++ return log_oom(); ++ } ++ } ++ ++ free(*pcpumems); ++ *pcpumems = pinstr; ++ ++ return 0; ++} ++ + int config_parse_tasks_max( + const char *unit, + const char *filename, +diff --git a/src/core/load-fragment.h b/src/core/load-fragment.h +index 11d43dd..405681f 100644 +--- a/src/core/load-fragment.h ++++ b/src/core/load-fragment.h +@@ -81,6 +81,7 @@ CONFIG_PARSER_PROTOTYPE(config_parse_cg_weight); + CONFIG_PARSER_PROTOTYPE(config_parse_cg_cpu_weight); + CONFIG_PARSER_PROTOTYPE(config_parse_cpu_shares); + CONFIG_PARSER_PROTOTYPE(config_parse_memory_limit); ++CONFIG_PARSER_PROTOTYPE(config_parse_cpuset_cpumems); + CONFIG_PARSER_PROTOTYPE(config_parse_tasks_max); + CONFIG_PARSER_PROTOTYPE(config_parse_delegate); + CONFIG_PARSER_PROTOTYPE(config_parse_managed_oom_mode); +diff --git a/src/core/main.c b/src/core/main.c +index c6d16b2..e64882c 100644 +--- a/src/core/main.c ++++ b/src/core/main.c +@@ -160,6 +160,7 @@ static bool arg_default_io_accounting; + static bool arg_default_ip_accounting; + static bool arg_default_blockio_accounting; + static bool arg_default_memory_accounting; ++static bool arg_default_cpuset_accounting; + static bool arg_default_tasks_accounting; + static TasksMax arg_default_tasks_max; + static sd_id128_t arg_machine_id; +@@ -681,6 +682,7 @@ static int parse_config_file(void) { + { "Manager", "DefaultIPAccounting", config_parse_bool, 0, &arg_default_ip_accounting }, + { "Manager", "DefaultBlockIOAccounting", config_parse_bool, 0, &arg_default_blockio_accounting }, + { "Manager", "DefaultMemoryAccounting", config_parse_bool, 0, &arg_default_memory_accounting }, ++ { "Manager", "DefaultCpusetAccounting", config_parse_bool, 0, &arg_default_cpuset_accounting }, + { "Manager", "DefaultTasksAccounting", config_parse_bool, 0, &arg_default_tasks_accounting }, + { "Manager", "DefaultTasksMax", config_parse_tasks_max, 0, &arg_default_tasks_max }, + { "Manager", "CtrlAltDelBurstAction", config_parse_emergency_action, arg_system, &arg_cad_burst_action }, +@@ -762,6 +764,7 @@ static void set_manager_defaults(Manager *m) { + m->default_ip_accounting = arg_default_ip_accounting; + m->default_blockio_accounting = arg_default_blockio_accounting; + m->default_memory_accounting = arg_default_memory_accounting; ++ m->default_cpuset_accounting = arg_default_cpuset_accounting; + m->default_tasks_accounting = arg_default_tasks_accounting; + m->default_tasks_max = arg_default_tasks_max; + m->default_oom_policy = arg_default_oom_policy; +@@ -2457,6 +2460,7 @@ static void reset_arguments(void) { + arg_default_ip_accounting = false; + arg_default_blockio_accounting = false; + arg_default_memory_accounting = MEMORY_ACCOUNTING_DEFAULT; ++ arg_default_cpuset_accounting = false; + arg_default_tasks_accounting = true; + arg_default_tasks_max = DEFAULT_TASKS_MAX; + arg_machine_id = (sd_id128_t) {}; +diff --git a/src/core/manager.c b/src/core/manager.c +index 2c8c726..011de6b 100644 +--- a/src/core/manager.c ++++ b/src/core/manager.c +@@ -833,6 +833,7 @@ int manager_new(LookupScope scope, ManagerTestRunFlags test_run_flags, Manager * + + .default_timer_accuracy_usec = USEC_PER_MINUTE, + .default_memory_accounting = MEMORY_ACCOUNTING_DEFAULT, ++ .default_cpuset_accounting = false, + .default_tasks_accounting = true, + .default_tasks_max = TASKS_MAX_UNSET, + .default_timeout_start_usec = manager_default_timeout(scope == LOOKUP_SCOPE_SYSTEM), +diff --git a/src/core/manager.h b/src/core/manager.h +index e7b594f..c4edacc 100644 +--- a/src/core/manager.h ++++ b/src/core/manager.h +@@ -365,6 +365,7 @@ struct Manager { + + bool default_cpu_accounting; + bool default_memory_accounting; ++ bool default_cpuset_accounting; + bool default_io_accounting; + bool default_blockio_accounting; + bool default_tasks_accounting; +diff --git a/src/core/system.conf.in b/src/core/system.conf.in +index 1349b1f..a0ef2bf 100644 +--- a/src/core/system.conf.in ++++ b/src/core/system.conf.in +@@ -55,6 +55,7 @@ + #DefaultIOAccounting=no + #DefaultIPAccounting=no + #DefaultMemoryAccounting={{ 'yes' if MEMORY_ACCOUNTING_DEFAULT else 'no' }} ++#DefaultCpusetAccounting= + #DefaultTasksAccounting=yes + #DefaultTasksMax=80% + #DefaultLimitCPU= +diff --git a/src/core/unit.c b/src/core/unit.c +index 5e230ef..9ac41b4 100644 +--- a/src/core/unit.c ++++ b/src/core/unit.c +@@ -179,6 +179,7 @@ static void unit_init(Unit *u) { + cc->io_accounting = u->manager->default_io_accounting; + cc->blockio_accounting = u->manager->default_blockio_accounting; + cc->memory_accounting = u->manager->default_memory_accounting; ++ cc->cpuset_accounting = u->manager->default_cpuset_accounting; + cc->tasks_accounting = u->manager->default_tasks_accounting; + cc->ip_accounting = u->manager->default_ip_accounting; + +diff --git a/src/shared/bus-unit-util.c b/src/shared/bus-unit-util.c +index 1e95e36..e1aed3d 100644 +--- a/src/shared/bus-unit-util.c ++++ b/src/shared/bus-unit-util.c +@@ -481,7 +481,10 @@ static int bus_append_cgroup_property(sd_bus_message *m, const char *field, cons + "IOAccounting", + "BlockIOAccounting", + "TasksAccounting", +- "IPAccounting")) ++ "IPAccounting", ++ "CPUSetAccounting", ++ "CPUSetCloneChildren", ++ "CPUSetMemMigrate")) + return bus_append_parse_boolean(m, field, eq); + + if (STR_IN_SET(field, "CPUWeight", +@@ -587,6 +590,16 @@ static int bus_append_cgroup_property(sd_bus_message *m, const char *field, cons + return bus_append_parse_size(m, field, eq, 1024); + } + ++ if (STR_IN_SET(field, "CPUSetCpus", "CPUSetMems")) { ++ if (string_isvalid_interval(eq) == 0 || streq(eq, "all")) ++ r = sd_bus_message_append(m, "(sv)", field, "s", eq); ++ else ++ r = -EINVAL; ++ if (r < 0) ++ return bus_log_create_error(r); ++ return 1; ++ } ++ + if (streq(field, "CPUQuota")) { + if (isempty(eq)) + r = sd_bus_message_append(m, "(sv)", "CPUQuotaPerSecUSec", "t", USEC_INFINITY); +diff --git a/src/shared/cpu-set-util.c b/src/shared/cpu-set-util.c +index 34c13cf..68da01b 100644 +--- a/src/shared/cpu-set-util.c ++++ b/src/shared/cpu-set-util.c +@@ -7,6 +7,7 @@ + + #include "alloc-util.h" + #include "cpu-set-util.h" ++#include "cgroup-util.h" + #include "dirent-util.h" + #include "errno-util.h" + #include "extract-word.h" +diff --git a/src/test/test-cgroup-mask.c b/src/test/test-cgroup-mask.c +index 57483f7..e969569 100644 +--- a/src/test/test-cgroup-mask.c ++++ b/src/test/test-cgroup-mask.c +@@ -55,6 +55,7 @@ TEST_RET(cgroup_mask, .sd_booted = true) { + * else. */ + m->default_cpu_accounting = + m->default_memory_accounting = ++ m->default_cpuset_accounting = + m->default_blockio_accounting = + m->default_io_accounting = + m->default_tasks_accounting = false; +@@ -140,10 +141,10 @@ static void test_cg_mask_to_string_one(CGroupMask mask, const char *t) { + + TEST(cg_mask_to_string) { + test_cg_mask_to_string_one(0, NULL); +- test_cg_mask_to_string_one(_CGROUP_MASK_ALL, "cpu cpuacct cpuset io blkio memory devices pids bpf-firewall bpf-devices bpf-foreign bpf-socket-bind bpf-restrict-network-interfaces"); ++ test_cg_mask_to_string_one(_CGROUP_MASK_ALL, "cpu cpuacct cpuset2 io blkio memory devices pids cpuset bpf-firewall bpf-devices bpf-foreign bpf-socket-bind bpf-restrict-network-interfaces"); + test_cg_mask_to_string_one(CGROUP_MASK_CPU, "cpu"); + test_cg_mask_to_string_one(CGROUP_MASK_CPUACCT, "cpuacct"); +- test_cg_mask_to_string_one(CGROUP_MASK_CPUSET, "cpuset"); ++ test_cg_mask_to_string_one(CGROUP_MASK_CPUSET2, "cpuset2"); + test_cg_mask_to_string_one(CGROUP_MASK_IO, "io"); + test_cg_mask_to_string_one(CGROUP_MASK_BLKIO, "blkio"); + test_cg_mask_to_string_one(CGROUP_MASK_MEMORY, "memory"); +diff --git a/test/fuzz/fuzz-unit-file/directives-all.service b/test/fuzz/fuzz-unit-file/directives-all.service +index f8237d7..dcf99e1 100644 +--- a/test/fuzz/fuzz-unit-file/directives-all.service ++++ b/test/fuzz/fuzz-unit-file/directives-all.service +@@ -52,6 +52,11 @@ BusName= + CoredumpFilter= + CPUAccounting= + CPUQuota= ++CPUSetAccounting= ++CPUSetCloneChildren= ++CPUSetCpus= ++CPUSetMemMigrate= ++CPUSetMems= + CPUShares= + CPUWeight= + CapabilityBoundingSet= +-- +2.33.0 +
View file
_service:tar_scm:core-cgroup-support-default-slice-for-all-uni.patch
Added
@@ -0,0 +1,217 @@ +From a25f206a49d8a3111ac42791b2eca8a3c9af4991 Mon Sep 17 00:00:00 2001 +From: licunlong <licunlong1@huawei.com> +Date: Thu, 6 May 2021 09:38:55 +0800 +Subject: PATCH core-cgroup: support default slice for all units. + +With this patch, users can specify a default slice for all units by +adding DefaultUnitSlice=xxx.slice in /etc/systemd/system.conf. +--- + src/core/main.c | 22 +++++++++++ + src/core/manager.h | 3 ++ + src/core/unit.c | 98 ++++++++++++++++++++++++++++++++++++++++++---- + 3 files changed, 115 insertions(+), 8 deletions(-) + +diff --git a/src/core/main.c b/src/core/main.c +index 809ed76..500691a 100644 +--- a/src/core/main.c ++++ b/src/core/main.c +@@ -171,6 +171,7 @@ static EmergencyAction arg_cad_burst_action; + static OOMPolicy arg_default_oom_policy; + static CPUSet arg_cpu_affinity; + static NUMAPolicy arg_numa_policy; ++static char *arg_default_unit_slice = NULL; + static usec_t arg_clock_usec; + static void *arg_random_seed; + static size_t arg_random_seed_size; +@@ -694,6 +695,7 @@ static int parse_config_file(void) { + { "Manager", "CtrlAltDelBurstAction", config_parse_emergency_action, arg_system, &arg_cad_burst_action }, + { "Manager", "DefaultOOMPolicy", config_parse_oom_policy, 0, &arg_default_oom_policy }, + { "Manager", "DefaultOOMScoreAdjust", config_parse_oom_score_adjust, 0, NULL }, ++ { "Manager", "DefaultUnitSlice", config_parse_string, 0, &arg_default_unit_slice }, + { "Manager", "ReloadLimitIntervalSec", config_parse_sec, 0, &arg_reload_limit_interval_sec }, + { "Manager", "ReloadLimitBurst", config_parse_unsigned, 0, &arg_reload_limit_burst }, + #if ENABLE_SMACK +@@ -786,6 +788,26 @@ static void set_manager_defaults(Manager *m) { + + (void) manager_default_environment(m); + (void) manager_transient_environment_add(m, arg_default_environment); ++ if (m->default_unit_slice) ++ { ++ free(m->default_unit_slice); ++ m->default_unit_slice = NULL; ++ } ++ ++ if (arg_default_unit_slice) ++ { ++ char *default_unit_slice_tmp = NULL; ++ ++ default_unit_slice_tmp = strdup(arg_default_unit_slice); ++ if (!default_unit_slice_tmp) ++ log_oom(); ++ ++ m->default_unit_slice = default_unit_slice_tmp; ++ ++ /* free */ ++ free(arg_default_unit_slice); ++ arg_default_unit_slice = NULL; ++ } + } + + static void set_manager_settings(Manager *m) { +diff --git a/src/core/manager.h b/src/core/manager.h +index 814421f..9e391b1 100644 +--- a/src/core/manager.h ++++ b/src/core/manager.h +@@ -22,6 +22,7 @@ typedef struct Unit Unit; + + /* Enforce upper limit how many names we allow */ + #define MANAGER_MAX_NAMES 131072 /* 128K */ ++#define DEFAULT_UNIT_NAME_LEN_MAX 32 + + typedef struct Manager Manager; + +@@ -455,6 +456,8 @@ struct Manager { + unsigned sigchldgen; + unsigned notifygen; + ++ char *default_unit_slice; ++ + VarlinkServer *varlink_server; + /* When we're a system manager, this object manages the subscription from systemd-oomd to PID1 that's + * used to report changes in ManagedOOM settings (systemd server - oomd client). When +diff --git a/src/core/unit.c b/src/core/unit.c +index eef05d0..cc74a43 100644 +--- a/src/core/unit.c ++++ b/src/core/unit.c +@@ -3340,6 +3340,58 @@ int unit_set_slice(Unit *u, Unit *slice) { + return 1; + } + ++/* system-xxx.slice, xxx must be (a b c/A B C...and 0 1 2...) */ ++static bool slicename_is_valid(const char *slicename) { ++ const char *str_start = "system-"; ++ const char *str_end = ".slice"; ++ const char *str_tmp = NULL; ++ size_t len_in = 0; ++ size_t len_start = 0; ++ size_t len_end = 0; ++ size_t i = 0; ++ ++ if (isempty(slicename)) ++ return false; ++ ++ len_in = strlen(slicename); ++ len_start = strlen(str_start); ++ len_end = strlen(str_end); ++ ++ if (len_in > DEFAULT_UNIT_NAME_LEN_MAX) ++ return false; ++ ++ if (len_in <= len_start + len_end) ++ return false; ++ ++ /* system- */ ++ if (strncmp(slicename, str_start, len_start) != 0) ++ return false; ++ ++ str_tmp = slicename + len_start; ++ ++ len_in = strlen(str_tmp); ++ if (len_in <= len_end) ++ return false; ++ ++ /* .slice */ ++ if (!strneq(str_tmp + len_in - len_end, str_end, len_end)) ++ return false; ++ ++ /* a b c/A B C...and 0 1 2... */ ++ for (i = 0; i < (len_in - len_end); i++) { ++ char c = *(str_tmp + i); ++ ++ if ((c >= 'a' && c <= 'z') || ++ (c >= 'A' && c <= 'Z') || ++ (c >= '0' && c <= '9')) ++ continue; ++ else ++ return false; ++ } ++ ++ return true; ++} ++ + int unit_set_default_slice(Unit *u) { + const char *slice_name; + Unit *slice; +@@ -3353,6 +3405,20 @@ int unit_set_default_slice(Unit *u) { + if (UNIT_GET_SLICE(u)) + return 0; + ++ bool isdefaultslice = false; ++ char *default_unit_slice = u->manager->default_unit_slice; ++ ++ if (default_unit_slice) { ++ isdefaultslice = true; ++ ++ if (streq(default_unit_slice, SPECIAL_SYSTEM_SLICE)) ++ isdefaultslice = false; ++ else if (!slicename_is_valid(default_unit_slice)) { ++ log_error("default unit slice is error. slice name '%s' is invalid.", default_unit_slice); ++ isdefaultslice = false; ++ } ++ } ++ + if (u->instance) { + _cleanup_free_ char *prefix = NULL, *escaped = NULL; + +@@ -3370,24 +3436,40 @@ int unit_set_default_slice(Unit *u) { + if (!escaped) + return -ENOMEM; + +- if (MANAGER_IS_SYSTEM(u->manager)) +- slice_name = strjoina("system-", escaped, ".slice"); +- else ++ if (MANAGER_IS_SYSTEM(u->manager)) { ++ if (isdefaultslice) { ++ _cleanup_free_ char *default_unit_slice_tmp = NULL; ++ ++ default_unit_slice_tmp = strreplace(default_unit_slice, ".slice", "-"); ++ if (!default_unit_slice_tmp) ++ return -ENOMEM; ++ ++ slice_name = strjoina(default_unit_slice_tmp, escaped, ".slice"); ++ } else ++ slice_name = strjoina("system-", escaped, ".slice"); ++ } else + slice_name = strjoina("app-", escaped, ".slice"); + +- } else if (unit_is_extrinsic(u)) ++ } else if (unit_is_extrinsic(u)) { + /* Keep all extrinsic units (e.g. perpetual units and swap and mount units in user mode) in + * the root slice. They don't really belong in one of the subslices. */ + slice_name = SPECIAL_ROOT_SLICE; +- +- else if (MANAGER_IS_SYSTEM(u->manager)) +- slice_name = SPECIAL_SYSTEM_SLICE; +- else ++ isdefaultslice = false; ++ } else if (MANAGER_IS_SYSTEM(u->manager)) { ++ if (isdefaultslice) ++ slice_name = default_unit_slice; ++ else ++ slice_name = SPECIAL_SYSTEM_SLICE; ++ } else { + slice_name = SPECIAL_APP_SLICE; ++ isdefaultslice = false; ++ } + + r = manager_load_unit(u->manager, slice_name, NULL, NULL, &slice); + if (r < 0) + return r; ++ if (isdefaultslice) ++ slice->default_dependencies=false; + + return unit_set_slice(u, slice); + } +-- +2.33.0 +
View file
_service:tar_scm:core-cgroup-support-freezer.patch
Added
@@ -0,0 +1,506 @@ +From 05a0f33b0d0a650b25ce7955a171d725f9c3f5f6 Mon Sep 17 00:00:00 2001 +From: licunlong <licunlong1@huawei.com> +Date: Thu, 6 May 2021 09:38:54 +0800 +Subject: PATCH core-cgroup: support freezer. + +This patch add support for freezer subsystem. +--- + src/basic/cgroup-util.c | 1 + + src/basic/cgroup-util.h | 4 +- + src/core/cgroup.c | 16 +++++++ + src/core/cgroup.h | 4 ++ + src/core/dbus-cgroup.c | 29 +++++++++++++ + src/core/dbus-manager.c | 1 + + src/core/load-fragment-gperf.gperf.in | 2 + + src/core/load-fragment.c | 33 ++++++++++++++ + src/core/load-fragment.h | 1 + + src/core/main.c | 4 ++ + src/core/manager.h | 1 + + src/core/system.conf.in | 1 + + src/core/unit.c | 1 + + src/shared/bus-unit-util.c | 11 +++++ + src/test/meson.build | 6 +++ + src/test/test-cgroup-freezer.c | 43 +++++++++++++++++++ + src/test/test-cgroup-mask.c | 3 +- + .../fuzz-unit-file/directives-all.service | 2 + + 18 files changed, 161 insertions(+), 2 deletions(-) + create mode 100644 src/test/test-cgroup-freezer.c + +diff --git a/src/basic/cgroup-util.c b/src/basic/cgroup-util.c +index 1bb07f7..ac25693 100644 +--- a/src/basic/cgroup-util.c ++++ b/src/basic/cgroup-util.c +@@ -2255,6 +2255,7 @@ static const char *const cgroup_controller_table_CGROUP_CONTROLLER_MAX = { + CGROUP_CONTROLLER_DEVICES = "devices", + CGROUP_CONTROLLER_PIDS = "pids", + CGROUP_CONTROLLER_CPUSET = "cpuset", ++ CGROUP_CONTROLLER_FREEZER = "freezer", + CGROUP_CONTROLLER_BPF_FIREWALL = "bpf-firewall", + CGROUP_CONTROLLER_BPF_DEVICES = "bpf-devices", + CGROUP_CONTROLLER_BPF_FOREIGN = "bpf-foreign", +diff --git a/src/basic/cgroup-util.h b/src/basic/cgroup-util.h +index 764d47a..147c956 100644 +--- a/src/basic/cgroup-util.h ++++ b/src/basic/cgroup-util.h +@@ -28,6 +28,7 @@ typedef enum CGroupController { + CGROUP_CONTROLLER_DEVICES, /* v1 only */ + CGROUP_CONTROLLER_PIDS, + CGROUP_CONTROLLER_CPUSET, ++ CGROUP_CONTROLLER_FREEZER, + + /* BPF-based pseudo-controllers, v2 only */ + CGROUP_CONTROLLER_BPF_FIREWALL, +@@ -56,6 +57,7 @@ typedef enum CGroupMask { + CGROUP_MASK_DEVICES = CGROUP_CONTROLLER_TO_MASK(CGROUP_CONTROLLER_DEVICES), + CGROUP_MASK_PIDS = CGROUP_CONTROLLER_TO_MASK(CGROUP_CONTROLLER_PIDS), + CGROUP_MASK_CPUSET = CGROUP_CONTROLLER_TO_MASK(CGROUP_CONTROLLER_CPUSET), ++ CGROUP_MASK_FREEZER = CGROUP_CONTROLLER_TO_MASK(CGROUP_CONTROLLER_FREEZER), + CGROUP_MASK_BPF_FIREWALL = CGROUP_CONTROLLER_TO_MASK(CGROUP_CONTROLLER_BPF_FIREWALL), + CGROUP_MASK_BPF_DEVICES = CGROUP_CONTROLLER_TO_MASK(CGROUP_CONTROLLER_BPF_DEVICES), + CGROUP_MASK_BPF_FOREIGN = CGROUP_CONTROLLER_TO_MASK(CGROUP_CONTROLLER_BPF_FOREIGN), +@@ -63,7 +65,7 @@ typedef enum CGroupMask { + CGROUP_MASK_BPF_RESTRICT_NETWORK_INTERFACES = CGROUP_CONTROLLER_TO_MASK(CGROUP_CONTROLLER_BPF_RESTRICT_NETWORK_INTERFACES), + + /* All real cgroup v1 controllers */ +- CGROUP_MASK_V1 = CGROUP_MASK_CPU|CGROUP_MASK_CPUACCT|CGROUP_MASK_BLKIO|CGROUP_MASK_MEMORY|CGROUP_MASK_CPUSET|CGROUP_MASK_DEVICES|CGROUP_MASK_PIDS, ++ CGROUP_MASK_V1 = CGROUP_MASK_CPU|CGROUP_MASK_CPUACCT|CGROUP_MASK_BLKIO|CGROUP_MASK_MEMORY|CGROUP_MASK_CPUSET|CGROUP_MASK_FREEZER|CGROUP_MASK_DEVICES|CGROUP_MASK_PIDS, + + /* All real cgroup v2 controllers */ + CGROUP_MASK_V2 = CGROUP_MASK_CPU|CGROUP_MASK_CPUSET2|CGROUP_MASK_IO|CGROUP_MASK_MEMORY|CGROUP_MASK_PIDS, +diff --git a/src/core/cgroup.c b/src/core/cgroup.c +index a6396e1..7d1e59b 100644 +--- a/src/core/cgroup.c ++++ b/src/core/cgroup.c +@@ -162,6 +162,7 @@ void cgroup_context_init(CGroupContext *c) { + .startup_blockio_weight = CGROUP_BLKIO_WEIGHT_INVALID, + + .tasks_max = TASKS_MAX_UNSET, ++ .freezer_state = NULL, + + .moom_swap = MANAGED_OOM_AUTO, + .moom_mem_pressure = MANAGED_OOM_AUTO, +@@ -287,6 +288,9 @@ void cgroup_context_done(CGroupContext *c) { + cpu_set_reset(&c->startup_cpuset_cpus2); + cpu_set_reset(&c->cpuset_mems2); + cpu_set_reset(&c->startup_cpuset_mems2); ++ ++ if (c->freezer_state) ++ c->freezer_state = mfree(c->freezer_state); + } + + static int unit_get_kernel_memory_limit(Unit *u, const char *file, uint64_t *ret) { +@@ -451,6 +455,7 @@ void cgroup_context_dump(Unit *u, FILE* f, const char *prefix) { + "%sBlockIOAccounting: %s\n" + "%sMemoryAccounting: %s\n" + "%sCPUSetAccounting: %s\n" ++ "%sFreezerAccounting=%s\n" + "%sTasksAccounting: %s\n" + "%sIPAccounting: %s\n" + "%sCPUWeight: %" PRIu64 "\n" +@@ -481,6 +486,7 @@ void cgroup_context_dump(Unit *u, FILE* f, const char *prefix) { + "%sCPUSetCloneChildren=%s\n" + "%sCPUSetMemMigrate=%s\n" + "%sTasksMax: %" PRIu64 "\n" ++ "%sFreezerState=%s\n" + "%sDevicePolicy: %s\n" + "%sDisableControllers: %s\n" + "%sDelegate: %s\n" +@@ -493,6 +499,7 @@ void cgroup_context_dump(Unit *u, FILE* f, const char *prefix) { + prefix, yes_no(c->blockio_accounting), + prefix, yes_no(c->memory_accounting), + prefix, yes_no(c->cpuset_accounting), ++ prefix, yes_no(c->freezer_accounting), + prefix, yes_no(c->tasks_accounting), + prefix, yes_no(c->ip_accounting), + prefix, c->cpu_weight, +@@ -523,6 +530,7 @@ void cgroup_context_dump(Unit *u, FILE* f, const char *prefix) { + prefix, yes_no(c->cpuset_clone_children), + prefix, yes_no(c->cpuset_memory_migrate), + prefix, tasks_max_resolve(&c->tasks_max), ++ prefix, c->freezer_state, + prefix, cgroup_device_policy_to_string(c->device_policy), + prefix, strempty(disable_controllers_str), + prefix, yes_no(c->delegate), +@@ -1722,6 +1730,11 @@ static void cgroup_context_apply( + } + } + ++ if ((apply_mask & CGROUP_MASK_FREEZER) && !is_local_root) { ++ if (c->freezer_state) ++ (void) set_attribute_and_warn(u, "freezer", "freezer.state", c->freezer_state); ++ } ++ + /* On cgroup v2 we can apply BPF everywhere. On cgroup v1 we apply it everywhere except for the root of + * containers, where we leave this to the manager */ + if ((apply_mask & (CGROUP_MASK_DEVICES | CGROUP_MASK_BPF_DEVICES)) && +@@ -1878,6 +1891,9 @@ static CGroupMask unit_get_cgroup_mask(Unit *u) { + c->cpuset_mems) + mask |= CGROUP_MASK_CPUSET; + ++ if (c->freezer_accounting || c->freezer_state) ++ mask |= CGROUP_MASK_FREEZER; ++ + if (c->device_allow || + c->device_policy != CGROUP_DEVICE_POLICY_AUTO) + mask |= CGROUP_MASK_DEVICES | CGROUP_MASK_BPF_DEVICES; +diff --git a/src/core/cgroup.h b/src/core/cgroup.h +index 501cba4..2251548 100644 +--- a/src/core/cgroup.h ++++ b/src/core/cgroup.h +@@ -116,6 +116,7 @@ struct CGroupContext { + bool blockio_accounting; + bool memory_accounting; + bool cpuset_accounting; ++ bool freezer_accounting; + bool tasks_accounting; + bool ip_accounting; + +@@ -196,6 +197,9 @@ struct CGroupContext { + /* Common */ + TasksMax tasks_max; + ++ /* Freezer */ ++ char *freezer_state; ++ + /* Settings for systemd-oomd */ + ManagedOOMMode moom_swap; + ManagedOOMMode moom_mem_pressure; +diff --git a/src/core/dbus-cgroup.c b/src/core/dbus-cgroup.c +index c3b140e..c51a8b7 100644 +--- a/src/core/dbus-cgroup.c ++++ b/src/core/dbus-cgroup.c +@@ -475,6 +475,8 @@ const sd_bus_vtable bus_cgroup_vtable = { + SD_BUS_PROPERTY("CPUSetMems", "s", NULL, offsetof(CGroupContext, cpuset_mems), 0), + SD_BUS_PROPERTY("CPUSetCloneChildren", "b", bus_property_get_bool, offsetof(CGroupContext, cpuset_clone_children), 0), + SD_BUS_PROPERTY("CPUSetMemMigrate", "b", bus_property_get_bool, offsetof(CGroupContext, cpuset_memory_migrate), 0), ++ SD_BUS_PROPERTY("FreezerAccounting", "b", bus_property_get_bool, offsetof(CGroupContext, freezer_accounting), 0), ++ SD_BUS_PROPERTY("FreezerState", "s", NULL, offsetof(CGroupContext, freezer_state), 0), + SD_BUS_PROPERTY("DevicePolicy", "s", property_get_cgroup_device_policy, offsetof(CGroupContext, device_policy), 0), + SD_BUS_PROPERTY("DeviceAllow", "a(ss)", property_get_device_allow, 0, 0), + SD_BUS_PROPERTY("TasksAccounting", "b", bus_property_get_bool, offsetof(CGroupContext, tasks_accounting), 0), +@@ -1137,6 +1139,9 @@ int bus_cgroup_set_property( + if (streq(name, "CPUSetAccounting")) + return bus_cgroup_set_boolean(u, name, &c->cpuset_accounting, CGROUP_MASK_CPUSET, message, flags, error); + ++ if (streq(name, "FreezerAccounting")) ++ return bus_cgroup_set_boolean(u, name, &c->freezer_accounting, CGROUP_MASK_FREEZER, message, flags, error); ++ + if (STR_IN_SET(name, "CPUSetCpus", "CPUSetMems")) { + const char *cpuset_str = NULL; + +@@ -1171,6 +1176,30 @@ int bus_cgroup_set_property( + if (streq(name, "CPUSetMemMigrate")) + return bus_cgroup_set_boolean(u, name, &c->cpuset_memory_migrate, CGROUP_MASK_CPUSET, message, flags, error); + ++ if (streq(name, "FreezerState")) { ++ const char *state = NULL; ++ ++ r = sd_bus_message_read(message, "s", &state); ++ if (r < 0) ++ return r; ++ ++ if (!UNIT_WRITE_FLAGS_NOOP(flags)) { ++ unit_invalidate_cgroup(u, CGROUP_MASK_FREEZER); ++ ++ if (c->freezer_state) { ++ free(c->freezer_state); ++ c->freezer_state = NULL; ++ } ++ ++ c->freezer_state = strdup(state); ++ if (!c->freezer_state) ++ return -ENOMEM; ++ ++ unit_write_settingf(u, flags, name, "FreezerState=%s", state); ++ } ++ return 1; ++ } ++ + if (streq(name, "TasksAccounting")) + return bus_cgroup_set_boolean(u, name, &c->tasks_accounting, CGROUP_MASK_PIDS, message, flags, error); + +diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c +index d6f45a7..7e57a32 100644 +--- a/src/core/dbus-manager.c ++++ b/src/core/dbus-manager.c +@@ -2911,6 +2911,7 @@ const sd_bus_vtable bus_manager_vtable = { + SD_BUS_PROPERTY("DefaultBlockIOAccounting", "b", bus_property_get_bool, offsetof(Manager, default_blockio_accounting), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("DefaultMemoryAccounting", "b", bus_property_get_bool, offsetof(Manager, default_memory_accounting), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("DefaultCpusetAccounting", "b", bus_property_get_bool, offsetof(Manager, default_cpuset_accounting), SD_BUS_VTABLE_PROPERTY_CONST), ++ SD_BUS_PROPERTY("DefaultFreezerAccounting", "b", bus_property_get_bool, offsetof(Manager, default_freezer_accounting), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("DefaultTasksAccounting", "b", bus_property_get_bool, offsetof(Manager, default_tasks_accounting), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("DefaultLimitCPU", "t", bus_property_get_rlimit, offsetof(Manager, rlimitRLIMIT_CPU), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("DefaultLimitCPUSoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimitRLIMIT_CPU), SD_BUS_VTABLE_PROPERTY_CONST), +diff --git a/src/core/load-fragment-gperf.gperf.in b/src/core/load-fragment-gperf.gperf.in +index 8600faa..eb68807 100644 +--- a/src/core/load-fragment-gperf.gperf.in ++++ b/src/core/load-fragment-gperf.gperf.in +@@ -213,6 +213,8 @@ + {{type}}.CPUSetMems, config_parse_cpuset_cpumems, 0, offsetof({{type}}, cgroup_context.cpuset_mems) + {{type}}.CPUSetCloneChildren, config_parse_bool, 0, offsetof({{type}}, cgroup_context.cpuset_clone_children) + {{type}}.CPUSetMemMigrate, config_parse_bool, 0, offsetof({{type}}, cgroup_context.cpuset_memory_migrate) ++{{type}}.FreezerAccounting, config_parse_bool, 0, offsetof({{type}}, cgroup_context.freezer_accounting) ++{{type}}.FreezerState, config_parse_freezer_state, 0, offsetof({{type}}, cgroup_context.freezer_state) + {{type}}.DeviceAllow, config_parse_device_allow, 0, offsetof({{type}}, cgroup_context) + {{type}}.DevicePolicy, config_parse_device_policy, 0, offsetof({{type}}, cgroup_context.device_policy) + {{type}}.IOAccounting, config_parse_bool, 0, offsetof({{type}}, cgroup_context.io_accounting) +diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c +index b0feac7..d01b6c4 100644 +--- a/src/core/load-fragment.c ++++ b/src/core/load-fragment.c +@@ -3933,6 +3933,39 @@ int config_parse_cpuset_cpumems( + return 0; + } + ++int config_parse_freezer_state( ++ const char *unit, ++ const char *filename, ++ unsigned line, ++ const char *section, ++ unsigned section_line, ++ const char *lvalue, ++ int ltype, ++ const char *rvalue, ++ void *data, ++ void *userdata) { ++ ++ char **freezer_state = data; ++ char *pinstr = NULL; ++ ++ assert(filename); ++ assert(lvalue); ++ assert(rvalue); ++ ++ if (!STR_IN_SET(rvalue, "FROZEN", "THAWED")) { ++ log_syntax(unit, LOG_ERR, filename, line, EINVAL, "Freezer state '%s' is invalid, Ignoring.", rvalue); ++ return 0; ++ } ++ ++ pinstr = strdup(rvalue); ++ if (!pinstr) ++ return log_oom(); ++ ++ free(*freezer_state); ++ *freezer_state = pinstr; ++ return 0; ++} ++ + int config_parse_tasks_max( + const char *unit, + const char *filename, +diff --git a/src/core/load-fragment.h b/src/core/load-fragment.h +index 405681f..d5437ea 100644 +--- a/src/core/load-fragment.h ++++ b/src/core/load-fragment.h +@@ -82,6 +82,7 @@ CONFIG_PARSER_PROTOTYPE(config_parse_cg_cpu_weight); + CONFIG_PARSER_PROTOTYPE(config_parse_cpu_shares); + CONFIG_PARSER_PROTOTYPE(config_parse_memory_limit); + CONFIG_PARSER_PROTOTYPE(config_parse_cpuset_cpumems); ++CONFIG_PARSER_PROTOTYPE(config_parse_freezer_state); + CONFIG_PARSER_PROTOTYPE(config_parse_tasks_max); + CONFIG_PARSER_PROTOTYPE(config_parse_delegate); + CONFIG_PARSER_PROTOTYPE(config_parse_managed_oom_mode); +diff --git a/src/core/main.c b/src/core/main.c +index e64882c..9f62b9d 100644 +--- a/src/core/main.c ++++ b/src/core/main.c +@@ -161,6 +161,7 @@ static bool arg_default_ip_accounting; + static bool arg_default_blockio_accounting; + static bool arg_default_memory_accounting; + static bool arg_default_cpuset_accounting; ++static bool arg_default_freezer_accounting; + static bool arg_default_tasks_accounting; + static TasksMax arg_default_tasks_max; + static sd_id128_t arg_machine_id; +@@ -683,6 +684,7 @@ static int parse_config_file(void) { + { "Manager", "DefaultBlockIOAccounting", config_parse_bool, 0, &arg_default_blockio_accounting }, + { "Manager", "DefaultMemoryAccounting", config_parse_bool, 0, &arg_default_memory_accounting }, + { "Manager", "DefaultCpusetAccounting", config_parse_bool, 0, &arg_default_cpuset_accounting }, ++ { "Manager", "DefaultFreezerAccounting", config_parse_bool, 0, &arg_default_freezer_accounting }, + { "Manager", "DefaultTasksAccounting", config_parse_bool, 0, &arg_default_tasks_accounting }, + { "Manager", "DefaultTasksMax", config_parse_tasks_max, 0, &arg_default_tasks_max }, + { "Manager", "CtrlAltDelBurstAction", config_parse_emergency_action, arg_system, &arg_cad_burst_action }, +@@ -765,6 +767,7 @@ static void set_manager_defaults(Manager *m) { + m->default_blockio_accounting = arg_default_blockio_accounting; + m->default_memory_accounting = arg_default_memory_accounting; + m->default_cpuset_accounting = arg_default_cpuset_accounting; ++ m->default_freezer_accounting = arg_default_freezer_accounting; + m->default_tasks_accounting = arg_default_tasks_accounting; + m->default_tasks_max = arg_default_tasks_max; + m->default_oom_policy = arg_default_oom_policy; +@@ -2461,6 +2464,7 @@ static void reset_arguments(void) { + arg_default_blockio_accounting = false; + arg_default_memory_accounting = MEMORY_ACCOUNTING_DEFAULT; + arg_default_cpuset_accounting = false; ++ arg_default_freezer_accounting = false; + arg_default_tasks_accounting = true; + arg_default_tasks_max = DEFAULT_TASKS_MAX; + arg_machine_id = (sd_id128_t) {}; +diff --git a/src/core/manager.h b/src/core/manager.h +index c4edacc..0196c52 100644 +--- a/src/core/manager.h ++++ b/src/core/manager.h +@@ -366,6 +366,7 @@ struct Manager { + bool default_cpu_accounting; + bool default_memory_accounting; + bool default_cpuset_accounting; ++ bool default_freezer_accounting; + bool default_io_accounting; + bool default_blockio_accounting; + bool default_tasks_accounting; +diff --git a/src/core/system.conf.in b/src/core/system.conf.in +index a0ef2bf..a44511b 100644 +--- a/src/core/system.conf.in ++++ b/src/core/system.conf.in +@@ -56,6 +56,7 @@ + #DefaultIPAccounting=no + #DefaultMemoryAccounting={{ 'yes' if MEMORY_ACCOUNTING_DEFAULT else 'no' }} + #DefaultCpusetAccounting= ++#DefaultFreezerAccounting=no + #DefaultTasksAccounting=yes + #DefaultTasksMax=80% + #DefaultLimitCPU= +diff --git a/src/core/unit.c b/src/core/unit.c +index 9ac41b4..eef05d0 100644 +--- a/src/core/unit.c ++++ b/src/core/unit.c +@@ -180,6 +180,7 @@ static void unit_init(Unit *u) { + cc->blockio_accounting = u->manager->default_blockio_accounting; + cc->memory_accounting = u->manager->default_memory_accounting; + cc->cpuset_accounting = u->manager->default_cpuset_accounting; ++ cc->freezer_accounting = u->manager->default_freezer_accounting; + cc->tasks_accounting = u->manager->default_tasks_accounting; + cc->ip_accounting = u->manager->default_ip_accounting; + +diff --git a/src/shared/bus-unit-util.c b/src/shared/bus-unit-util.c +index e1aed3d..a174e3e 100644 +--- a/src/shared/bus-unit-util.c ++++ b/src/shared/bus-unit-util.c +@@ -483,6 +483,7 @@ static int bus_append_cgroup_property(sd_bus_message *m, const char *field, cons + "TasksAccounting", + "IPAccounting", + "CPUSetAccounting", ++ "FreezerAccounting", + "CPUSetCloneChildren", + "CPUSetMemMigrate")) + return bus_append_parse_boolean(m, field, eq); +@@ -600,6 +601,16 @@ static int bus_append_cgroup_property(sd_bus_message *m, const char *field, cons + return 1; + } + ++ if (streq(field, "FreezerState")) { ++ if (STR_IN_SET(eq, "FROZEN", "THAWED")) ++ r = sd_bus_message_append(m, "(sv)", field, "s", eq); ++ else ++ r = -EINVAL; ++ if (r < 0) ++ return bus_log_create_error(r); ++ return 1; ++ } ++ + if (streq(field, "CPUQuota")) { + if (isempty(eq)) + r = sd_bus_message_append(m, "(sv)", "CPUQuotaPerSecUSec", "t", USEC_INFINITY); +diff --git a/src/test/meson.build b/src/test/meson.build +index 34dbd6d..be99212 100644 +--- a/src/test/meson.build ++++ b/src/test/meson.build +@@ -525,6 +525,12 @@ tests += + , + core_includes, + ++ files('test-cgroup-freezer.c'), ++ libcore, ++ libshared, ++ , ++ core_includes, ++ + files('test-cgroup-unit-default.c'), + libcore, + libshared, +diff --git a/src/test/test-cgroup-freezer.c b/src/test/test-cgroup-freezer.c +new file mode 100644 +index 0000000..a533d16 +--- /dev/null ++++ b/src/test/test-cgroup-freezer.c +@@ -0,0 +1,43 @@ ++/* SPDX-License-Identifier: LGPL-2.1+ */ ++ ++#include "load-fragment.h" ++#include "string-util.h" ++ ++static void test_config_parse_freezer_state(void) { ++ /* int config_parse_freezer_state( ++ const char *unit, ++ const char *filename, ++ unsigned line, ++ const char *section, ++ unsigned section_line, ++ const char *lvalue, ++ int ltype, ++ const char *rvalue, ++ void *data, ++ void *userdata) */ ++ int r; ++ _cleanup_free_ char *pstate = NULL; ++ ++ r = config_parse_freezer_state(NULL, "fake", 1, "section", 1, "FreezerState", 0, "FROZEN", &pstate, NULL); ++ assert_se(r >= 0); ++ assert_se(streq(pstate, "FROZEN")); ++ ++ pstate = mfree(pstate); ++ r = config_parse_freezer_state(NULL, "fake", 1, "section", 1, "FreezerState", 0, "THAWED", &pstate, NULL); ++ assert_se(r >= 0); ++ assert_se(streq(pstate, "THAWED")); ++ ++ pstate = mfree(pstate); ++ r = config_parse_freezer_state(NULL, "fake", 1, "section", 1, "FreezerState", 0, "test", &pstate, NULL); ++ assert_se(r >= 0); ++ assert_se(!pstate); ++ ++ r = config_parse_freezer_state(NULL, "fake", 1, "section", 1, "FreezerState", 0, "", &pstate, NULL); ++ assert_se(r >= 0); ++ assert_se(!pstate); ++} ++ ++int main(int argc, char *argv){ ++ test_config_parse_freezer_state(); ++ return 0; ++} +diff --git a/src/test/test-cgroup-mask.c b/src/test/test-cgroup-mask.c +index e969569..e76f252 100644 +--- a/src/test/test-cgroup-mask.c ++++ b/src/test/test-cgroup-mask.c +@@ -56,6 +56,7 @@ TEST_RET(cgroup_mask, .sd_booted = true) { + m->default_cpu_accounting = + m->default_memory_accounting = + m->default_cpuset_accounting = ++ m->default_freezer_accounting = + m->default_blockio_accounting = + m->default_io_accounting = + m->default_tasks_accounting = false; +@@ -141,7 +142,7 @@ static void test_cg_mask_to_string_one(CGroupMask mask, const char *t) { + + TEST(cg_mask_to_string) { + test_cg_mask_to_string_one(0, NULL); +- test_cg_mask_to_string_one(_CGROUP_MASK_ALL, "cpu cpuacct cpuset2 io blkio memory devices pids cpuset bpf-firewall bpf-devices bpf-foreign bpf-socket-bind bpf-restrict-network-interfaces"); ++ test_cg_mask_to_string_one(_CGROUP_MASK_ALL, "cpu cpuacct cpuset2 io blkio memory devices pids cpuset freezer bpf-firewall bpf-devices bpf-foreign bpf-socket-bind bpf-restrict-network-interfaces"); + test_cg_mask_to_string_one(CGROUP_MASK_CPU, "cpu"); + test_cg_mask_to_string_one(CGROUP_MASK_CPUACCT, "cpuacct"); + test_cg_mask_to_string_one(CGROUP_MASK_CPUSET2, "cpuset2"); +diff --git a/test/fuzz/fuzz-unit-file/directives-all.service b/test/fuzz/fuzz-unit-file/directives-all.service +index dcf99e1..1a5cd5d 100644 +--- a/test/fuzz/fuzz-unit-file/directives-all.service ++++ b/test/fuzz/fuzz-unit-file/directives-all.service +@@ -115,6 +115,8 @@ FileDescriptorName= + FileDescriptorStoreMax= + ForceUnmount= + FreeBind= ++FreezerAccounting= ++FreezerState= + Group= + GuessMainPID= + IOAccounting= +-- +2.33.0 +
View file
_service:tar_scm:core-cgroup-support-memorysw.patch
Added
@@ -0,0 +1,186 @@ +From cfb8a3cf09d9a958388ca1181bb92d9f77ab100e Mon Sep 17 00:00:00 2001 +From: licunlong <licunlong1@huawei.com> +Date: Thu, 6 May 2021 09:38:54 +0800 +Subject: PATCH core-cgroup: support memorysw + +Upstream systemd dosen't support setting memory.memsw.limit_in_bytes. +This patch enables setting memory.memsw.limit_in_bytes by MemoryMemswLimit. +--- + src/core/cgroup.c | 17 +++++++++++++++-- + src/core/cgroup.h | 1 + + src/core/dbus-cgroup.c | 4 ++++ + src/core/load-fragment-gperf.gperf.in | 1 + + src/core/load-fragment.c | 10 ++++++---- + src/shared/bus-print-properties.c | 2 +- + src/shared/bus-unit-util.c | 1 + + test/fuzz/fuzz-unit-file/directives-all.service | 1 + + 8 files changed, 30 insertions(+), 7 deletions(-) + +diff --git a/src/core/cgroup.c b/src/core/cgroup.c +index 7d1e59b..f827219 100644 +--- a/src/core/cgroup.c ++++ b/src/core/cgroup.c +@@ -154,6 +154,7 @@ void cgroup_context_init(CGroupContext *c) { + .memory_zswap_max = CGROUP_LIMIT_MAX, + + .memory_limit = CGROUP_LIMIT_MAX, ++ .memory_memsw_limit = CGROUP_LIMIT_MAX, + + .io_weight = CGROUP_WEIGHT_INVALID, + .startup_io_weight = CGROUP_WEIGHT_INVALID, +@@ -481,6 +482,7 @@ void cgroup_context_dump(Unit *u, FILE* f, const char *prefix) { + "%sMemorySwapMax: %" PRIu64 "%s\n" + "%sMemoryZSwapMax: %" PRIu64 "%s\n" + "%sMemoryLimit: %" PRIu64 "\n" ++ "%sMemoryMemswLimit=%" PRIu64 "\n" + "%sCPUSetCpus=%s\n" + "%sCPUSetMems=%s\n" + "%sCPUSetCloneChildren=%s\n" +@@ -525,6 +527,7 @@ void cgroup_context_dump(Unit *u, FILE* f, const char *prefix) { + prefix, c->memory_swap_max, format_cgroup_memory_limit_comparison(cde, sizeof(cde), u, "MemorySwapMax"), + prefix, c->memory_zswap_max, format_cgroup_memory_limit_comparison(cde, sizeof(cde), u, "MemoryZSwapMax"), + prefix, c->memory_limit, ++ prefix, c->memory_memsw_limit, + prefix, c->cpuset_cpus, + prefix, c->cpuset_mems, + prefix, yes_no(c->cpuset_clone_children), +@@ -1673,14 +1676,17 @@ static void cgroup_context_apply( + + } else { + char bufDECIMAL_STR_MAX(uint64_t) + 1; +- uint64_t val; ++ uint64_t val, sw_val; + + if (unit_has_unified_memory_config(u)) { + val = c->memory_max; ++ sw_val = CGROUP_LIMIT_MAX; + if (val != CGROUP_LIMIT_MAX) + log_cgroup_compat(u, "Applying MemoryMax=%" PRIu64 " as MemoryLimit=", val); +- } else ++ } else { + val = c->memory_limit; ++ sw_val = c->memory_memsw_limit; ++ } + + if (val == CGROUP_LIMIT_MAX) + strncpy(buf, "-1\n", sizeof(buf)); +@@ -1688,6 +1694,12 @@ static void cgroup_context_apply( + xsprintf(buf, "%" PRIu64 "\n", val); + + (void) set_attribute_and_warn(u, "memory", "memory.limit_in_bytes", buf); ++ ++ if (sw_val == CGROUP_LIMIT_MAX) ++ strncpy(buf, "-1\n", sizeof(buf)); ++ else ++ xsprintf(buf, "%" PRIu64 "\n", sw_val); ++ (void) set_attribute_and_warn(u, "memory", "memory.memsw.limit_in_bytes", buf); + } + } + +@@ -1883,6 +1895,7 @@ static CGroupMask unit_get_cgroup_mask(Unit *u) { + + if (c->memory_accounting || + c->memory_limit != CGROUP_LIMIT_MAX || ++ c->memory_memsw_limit != CGROUP_LIMIT_MAX || + unit_has_unified_memory_config(u)) + mask |= CGROUP_MASK_MEMORY; + +diff --git a/src/core/cgroup.h b/src/core/cgroup.h +index 2251548..313b63c 100644 +--- a/src/core/cgroup.h ++++ b/src/core/cgroup.h +@@ -187,6 +187,7 @@ struct CGroupContext { + LIST_HEAD(CGroupBlockIODeviceBandwidth, blockio_device_bandwidths); + + uint64_t memory_limit; ++ uint64_t memory_memsw_limit; + + CGroupDevicePolicy device_policy; + LIST_HEAD(CGroupDeviceAllow, device_allow); +diff --git a/src/core/dbus-cgroup.c b/src/core/dbus-cgroup.c +index c51a8b7..e54657e 100644 +--- a/src/core/dbus-cgroup.c ++++ b/src/core/dbus-cgroup.c +@@ -470,6 +470,7 @@ const sd_bus_vtable bus_cgroup_vtable = { + SD_BUS_PROPERTY("MemorySwapMax", "t", NULL, offsetof(CGroupContext, memory_swap_max), 0), + SD_BUS_PROPERTY("MemoryZSwapMax", "t", NULL, offsetof(CGroupContext, memory_zswap_max), 0), + SD_BUS_PROPERTY("MemoryLimit", "t", NULL, offsetof(CGroupContext, memory_limit), 0), ++ SD_BUS_PROPERTY("MemoryMemswLimit", "t", NULL, offsetof(CGroupContext, memory_memsw_limit), 0), + SD_BUS_PROPERTY("CPUSetAccounting", "b", bus_property_get_bool, offsetof(CGroupContext, cpuset_accounting), 0), + SD_BUS_PROPERTY("CPUSetCpus", "s", NULL, offsetof(CGroupContext, cpuset_cpus), 0), + SD_BUS_PROPERTY("CPUSetMems", "s", NULL, offsetof(CGroupContext, cpuset_mems), 0), +@@ -1093,6 +1094,9 @@ int bus_cgroup_set_property( + if (streq(name, "MemoryLimit")) + return bus_cgroup_set_memory(u, name, &c->memory_limit, message, flags, error); + ++ if (streq(name, "MemoryMemswLimit")) ++ return bus_cgroup_set_memory(u, name, &c->memory_memsw_limit, message, flags, error); ++ + if (streq(name, "MemoryMinScale")) { + r = bus_cgroup_set_memory_protection_scale(u, name, &c->memory_min, message, flags, error); + if (r > 0) +diff --git a/src/core/load-fragment-gperf.gperf.in b/src/core/load-fragment-gperf.gperf.in +index eb68807..c1bc771 100644 +--- a/src/core/load-fragment-gperf.gperf.in ++++ b/src/core/load-fragment-gperf.gperf.in +@@ -208,6 +208,7 @@ + {{type}}.MemorySwapMax, config_parse_memory_limit, 0, offsetof({{type}}, cgroup_context) + {{type}}.MemoryZSwapMax, config_parse_memory_limit, 0, offsetof({{type}}, cgroup_context) + {{type}}.MemoryLimit, config_parse_memory_limit, 0, offsetof({{type}}, cgroup_context) ++{{type}}.MemoryMemswLimit, config_parse_memory_limit, 0, offsetof({{type}}, cgroup_context) + {{type}}.CPUSetAccounting, config_parse_bool, 0, offsetof({{type}}, cgroup_context.cpuset_accounting) + {{type}}.CPUSetCpus, config_parse_cpuset_cpumems, 0, offsetof({{type}}, cgroup_context.cpuset_cpus) + {{type}}.CPUSetMems, config_parse_cpuset_cpumems, 0, offsetof({{type}}, cgroup_context.cpuset_mems) +diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c +index d01b6c4..8d2171f 100644 +--- a/src/core/load-fragment.c ++++ b/src/core/load-fragment.c +@@ -3854,6 +3854,8 @@ int config_parse_memory_limit( + c->memory_swap_max = bytes; + else if (streq(lvalue, "MemoryZSwapMax")) + c->memory_zswap_max = bytes; ++ else if (streq(lvalue, "MemoryMemswLimit")) ++ c->memory_memsw_limit = bytes; + else if (streq(lvalue, "MemoryLimit")) { + log_syntax(unit, LOG_WARNING, filename, line, 0, + "Unit uses MemoryLimit=; please use MemoryMax= instead. Support for MemoryLimit= will be removed soon."); +diff --git a/src/shared/bus-print-properties.c b/src/shared/bus-print-properties.c +index 9369866..9e26b71 100644 +--- a/src/shared/bus-print-properties.c ++++ b/src/shared/bus-print-properties.c +@@ -162,7 +162,7 @@ static int bus_print_property(const char *name, const char *expected_value, sd_b + + bus_print_property_value(name, expected_value, flags, "not set"); + +- else if ((STR_IN_SET(name, "DefaultMemoryLow", "DefaultMemoryMin", "MemoryLow", "MemoryHigh", "MemoryMax", "MemorySwapMax", "MemoryZSwapMax", "MemoryLimit", "MemoryAvailable") && u == CGROUP_LIMIT_MAX) || ++ else if ((STR_IN_SET(name, "DefaultMemoryLow", "DefaultMemoryMin", "MemoryLow", "MemoryHigh", "MemoryMax", "MemorySwapMax", "MemoryZSwapMax", "MemoryLimit", "MemoryMemswLimit", "MemoryAvailable") && u == CGROUP_LIMIT_MAX) || + (STR_IN_SET(name, "TasksMax", "DefaultTasksMax") && u == UINT64_MAX) || + (startswith(name, "Limit") && u == UINT64_MAX) || + (startswith(name, "DefaultLimit") && u == UINT64_MAX)) +diff --git a/src/shared/bus-unit-util.c b/src/shared/bus-unit-util.c +index a174e3e..984dfa9 100644 +--- a/src/shared/bus-unit-util.c ++++ b/src/shared/bus-unit-util.c +@@ -547,6 +547,7 @@ static int bus_append_cgroup_property(sd_bus_message *m, const char *field, cons + "MemorySwapMax", + "MemoryZSwapMax", + "MemoryLimit", ++ "MemoryMemswLimit", + "TasksMax")) { + + if (streq(eq, "infinity")) { +diff --git a/test/fuzz/fuzz-unit-file/directives-all.service b/test/fuzz/fuzz-unit-file/directives-all.service +index 1a5cd5d..59c693d 100644 +--- a/test/fuzz/fuzz-unit-file/directives-all.service ++++ b/test/fuzz/fuzz-unit-file/directives-all.service +@@ -166,6 +166,7 @@ MemoryHigh= + MemoryLimit= + MemoryLow= + MemoryMax= ++MemoryMemswLimit= + MemorySwapMax= + MemoryZSwapMax= + MessageQueueMaxMessages= +-- +2.33.0 +
View file
_service:tar_scm:core-update-arg_default_rlimit-in-bump_rlimit.patch
Added
@@ -0,0 +1,24 @@ +From a80954ddf69d90d3b02ab62fb025534862069dc3 Mon Sep 17 00:00:00 2001 +From: licunlong <licunlong1@huawei.com> +Date: Wed, 24 Jun 2020 17:23:03 +0800 +Subject: PATCH core-update-arg_default_rlimit-in-bump_rlimit + +--- + src/core/system.conf.in | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/core/system.conf.in b/src/core/system.conf.in +index a58f65a..4762669 100644 +--- a/src/core/system.conf.in ++++ b/src/core/system.conf.in +@@ -61,7 +61,7 @@ + #DefaultLimitNOFILE=1024:{{HIGH_RLIMIT_NOFILE}} + #DefaultLimitAS= + #DefaultLimitNPROC= +-#DefaultLimitMEMLOCK=8M ++DefaultLimitMEMLOCK=64M + #DefaultLimitLOCKS= + #DefaultLimitSIGPENDING= + #DefaultLimitMSGQUEUE= +-- +2.23.0
View file
_service:tar_scm:delay-to-restart-when-a-service-can-not-be-auto-restarted.patch
Added
@@ -0,0 +1,44 @@ +From 9315c29e4fdfa19c90bb483a364b017881f5cef7 Mon Sep 17 00:00:00 2001 +From: huangkaibin <huangkaibin@huawei.com> +Date: Sat, 21 Apr 2018 17:18:19 +0800 +Subject: PATCH systemd-core: Delay to restart when a service can not be + auto-restarted when there is one STOP_JOB for the service + +When a service current has a STOP job has not scheduled yet, +and also if the service is already scheduled with an auto-restart +with restart-second configured as 0, the service will not be restarted successfully, +and systemd will go into an endless loop to restart the service. +This is because restart-second is 0 and timer task has higher priority than IO tasks when there priority +is same(both with 0), so the STOP job has no chance to be scheduled, and systemd will go into the endless loop +to handle the time task. +This patch fix this problem by delaying 1 second to restart the service to cause STOP job to be scheduled. +--- + src/core/service.c | 6 +++++- + 1 file changed, 5 insertions(+), 1 deletion(-) + +diff --git a/src/core/service.c b/src/core/service.c +index e368ec8..9b4b5b1 100644 +--- a/src/core/service.c ++++ b/src/core/service.c +@@ -2262,13 +2262,17 @@ fail: + static void service_enter_restart(Service *s) { + _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; + int r; ++ int restart_usec; + + assert(s); + + if (unit_has_job_type(UNIT(s), JOB_STOP)) { + /* Don't restart things if we are going down anyway */ + log_unit_info(UNIT(s), "Stop job pending for unit, skipping automatic restart."); +- return; ++ restart_usec = (s->restart_usec == 0) ? 1*USEC_PER_SEC : s->restart_usec; ++ r = service_arm_timer(s, /* relative= */ false, usec_add(now(CLOCK_MONOTONIC), restart_usec)); ++ if (r < 0) ++ goto fail; + } + + /* Any units that are bound to this service must also be +-- +1.8.3.1 +
View file
_service:tar_scm:delete-journal-files-except-system.journal-when-jour.patch
Added
@@ -0,0 +1,184 @@ +From 02d47bd2108d46cf9790500a7568a7523df485f9 Mon Sep 17 00:00:00 2001 +From: xujing <xujing125@huawei.com> +Date: Fri, 26 Aug 2022 20:32:37 +0800 +Subject: PATCH delete journal files except system.journal when journal~ + is generated + +In the case of time change and system panic, the function of invoking +sd_journal_next to obtain logs may not meet expectations(rsyslog cannot obtain +logs). Therefore, when the journal~ file is generated, delete all journal files +except system.journal, to ensure that the sd_journal_next function meets user +expectations. +--- + meson.build | 2 ++ + src/basic/dirent-util.c | 24 +++++++++++++++++ + src/basic/dirent-util.h | 2 ++ + src/libsystemd/sd-journal/journal-file.c | 34 ++++++++++++++++++++++++ + src/libsystemd/sd-journal/sd-journal.c | 22 --------------- + 5 files changed, 62 insertions(+), 22 deletions(-) + +diff --git a/meson.build b/meson.build +index 0372b17..8b1ce23 100644 +--- a/meson.build ++++ b/meson.build +@@ -2001,6 +2001,8 @@ basic_includes = include_directories( + 'src/basic', + 'src/fundamental', + 'src/systemd', ++ 'src/libsystemd/sd-id128', ++ 'src/libsystemd/sd-journal', + '.') + + libsystemd_includes = basic_includes, include_directories( +diff --git a/src/basic/dirent-util.c b/src/basic/dirent-util.c +index 17df6a2..e362554 100644 +--- a/src/basic/dirent-util.c ++++ b/src/basic/dirent-util.c +@@ -7,6 +7,8 @@ + #include "path-util.h" + #include "stat-util.h" + #include "string-util.h" ++#include "id128-util.h" ++#include "syslog-util.h" + + int dirent_ensure_type(int dir_fd, struct dirent *de) { + STRUCT_STATX_DEFINE(sx); +@@ -65,6 +67,28 @@ bool dirent_is_file_with_suffix(const struct dirent *de, const char *suffix) { + return endswith(de->d_name, suffix); + } + ++bool dirent_is_journal_subdir(const struct dirent *de) { ++ const char *e, *n; ++ assert(de); ++ ++ /* returns true if the specified directory entry looks like a directory that might contain journal ++ * files we might be interested in, i.e. is either a 128bit ID or a 128bit ID suffixed by a ++ * namespace. */ ++ ++ if (!IN_SET(de->d_type, DT_DIR, DT_LNK, DT_UNKNOWN)) ++ return false; ++ ++ e = strchr(de->d_name, '.'); ++ if (!e) ++ return id128_is_valid(de->d_name); /* No namespace */ ++ ++ n = strndupa(de->d_name, e - de->d_name); ++ if (!id128_is_valid(n)) ++ return false; ++ ++ return log_namespace_name_valid(e + 1); ++} ++ + struct dirent *readdir_ensure_type(DIR *d) { + int r; + +diff --git a/src/basic/dirent-util.h b/src/basic/dirent-util.h +index 0f1fb23..2effce3 100644 +--- a/src/basic/dirent-util.h ++++ b/src/basic/dirent-util.h +@@ -12,6 +12,8 @@ bool dirent_is_file(const struct dirent *de) _pure_; + bool dirent_is_file_with_suffix(const struct dirent *de, const char *suffix) _pure_; + int dirent_ensure_type(int dir_fd, struct dirent *de); + ++bool dirent_is_journal_subdir(const struct dirent *de); ++ + struct dirent *readdir_ensure_type(DIR *d); + struct dirent *readdir_no_dot(DIR *dirp); + +diff --git a/src/libsystemd/sd-journal/journal-file.c b/src/libsystemd/sd-journal/journal-file.c +index 9e6bf6e..561a705 100644 +--- a/src/libsystemd/sd-journal/journal-file.c ++++ b/src/libsystemd/sd-journal/journal-file.c +@@ -38,6 +38,7 @@ + #include "sync-util.h" + #include "user-util.h" + #include "xattr-util.h" ++#include "dirent-util.h" + + #define DEFAULT_DATA_HASH_TABLE_SIZE (2047ULL*sizeof(HashItem)) + #define DEFAULT_FIELD_HASH_TABLE_SIZE (333ULL*sizeof(HashItem)) +@@ -4069,8 +4070,35 @@ int journal_file_archive(JournalFile *f, char **ret_previous_path) { + return 0; + } + ++static void delete_dumped_journal_files(const char *path) { ++ _cleanup_closedir_ DIR *d = NULL; ++ ++ d = opendir(path); ++ if (!d) ++ return; ++ ++ FOREACH_DIRENT_ALL(de, d, return) { ++ if (IN_SET(de->d_type, DT_REG, DT_LNK, DT_UNKNOWN) && ++ (endswith(de->d_name, ".journal") || ++ endswith(de->d_name, ".journal~")) && ++ strcmp(de->d_name, "system.journal") != 0) ++ (void) unlinkat_deallocate(dirfd(d), de->d_name, 0); ++ ++ if (dirent_is_journal_subdir(de)) { ++ _cleanup_free_ char *sub_path = NULL; ++ ++ sub_path = path_join(path, de->d_name); ++ if (!sub_path) ++ continue; ++ ++ delete_dumped_journal_files(sub_path); ++ } ++ } ++} ++ + int journal_file_dispose(int dir_fd, const char *fname) { + _cleanup_free_ char *p = NULL; ++ dual_timestamp boot_timestamp; + + assert(fname); + +@@ -4091,6 +4119,12 @@ int journal_file_dispose(int dir_fd, const char *fname) { + if (renameat(dir_fd, fname, dir_fd, p) < 0) + return -errno; + ++ dual_timestamp_get(&boot_timestamp); ++ if (boot_timestamp.monotonic < 10*USEC_PER_MINUTE) { ++ delete_dumped_journal_files("/var/log/journal"); ++ return 0; ++ } ++ + return 0; + } + +diff --git a/src/libsystemd/sd-journal/sd-journal.c b/src/libsystemd/sd-journal/sd-journal.c +index f6090dd..8b83f65 100644 +--- a/src/libsystemd/sd-journal/sd-journal.c ++++ b/src/libsystemd/sd-journal/sd-journal.c +@@ -1510,28 +1510,6 @@ static bool dirent_is_journal_file(const struct dirent *de) { + endswith(de->d_name, ".journal~"); + } + +-static bool dirent_is_journal_subdir(const struct dirent *de) { +- const char *e, *n; +- assert(de); +- +- /* returns true if the specified directory entry looks like a directory that might contain journal +- * files we might be interested in, i.e. is either a 128bit ID or a 128bit ID suffixed by a +- * namespace. */ +- +- if (!IN_SET(de->d_type, DT_DIR, DT_LNK, DT_UNKNOWN)) +- return false; +- +- e = strchr(de->d_name, '.'); +- if (!e) +- return id128_is_valid(de->d_name); /* No namespace */ +- +- n = strndupa_safe(de->d_name, e - de->d_name); +- if (!id128_is_valid(n)) +- return false; +- +- return log_namespace_name_valid(e + 1); +-} +- + static int directory_open(sd_journal *j, const char *path, DIR **ret) { + DIR *d; + +-- +2.33.0 +
View file
_service:tar_scm:disable-initialize_clock.patch
Added
@@ -0,0 +1,65 @@ +From fbd28b3b40701f1fda29707dfa09d1e481c4162c Mon Sep 17 00:00:00 2001 +From: hexiaowen<hexiaowen@huawei.com> +Date: Tue, 9 Jul 2019 19:13:43 +0800 +Subject: PATCH delete clock_apply_epoch + +resolved: apply epoch to system time from PID 1 + +For use in timesyncd we already defined a compile-time "epoch" value, which is based on the mtime of the NEWS file, and +specifies a point in time we know lies in the past at runtime. timesyncd uses this to filter out nonsensical timestamp +file data, and bump the system clock to a time that is after the build time of systemd. This patch adds similar bumping +code to earliest PID 1 initialization, so that the system never continues operation with a clock that is in the 1970ies +or even 1930s. we think it is ok when current system time is before build time. + +And, don't restore time when systemd-timesyncd started. + +--- + src/core/main.c | 12 ------------ + src/timesync/timesyncd.c | 8 -------- + 2 files changed, 20 deletions(-) + +diff --git a/src/core/main.c b/src/core/main.c +index 4051a91..c6d16b2 100644 +--- a/src/core/main.c ++++ b/src/core/main.c +@@ -1627,18 +1627,6 @@ static void initialize_clock(void) { + */ + (void) clock_reset_timewarp(); + +- ClockChangeDirection change_dir; +- r = clock_apply_epoch(&change_dir); +- if (r > 0 && change_dir == CLOCK_CHANGE_FORWARD) +- log_info("System time before build time, advancing clock."); +- else if (r > 0 && change_dir == CLOCK_CHANGE_BACKWARD) +- log_info("System time is further ahead than %s after build time, resetting clock to build time.", +- FORMAT_TIMESPAN(CLOCK_VALID_RANGE_USEC_MAX, USEC_PER_DAY)); +- else if (r < 0 && change_dir == CLOCK_CHANGE_FORWARD) +- log_error_errno(r, "Current system time is before build time, but cannot correct: %m"); +- else if (r < 0 && change_dir == CLOCK_CHANGE_BACKWARD) +- log_error_errno(r, "Current system time is further ahead %s after build time, but cannot correct: %m", +- FORMAT_TIMESPAN(CLOCK_VALID_RANGE_USEC_MAX, USEC_PER_DAY)); + } + + static void apply_clock_update(void) { +diff --git a/src/timesync/timesyncd.c b/src/timesync/timesyncd.c +index e60742c..efe56fd 100644 +--- a/src/timesync/timesyncd.c ++++ b/src/timesync/timesyncd.c +@@ -121,14 +121,6 @@ static int load_clock_timestamp(uid_t uid, gid_t gid) { + if (ct > min) + return 0; + +- /* Not that it matters much, but we actually restore the clock to n+1 here rather than n, simply +- * because we read n as time previously already and we want to progress here, i.e. not report the +- * same time again. */ +- if (clock_settime(CLOCK_REALTIME, TIMESPEC_STORE(min+1)) < 0) { +- log_warning_errno(errno, "Failed to restore system clock, ignoring: %m"); +- return 0; +- } +- + log_struct(LOG_INFO, + "MESSAGE_ID=" SD_MESSAGE_TIME_BUMP_STR, + "REALTIME_USEC=" USEC_FMT, min+1, +-- +2.33.0 +
View file
_service:tar_scm:fix-capsh-drop-but-ping-success.patch
Added
@@ -0,0 +1,29 @@ +From c20f91b6d99ac98a7d883e77f609e52482fe7c3b Mon Sep 17 00:00:00 2001 +From: openEuler Buildteam <buildteam@openeuler.org> +Date: Fri, 17 Jan 2020 23:00:49 +0800 +Subject: PATCH change +fix capsh --drop=cap_net_raw -- -c "/bin/ping -c 1 localhost" +but ping success, the reson is github issue. + +https://github.com/systemd/systemd/pull/13141/commits/0a8ce60ee87de9a817284b31c6ccba062664057f + +--- + sysctl.d/50-default.conf | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/sysctl.d/50-default.conf b/sysctl.d/50-default.conf +index 41bd1f9..4d9bef8 100644 +--- a/sysctl.d/50-default.conf ++++ b/sysctl.d/50-default.conf +@@ -36,7 +36,7 @@ net.ipv4.conf.all.promote_secondaries = 1 + # #define GID_T_MAX (((gid_t)~0U) >> 1) + # That's not so bad because values between 2^31 and 2^32-1 are reserved on + # systemd-based systems anyway: https://systemd.io/UIDS-GIDS#summary +--net.ipv4.ping_group_range = 0 2147483647 ++net.ipv4.ping_group_range = 1 0 + + # Fair Queue CoDel packet scheduler to fight bufferbloat + -net.core.default_qdisc = fq_codel +-- +1.8.3.1 +
View file
_service:tar_scm:fix-journal-file-descriptors-leak-problems.patch
Added
@@ -0,0 +1,53 @@ +From 4f8cec1924bf00532f5350d9a4d7af8e853241fe Mon Sep 17 00:00:00 2001 +From: huangkaibin <huangkaibin@huawei.com> +Date: Thu, 28 Jun 2018 20:23:45 +0800 +Subject: PATCH systemd-journald: Fix journal file descriptors leak problems. + +Journal files opened and then be removed by external programs(for example, the journal rotation +of systemd-journald will removed jounal files) before journal directory notify watching is added +will not be closed properly. This patch fix this problem by removing and closing these deleted journal files +after notify watching is added. +--- + src/libsystemd/sd-journal/sd-journal.c | 19 +++++++++++++++++++ + 1 file changed, 19 insertions(+) + +diff --git a/src/libsystemd/sd-journal/sd-journal.c b/src/libsystemd/sd-journal/sd-journal.c +index 5728c53..1238652 100644 +--- a/src/libsystemd/sd-journal/sd-journal.c ++++ b/src/libsystemd/sd-journal/sd-journal.c +@@ -1584,6 +1584,17 @@ fail: + log_debug_errno(errno, "Failed to enumerate directory %s, ignoring: %m", m->path); + } + ++static void remove_nonexistent_journal_files(sd_journal *j) { ++ JournalFile *f = NULL; ++ ORDERED_HASHMAP_FOREACH(f, j->files) { ++ if(f->path && access(f->path, F_OK) < 0) { ++ log_debug("Remove not-existed file from the journal map: %s", f->path); ++ /*Its OK to remove entry from the hashmap although we are iterating on it.*/ ++ remove_file_real(j, f); ++ } ++ } ++} ++ + static void directory_watch(sd_journal *j, Directory *m, int fd, uint32_t mask) { + int r; + +@@ -1612,6 +1623,14 @@ static void directory_watch(sd_journal *j, Directory *m, int fd, uint32_t mask) + (void) inotify_rm_watch(j->inotify_fd, m->wd); + m->wd = -1; + } ++ ++ /* ++ * Before event watching, there were some files opened and if some of these opened files were ++ * deleted due to the journal rotation of systemd-jounald, they will become leaking files and will ++ * never be closed until the process exited. ++ * So here we remove these deleted files from the journal after event watching. ++ */ ++ remove_nonexistent_journal_files(j); + } + + static int add_directory( +-- +2.27.0 +
View file
_service:tar_scm:fix-two-VF-virtual-machines-have-same-mac-address.patch
Added
@@ -0,0 +1,45 @@ +From: fangxiuning <fangxiuning@huawei.com> +Date: Thu, 5 Sep 2019 07:40:41 +0800 +Subject: fix two vf virtual machine has same mac address +through 82599,hns3 physical network cart vf two virtual machine, +two virtual machine have the same mac address. + +MACAddressPolicy= +The policy by which the MAC address should be set. The available +policies are: + +persistent +If the hardware has a persistent MAC address, as most hardware should, +and if it is used by the kernel, nothing is done. Otherwise, a new MAC +address is generated which is guaranteed to be the same on every boot +for the given machine and the given device, but which is otherwise random. +This feature depends on ID_NET_NAME_* properties to exist for the link. +On hardware where these properties are not set, the generation of a +persistent MAC address will fail. + + +random +If the kernel is using a random MAC address, nothing is done. Otherwise, +a new address is randomly generated each time the device appears, +typically at boot. Either way, the random address will have the "unicast" +and "locally administered" bits set. + +none +Keeps the MAC address assigned by the kernel. +--- + network/99-default.link | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/network/99-default.link b/network/99-default.link +index dc7a42bf58..2b8f46a84c 100644 +--- a/network/99-default.link ++++ b/network/99-default.link +@@ -13,4 +13,4 @@ OriginalName=* + Link + NamePolicy=keep kernel database onboard slot path + AlternativeNamesPolicy=database onboard slot path +-MACAddressPolicy=persistent ++MACAddressPolicy=none +-- +2.23.0 +
View file
_service:tar_scm:fuser-print-umount-message-to-reboot-umount-msg.patch
Added
@@ -0,0 +1,228 @@ +From 224b51420b0e3b62cda4bb16f31c6d28e96c7123 Mon Sep 17 00:00:00 2001 +From: sunshihao <sunshihao@huawei.com> +Date: Mon, 25 Jan 2021 14:42:23 +0800 +Subject: PATCH fuser: print umount info to /.reboot-umount-msg.log + +The patch tries to save which processes holds the mountpoint +persistently to /.reboot-umount-msg.log, when the system is +suspended during system restart. + +This patch change the value of DefaultDFXReboot that is set in +/etc/systemd/system.conf file from no to yes.The systemd reboot +feature will open when the process start. + +Signed-off-by: sunshihao <sunshihao@huawei.com> +Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com> +Signed-off-by: lixiaokeng <lixiaokeng@huawei.com> +--- + src/core/fuser.c | 57 +++++++++++++++++++++++++++++++++++++---- + src/core/fuser.h | 3 +++ + src/core/job.c | 38 +++++++++++++++++++++++++++ + src/core/system.conf.in | 2 +- + 4 files changed, 94 insertions(+), 6 deletions(-) + +diff --git a/src/core/fuser.c b/src/core/fuser.c +index e943469..94a0812 100644 +--- a/src/core/fuser.c ++++ b/src/core/fuser.c +@@ -383,6 +383,8 @@ static void print_matches(const struct name *name) { + static char P_cmd_longMAX_COMM_LEN; + char cmd_pathPATH_MAX; + int r = 0; ++ FILE *fp = NULL; ++ int flag = 0; + + if (name == NULL) { + manager_status_printf(NULL, STATUS_TYPE_NORMAL, NULL, +@@ -390,11 +392,29 @@ static void print_matches(const struct name *name) { + return; + } + ++ /* Write the content in the back of previous one */ ++ fp = fopen(REBOOT_UMOUNT_FILE_NAME, "a+"); ++ ++ /* print the time info to /.reboot-umount-msg.log file */ ++ if (fp == NULL) { ++ manager_status_printf(NULL, STATUS_TYPE_NORMAL, NULL, ++ "Open %s failed!", REBOOT_UMOUNT_FILE_NAME); ++ } ++ + manager_status_printf(NULL, STATUS_TYPE_NORMAL, NULL, + "\t\tUSER\t\tPID\tCOMMAND"); + manager_status_printf(NULL, STATUS_TYPE_NORMAL, NULL, + "%s:", name->filename); + ++ /* print the umount fail point to the /.reboot-umount-msg.log file */ ++ if (fp != NULL) { ++ if (strlen(name->filename) <= MOUNT_FILE_NAME_MAX_LEN) { ++ fprintf(fp, "%-20s\t", name->filename); ++ } else { ++ fprintf(fp, "%s\n\t\t\t", name->filename); ++ } ++ } ++ + for (pptr = name->matched_procs; pptr != NULL; pptr = pptr->next) { + if (pwent == NULL || pwent->pw_uid != pptr->uid) + pwent = getpwuid(pptr->uid); //get username +@@ -402,7 +422,7 @@ static void print_matches(const struct name *name) { + r = snprintf(cmd_path, sizeof(cmd_path), "/proc/%d", pptr->pid); + if (r <= 0) { + manager_status_printf(NULL, STATUS_TYPE_NORMAL, NULL, "Can't snprintf /proc/%d.", pptr->pid); +- return; ++ goto out; + } + + read_cmdline(P_cmd_long, sizeof(P_cmd_long), cmd_path, "cmdline", ' '); +@@ -415,22 +435,49 @@ static void print_matches(const struct name *name) { + if (pptr->command == NULL) + continue; + ++ if (flag > 0) { ++ if (fp != NULL) { ++ fprintf(fp, "\t\t\t"); ++ } ++ } else { ++ flag++; ++ } ++ + if (pwent != NULL) { +- if (pptr->pid != 0) ++ if (pptr->pid != 0) { + manager_status_printf(NULL, STATUS_TYPE_NORMAL, NULL, + "\t\t%-s\t\t%-d\t%-s", pwent->pw_name, pptr->pid, pptr->command); +- else ++ if (fp != NULL) { ++ fprintf(fp, "%-s\t\t%-d\t%-s\n", pwent->pw_name, pptr->pid, pptr->command); ++ } ++ } else { + manager_status_printf(NULL, STATUS_TYPE_NORMAL, NULL, + "\t\t%-s\t\t%-s\t%-s", pwent->pw_name, "kernel", pptr->command); ++ if (fp != NULL) { ++ fprintf(fp, "%-s\t\t%-s\t%-s\n", pwent->pw_name, "kernel", pptr->command); ++ } ++ } + } else { +- if (pptr->pid != 0) ++ if (pptr->pid != 0) { + manager_status_printf(NULL, STATUS_TYPE_NORMAL, NULL, + "\t\t%-u\t\t%-d\t%-s", pptr->uid, pptr->pid, pptr->command); +- else ++ if (fp != NULL) { ++ fprintf(fp, "%-u\t\t%-d\t%-s\n", pptr->uid, pptr->pid, pptr->command); ++ } ++ } else { + manager_status_printf(NULL, STATUS_TYPE_NORMAL, NULL, + "\t\t%-u\t\t%-s\t%-s", pptr->uid, "kernel", pptr->command); ++ if (fp != NULL) { ++ fprintf(fp, "%-u\t\t%-s\t%-s\n", pptr->uid, "kernel", pptr->command); ++ } ++ } + } + } ++ ++out: ++ if (fp != NULL) { ++ fclose(fp); ++ } + } + + static void free_matched_procs(struct procs *matched_procs) { +diff --git a/src/core/fuser.h b/src/core/fuser.h +index b74b879..2729c9b 100644 +--- a/src/core/fuser.h ++++ b/src/core/fuser.h +@@ -14,6 +14,7 @@ + #include <string.h> + #include <limits.h> + #include <errno.h> ++#include <time.h> + + #include "manager.h" + +@@ -51,5 +52,7 @@ struct device { + #define MAX_COMM_LEN 1024 + #define PROC_MOUNTS "/proc/mounts" + #define PROC_SWAPS "/proc/swaps" ++#define REBOOT_UMOUNT_FILE_NAME "/.reboot-umount-msg.log" ++#define MOUNT_FILE_NAME_MAX_LEN 20 + + int fuser(const char *dir); +diff --git a/src/core/job.c b/src/core/job.c +index d7ad85a..ee48860 100644 +--- a/src/core/job.c ++++ b/src/core/job.c +@@ -31,6 +31,8 @@ + #include "mount.h" + #include "process-util.h" + ++bool g_first_print = true; ++ + Job* job_new_raw(Unit *unit) { + Job *j; + +@@ -706,6 +708,9 @@ static void job_emit_done_message(Unit *u, uint32_t job_id, JobType t, JobResult + const char *ident, *format; + int r = 0; + pid_t pid; ++ FILE *fp = NULL; ++ time_t tmpt; ++ struct tm local_time; + + assert(u); + assert(t >= 0); +@@ -807,6 +812,39 @@ static void job_emit_done_message(Unit *u, uint32_t job_id, JobType t, JobResult + ((u->type == UNIT_MOUNT || u->type == UNIT_AUTOMOUNT) && t == JOB_STOP && result == JOB_FAILED)) { + + Mount *m = MOUNT(u); ++ if (g_first_print) { ++ /* Overwrite previous content at the first time */ ++ fp = fopen(REBOOT_UMOUNT_FILE_NAME, "w+"); ++ ++ /* Only get the local time once */ ++ tmpt = time(NULL); ++ if (!localtime_r(&tmpt, &local_time)) { ++ manager_status_printf(NULL, STATUS_TYPE_NORMAL, NULL, ++ "Get local time failed!"); ++ } ++ } ++ ++ /* print the time info to /.reboot-umount-msg.log file */ ++ if (g_first_print && fp == NULL) { ++ manager_status_printf(NULL, STATUS_TYPE_NORMAL, NULL, ++ "Open %s failed!", REBOOT_UMOUNT_FILE_NAME); ++ } else if (g_first_print) { ++ /* Only do this part one time */ ++ g_first_print = false; ++ ++ if (chmod(REBOOT_UMOUNT_FILE_NAME, S_IRUSR | S_IWUSR)) { ++ manager_status_printf(NULL, STATUS_TYPE_NORMAL, NULL, ++ "Set %s file attributes failed!", REBOOT_UMOUNT_FILE_NAME); ++ } ++ ++ fprintf(fp, "reboot time is %d/%d/%d-%d:%d:%d.\n", local_time.tm_year + 1900, ++ local_time.tm_mon + 1, local_time.tm_mday, local_time.tm_hour, ++ local_time.tm_min, local_time.tm_sec); ++ ++ fprintf(fp, "\n\t\t\tUSER\t\tPID\tCOMMAND\n"); ++ fclose(fp); ++ } ++ + + r = safe_fork("(fuser-shutdown)", FORK_RESET_SIGNALS, &pid); + if (r < 0) { +diff --git a/src/core/system.conf.in b/src/core/system.conf.in +index e9a5420..066a9a7 100644 +--- a/src/core/system.conf.in ++++ b/src/core/system.conf.in +@@ -76,7 +76,7 @@ DefaultLimitMEMLOCK=64M + #DefaultLimitRTPRIO= + #DefaultLimitRTTIME= + #DefaultOOMPolicy=stop +-#DefaultDFXReboot=no ++DefaultDFXReboot=yes + #DefaultSmackProcessLabel= + #ReloadLimitIntervalSec= + #ReloadLimitBurst= +-- +2.33.0 +
View file
_service:tar_scm:keep-weight-consistent-with-the-set-value.patch
Added
@@ -0,0 +1,36 @@ +From 7424b6c0f38d4a32fd96e74d7078707c026c6c66 Mon Sep 17 00:00:00 2001 +From: wangyuhang <wangyuhang27@huawei.com> +Date: Thu, 9 Jun 2022 20:10:50 +0800 +Subject: PATCH keep weight consistent with the set value + +--- + src/core/cgroup.c | 6 ++++-- + 1 file changed, 4 insertions(+), 2 deletions(-) + +diff --git a/src/core/cgroup.c b/src/core/cgroup.c +index 4cac3f6..f6ae2ab 100644 +--- a/src/core/cgroup.c ++++ b/src/core/cgroup.c +@@ -1392,7 +1392,8 @@ static void set_io_weight(Unit *u, uint64_t weight) { + + assert(u); + +- (void) set_bfq_weight(u, "io", makedev(0, 0), weight); ++ xsprintf(buf, "%" PRIu64 "\n", weight); ++ (void) set_attribute_and_warn(u, "io", "io.bfq.weight", buf); + + xsprintf(buf, "default %" PRIu64 "\n", weight); + (void) set_attribute_and_warn(u, "io", "io.weight", buf); +@@ -1403,7 +1404,8 @@ static void set_blkio_weight(Unit *u, uint64_t weight) { + + assert(u); + +- (void) set_bfq_weight(u, "blkio", makedev(0, 0), weight); ++ xsprintf(buf, "%" PRIu64 "\n", weight); ++ (void) set_attribute_and_warn(u, "blkio", "blkio.bfq.weight", buf); + + xsprintf(buf, "%" PRIu64 "\n", weight); + (void) set_attribute_and_warn(u, "blkio", "blkio.weight", buf); +-- +2.33.0 +
View file
_service:tar_scm:let-the-child-of-one-unit-don-t-affect-each-other.patch
Added
@@ -0,0 +1,83 @@ +From 8c9de291f2b782f5d7d40447f08553b5e325a34d Mon Sep 17 00:00:00 2001 +From: licunlong <licunlong1@huawei.com> +Date: Fri, 19 Mar 2021 01:29:01 +0800 +Subject: PATCH let the child of one unit don't affect each other. +This should only be used for .slice unit in the Unit section. +To reproduce the problem resolved by this patch, try the following steps: +1. start service A in a slice; +2. change the cgroup property by "echo 512 > service_a/cpu.shares"; +3. systemctl daemon-reload; +4. start service B in a slice; +5. check the cgroup property by "cat service_a/cpu.shares"; +With this directive enabled, the value will stay as 512; if disabled, +if will be restored to the default value of systemd. Defaults to "no". + +--- + src/core/cgroup.c | 3 +++ + src/core/load-fragment-gperf.gperf.in | 1 + + src/core/unit-serialize.c | 2 ++ + src/core/unit.h | 2 ++ + 4 files changed, 8 insertions(+) + +diff --git a/src/core/cgroup.c b/src/core/cgroup.c +index 4eedaf7..ab6d602 100644 +--- a/src/core/cgroup.c ++++ b/src/core/cgroup.c +@@ -2618,6 +2618,9 @@ void unit_add_family_to_cgroup_realize_queue(Unit *u) { + + UNIT_FOREACH_DEPENDENCY(m, u, UNIT_ATOM_SLICE_OF) { + ++ if (u->independent_child) ++ continue; ++ + /* No point in doing cgroup application for units without active processes. */ + if (UNIT_IS_INACTIVE_OR_FAILED(unit_active_state(m))) + continue; +diff --git a/src/core/load-fragment-gperf.gperf.in b/src/core/load-fragment-gperf.gperf.in +index 0702aa0..76b1217 100644 +--- a/src/core/load-fragment-gperf.gperf.in ++++ b/src/core/load-fragment-gperf.gperf.in +@@ -286,6 +286,7 @@ Unit.JoinsNamespaceOf, config_parse_unit_deps, + Unit.RequiresOverridable, config_parse_obsolete_unit_deps, UNIT_REQUIRES, 0 + Unit.RequisiteOverridable, config_parse_obsolete_unit_deps, UNIT_REQUISITE, 0 + Unit.RequiresMountsFor, config_parse_unit_requires_mounts_for, 0, 0 ++Unit.IndependentChild, config_parse_bool, 0, offsetof(Unit, independent_child) + Unit.StopWhenUnneeded, config_parse_bool, 0, offsetof(Unit, stop_when_unneeded) + Unit.RefuseManualStart, config_parse_bool, 0, offsetof(Unit, refuse_manual_start) + Unit.RefuseManualStop, config_parse_bool, 0, offsetof(Unit, refuse_manual_stop) +diff --git a/src/core/unit-serialize.c b/src/core/unit-serialize.c +index f3b3e70..b818181 100644 +--- a/src/core/unit-serialize.c ++++ b/src/core/unit-serialize.c +@@ -801,6 +801,7 @@ void unit_dump(Unit *u, FILE *f, const char *prefix) { + if (u->load_state == UNIT_LOADED) { + + fprintf(f, ++ "%s\tIndependentChild:%s\n" + "%s\tStopWhenUnneeded: %s\n" + "%s\tRefuseManualStart: %s\n" + "%s\tRefuseManualStop: %s\n" +@@ -808,6 +809,7 @@ void unit_dump(Unit *u, FILE *f, const char *prefix) { + "%s\tOnSuccessJobMode: %s\n" + "%s\tOnFailureJobMode: %s\n" + "%s\tIgnoreOnIsolate: %s\n", ++ prefix, yes_no(u->independent_child), + prefix, yes_no(u->stop_when_unneeded), + prefix, yes_no(u->refuse_manual_start), + prefix, yes_no(u->refuse_manual_stop), +diff --git a/src/core/unit.h b/src/core/unit.h +index cb85dfc..439714a 100644 +--- a/src/core/unit.h ++++ b/src/core/unit.h +@@ -350,6 +350,8 @@ typedef struct Unit { + sd_id128_t invocation_id; + char invocation_id_stringSD_ID128_STRING_MAX; /* useful when logging */ + ++ bool independent_child; ++ + /* Garbage collect us we nobody wants or requires us anymore */ + bool stop_when_unneeded; + +-- +2.27.0 +
View file
_service:tar_scm:logind-set-RemoveIPC-to-false-by-default.patch
Added
@@ -0,0 +1,53 @@ +From 0b3833d6c3b751c6dfb40eeb2ef852984c58f546 Mon Sep 17 00:00:00 2001 +From: openEuler Buildteam <buildteam@openeuler.org> +Date: Wed, 1 Aug 2018 10:58:28 +0200 +Subject: logind: set RemoveIPC to false by default + +Resolves: #1523233 +--- + man/logind.conf.xml | 2 +- + src/login/logind-core.c | 2 +- + src/login/logind.conf.in | 2 +- + 3 files changed, 3 insertions(+), 3 deletions(-) + +diff --git a/man/logind.conf.xml b/man/logind.conf.xml +index b00daf366d..a9fed78aa6 100644 +--- a/man/logind.conf.xml ++++ b/man/logind.conf.xml +@@ -340,7 +340,7 @@ + user fully logs out. Takes a boolean argument. If enabled, the user may not consume IPC resources after the + last of the user's sessions terminated. This covers System V semaphores, shared memory and message queues, as + well as POSIX shared memory and message queues. Note that IPC objects of the root user and other system users +- are excluded from the effect of this setting. Defaults to <literal>yes</literal>.</para></listitem> ++ are excluded from the effect of this setting. Defaults to <literal>no</literal>.</para></listitem> + </varlistentry> + + <varlistentry> +diff --git a/src/login/logind-core.c b/src/login/logind-core.c +index 4289461df6..556945be20 100644 +--- a/src/login/logind-core.c ++++ b/src/login/logind-core.c +@@ -35,7 +35,7 @@ void manager_reset_config(Manager *m) { + + m->n_autovts = 6; + m->reserve_vt = 6; +- m->remove_ipc = true; ++ m->remove_ipc = false; + m->inhibit_delay_max = 5 * USEC_PER_SEC; + m->user_stop_delay = 10 * USEC_PER_SEC; + +diff --git a/src/login/logind.conf.in b/src/login/logind.conf.in +index ed1084b06e..07ff0d195e 100644 +--- a/src/login/logind.conf.in ++++ b/src/login/logind.conf.in +@@ -33,6 +33,6 @@ + #IdleActionSec=30min + #RuntimeDirectorySize=10% + #RuntimeDirectoryInodesMax= +-#RemoveIPC=yes ++#RemoveIPC=no + #InhibitorsMax=8192 + #SessionsMax=8192 +-- +2.23.0 +
View file
_service:tar_scm:pid1-bump-DefaultTasksMax-to-80-of-the-kernel-pid.ma.patch
Added
@@ -0,0 +1,64 @@ +From ad2da19e1e80a9ab9d0dfae17a74f5009e4d1898 Mon Sep 17 00:00:00 2001 +From: openEuler Buildteam <buildteam@openeuler.org> +Date: Tue, 10 Mar 2020 21:01:43 +0800 +Subject: PATCH pid1 bump DefaultTasksMax to 80% of the kernel pid.max value + +--- + man/systemd-system.conf.xml | 2 +- + src/core/main.c | 2 +- + src/core/system.conf.in | 2 +- + units/user-.slice.d/10-defaults.conf | 2 +- + 4 files changed, 4 insertions(+), 4 deletions(-) + +diff --git a/man/systemd-system.conf.xml b/man/systemd-system.conf.xml +index c11dd46..b259631 100644 +--- a/man/systemd-system.conf.xml ++++ b/man/systemd-system.conf.xml +@@ -389,7 +389,7 @@ + <listitem><para>Configure the default value for the per-unit <varname>TasksMax=</varname> setting. See + <citerefentry><refentrytitle>systemd.resource-control</refentrytitle><manvolnum>5</manvolnum></citerefentry> + for details. This setting applies to all unit types that support resource control settings, with the exception +- of slice units. Defaults to 15% of the minimum of <varname>kernel.pid_max=</varname>, <varname>kernel.threads-max=</varname> ++ of slice units. Defaults to 80% of the minimum of <varname>kernel.pid_max=</varname>, <varname>kernel.threads-max=</varname> + and root cgroup <varname>pids.max</varname>. + Kernel has a default value for <varname>kernel.pid_max=</varname> and an algorithm of counting in case of more than 32 cores. + For example, with the default <varname>kernel.pid_max=</varname>, <varname>DefaultTasksMax=</varname> defaults to 4915, +diff --git a/src/core/main.c b/src/core/main.c +index da6c50a..f4fe751 100644 +--- a/src/core/main.c ++++ b/src/core/main.c +@@ -92,7 +92,7 @@ + #include <sanitizer/lsan_interface.h> + #endif + +-#define DEFAULT_TASKS_MAX ((TasksMax) { 15U, 100U }) /* 15% */ ++#define DEFAULT_TASKS_MAX ((TasksMax) { 80U, 100U }) /* 80% */ + + static enum { + ACTION_RUN, +diff --git a/src/core/system.conf.in b/src/core/system.conf.in +index e88280b..f2c75fc 100644 +--- a/src/core/system.conf.in ++++ b/src/core/system.conf.in +@@ -54,7 +54,7 @@ + #DefaultIPAccounting=no + #DefaultMemoryAccounting={{ 'yes' if MEMORY_ACCOUNTING_DEFAULT else 'no' }} + #DefaultTasksAccounting=yes +-#DefaultTasksMax=15% ++#DefaultTasksMax=80% + #DefaultLimitCPU= + #DefaultLimitFSIZE= + #DefaultLimitDATA= +diff --git a/units/user-.slice.d/10-defaults.conf b/units/user-.slice.d/10-defaults.conf +index cb3651b..be8fa28 100644 +--- a/units/user-.slice.d/10-defaults.conf ++++ b/units/user-.slice.d/10-defaults.conf +@@ -14,4 +14,4 @@ After=systemd-user-sessions.service + StopWhenUnneeded=yes + + Slice +-TasksMax=33% ++TasksMax=80% +-- +2.27.0 +
View file
_service:tar_scm:print-the-process-status-to-console-when-shutdown.patch
Added
@@ -0,0 +1,1280 @@ +From 5966f7a3b90ee25f23182e9320621a8477a40a51 Mon Sep 17 00:00:00 2001 +From: jiangchuangang <jiangchuangang@huawei.com> +Date: Thu, 2 Sep 2021 12:14:19 +0800 +Subject: PATCH print process status to console when shutdown + +--- + meson.build | 6 +- + src/basic/process-util.c | 58 ++++ + src/basic/process-util.h | 2 + + src/core/fuser.c | 506 +++++++++++++++++++++++++++++++++ + src/core/fuser.h | 55 ++++ + src/core/job.c | 36 +++ + src/core/main.c | 13 +- + src/core/manager.c | 1 + + src/core/manager.h | 2 + + src/core/meson.build | 1 + + src/core/system.conf.in | 1 + + src/shutdown/meson.build | 9 +- + src/shutdown/process-status.c | 143 ++++++++++ + src/shutdown/process-status.h | 24 ++ + src/shutdown/shutdown.c | 45 +++ + src/shutdown/umount.c | 5 + + src/test/meson.build | 15 + + src/test/test-fuser.c | 14 + + src/test/test-process-status.c | 10 + + 19 files changed, 939 insertions(+), 7 deletions(-) + create mode 100644 src/core/fuser.c + create mode 100644 src/core/fuser.h + create mode 100644 src/shutdown/process-status.c + create mode 100644 src/shutdown/process-status.h + create mode 100644 src/test/test-fuser.c + create mode 100644 src/test/test-process-status.c + +diff --git a/meson.build b/meson.build +index bfc8685..0372b17 100644 +--- a/meson.build ++++ b/meson.build +@@ -3882,8 +3882,10 @@ endif + executable( + 'systemd-shutdown', + systemd_shutdown_sources, +- include_directories : includes, +- link_with : libshared, ++ include_directories : includes, ++ core_includes, ++ link_with : libcore, ++ libshared, + dependencies : libmount, + versiondep, + install_rpath : rootpkglibdir, +diff --git a/src/basic/process-util.c b/src/basic/process-util.c +index b6bf83c..eb48f4d 100644 +--- a/src/basic/process-util.c ++++ b/src/basic/process-util.c +@@ -1569,3 +1569,61 @@ static const char* const sched_policy_table = { + }; + + DEFINE_STRING_TABLE_LOOKUP_WITH_FALLBACK(sched_policy, int, INT_MAX); ++ ++unsigned int read_cmdline(char *restrict const dst, unsigned sz, const char* whom, const char *what, char sep) { ++ char pathPATH_MAX; ++ _cleanup_close_ int fd = 0; ++ int len = 0; ++ unsigned n = 0; ++ ++ if (sz <= 0) ++ return 0; ++ ++ if (sz >= INT_MAX) ++ sz = INT_MAX-1; ++ ++ dst0 = '\0'; ++ ++ len = snprintf(path, sizeof(path), "%s/%s", whom, what); ++ if (len <= 0 || (size_t)len >= sizeof(path)) ++ return 0; ++ ++ fd = open(path, O_RDONLY); ++ if (fd == -1) ++ return 0; ++ ++ for (;;) { ++ ssize_t r = read(fd, dst+n, sz-n); ++ ++ if (r == -1) { ++ if (errno == EINTR) ++ continue; ++ break; ++ } ++ ++ if (r <= 0) ++ break; ++ n += r; ++ ++ if (n == sz) { ++ --n; ++ break; ++ } ++ } ++ ++ if (n) { ++ unsigned i = n; ++ ++ while (i && dsti-1 == '\0') ++ --i; ++ ++ while (i--) ++ if (dsti == '\n' || dsti == '\0') dsti = sep; ++ ++ if (dstn-1 == ' ') ++ dstn-1 = '\0'; ++ } ++ ++ dstn = '\0'; ++ return n; ++} +diff --git a/src/basic/process-util.h b/src/basic/process-util.h +index 96da0bb..55cb72b 100644 +--- a/src/basic/process-util.h ++++ b/src/basic/process-util.h +@@ -189,3 +189,5 @@ int pidfd_verify_pid(int pidfd, pid_t pid); + int setpriority_closest(int priority); + + _noreturn_ void freeze(void); ++ ++unsigned int read_cmdline(char *restrict const dst, unsigned sz, const char* whom, const char *what, char sep); +diff --git a/src/core/fuser.c b/src/core/fuser.c +new file mode 100644 +index 0000000..e943469 +--- /dev/null ++++ b/src/core/fuser.c +@@ -0,0 +1,506 @@ ++#include "fuser.h" ++#include "process-util.h" ++ ++static int parse_dir(struct name *this_name, struct inode *match_inode) { ++ if ((this_name == NULL) || (match_inode == NULL)) { ++ manager_status_printf(NULL, STATUS_TYPE_NORMAL, NULL, ++ "Can't parse dir."); ++ return -1; ++ } ++ ++ if (stat(this_name->filename, &this_name->st) != 0) { ++ manager_status_printf(NULL, STATUS_TYPE_NORMAL, NULL, ++ "Can't stat dir %s.", this_name->filename); ++ return -1; ++ } ++ ++ match_inode->name = this_name; ++ match_inode->device = this_name->st.st_dev; ++ match_inode->inode = this_name->st.st_ino; ++ ++ return 0; ++} ++ ++static int parse_mounts(struct name *this_name, struct device *match_device) { ++ if ((this_name == NULL) && (match_device == NULL)) { ++ manager_status_printf(NULL, STATUS_TYPE_NORMAL, NULL, ++ "Can't parse mounts."); ++ return -1; ++ } ++ ++ match_device->name = this_name; ++ ++ if (S_ISBLK(this_name->st.st_mode)) ++ match_device->device = this_name->st.st_rdev; ++ else ++ match_device->device = this_name->st.st_dev; ++ ++ return 0; ++} ++ ++static uid_t getpiduid(const pid_t pid) { ++ char pathnamePATH_MAX; ++ struct stat st; ++ int r = 0; ++ ++ r = snprintf(pathname, sizeof(pathname), "/proc/%d", pid); ++ if (r < 0) { ++ manager_status_printf(NULL, STATUS_TYPE_NORMAL, NULL, ++ "Snprintf run failed in getpiduid."); ++ return 0; ++ } ++ ++ if (stat(pathname, &st) != 0) ++ return 0; ++ ++ return st.st_uid; ++} ++ ++static struct stat *get_pidstat(const pid_t pid) { ++ char pathnamePATH_MAX; ++ struct stat *st = NULL; ++ int r = 0; ++ ++ st = (struct stat *)malloc(sizeof(struct stat)); ++ if (st == NULL) { ++ manager_status_printf(NULL, STATUS_TYPE_NORMAL, NULL, ++ "Malloc failed in get_pidstat."); ++ return NULL; ++ } ++ ++ r = snprintf(pathname, sizeof(pathname), "/proc/%d/cwd", pid); ++ if (r < 0) { ++ manager_status_printf(NULL, STATUS_TYPE_NORMAL, NULL, ++ "Snprintf run failed in get_pidstat."); ++ return NULL; ++ } ++ ++ if (stat(pathname, st) != 0) { ++ free(st); ++ return NULL; ++ } ++ ++ return st; ++} ++ ++static void add_matched_proc(struct name *name, const pid_t pid, const uid_t uid) { ++ struct procs *pptr = NULL; ++ struct procs *last_proc = NULL; ++ char pathnamePATH_MAX; ++ char cmdnameCMD_NAME_LEN + 1; ++ char *cptr = NULL; ++ int cmdlen = 0; ++ FILE *fp = NULL; ++ ++ if (name == NULL) { ++ manager_status_printf(NULL, STATUS_TYPE_NORMAL, NULL, ++ "Name should not be NULL."); ++ return; ++ } ++ ++ //find out wheather the pid already in pptr->pid ++ for (pptr = name->matched_procs; pptr != NULL; pptr = pptr->next) { ++ last_proc = pptr; ++ ++ if (pptr->pid == pid) ++ return; ++ } ++ ++ pptr = (struct procs *)malloc(sizeof(struct procs)); ++ if (pptr == NULL) { ++ manager_status_printf(NULL, STATUS_TYPE_NORMAL, NULL, ++ "Can't malloc in add_matched_proc."); ++ return; ++ } ++ ++ pptr->pid = pid; ++ pptr->uid = uid; ++ pptr->username = NULL; ++ pptr->next = NULL; ++ pptr->command = NULL; ++ ++ if ((snprintf(pathname, sizeof(pathname), "/proc/%d/stat", pid) > 0) && ++ ((fp = fopen(pathname, "r")) != NULL) && (fscanf(fp, "%*d (%100^)", cmdname) == 1)) { ++ pptr->command = (char *)malloc(COMM_LEN + 1); ++ ++ if (pptr->command != NULL) { ++ cmdlen = 0; ++ ++ for (cptr = cmdname; cmdlen < COMM_LEN && *cptr; cptr++) { ++ if (isprint(*cptr)) { ++ pptr->commandcmdlen++ = *cptr; ++ } else if (cmdlen < (COMM_LEN - 4)) { ++ cmdlen += sprintf(&(pptr->commandcmdlen), "\\%03o", (unsigned int)*cptr); ++ } ++ } ++ ++ pptr->commandcmdlen = '\0'; ++ } ++ } ++ ++ if (last_proc == NULL) ++ name->matched_procs = pptr; ++ else ++ last_proc->next = pptr; ++ ++ if (fp) ++ fclose(fp); ++} ++ ++static void check_dir(const pid_t pid, const char *dirname, const struct device *dev, ++ const struct inode *ino, const uid_t uid) { ++ DIR *dirp = NULL; ++ dev_t thedev; ++ struct dirent *direntry = NULL; ++ struct stat st; ++ char dirpathPATH_MAX; ++ char filepathPATH_MAX; ++ int r = 0; ++ ++ if (dirname == NULL) { ++ manager_status_printf(NULL, STATUS_TYPE_NORMAL, NULL, ++ "Dirname is NULL."); ++ return; ++ } ++ ++ r = snprintf(dirpath, sizeof(dirpath), "/proc/%d/%s", pid, dirname); ++ if (r < 0) { ++ manager_status_printf(NULL, STATUS_TYPE_NORMAL, NULL, ++ "Snprintf run failed in check_dir."); ++ return; ++ } ++ ++ dirp = opendir(dirpath); ++ if (dirp == NULL) ++ return; ++ ++ while ((direntry = readdir(dirp)) != NULL) { ++ if (direntry->d_name0 < '0' || direntry->d_name0 > '9') ++ continue; ++ ++ snprintf(filepath, sizeof(filepath), "/proc/%d/%s/%s", ++ pid, dirname, direntry->d_name); ++ ++ if (stat(filepath, &st) != 0) ++ continue; ++ ++ thedev = st.st_dev; ++ ++ if ((dev != NULL) && (thedev == dev->device)) { ++ add_matched_proc(dev->name, pid, uid); ++ } ++ ++ if ((ino != NULL) && (thedev == ino->device)) { ++ if (st.st_ino == ino->inode) { ++ add_matched_proc(ino->name, pid, uid); ++ } ++ } ++ } //end while ++ ++ closedir(dirp); ++} ++ ++static int scan_procs(const struct name *name, const struct inode *ino, const struct device *dev) { ++ DIR *topproc_dir = NULL; ++ struct dirent *topproc_dent = NULL; ++ pid_t pid; ++ pid_t my_pid; ++ uid_t uid; ++ ++ if (name == NULL) { ++ manager_status_printf(NULL, STATUS_TYPE_NORMAL, NULL, ++ "Name should not be null in scan_procs."); ++ return -1; ++ } ++ ++ if ((ino == NULL) && (dev == NULL)) { ++ manager_status_printf(NULL, STATUS_TYPE_NORMAL, NULL, ++ "Ino and dev should not be NULL in scan_procs."); ++ return -1; ++ } ++ ++ topproc_dir = opendir("/proc"); ++ if (topproc_dir == NULL) { ++ manager_status_printf(NULL, STATUS_TYPE_NORMAL, NULL, ++ "Can't open dir proc."); ++ return -1; ++ } ++ ++ my_pid = getpid(); ++ ++ while ((topproc_dent = readdir(topproc_dir)) != NULL) { ++ dev_t scan_dev; ++ struct stat *st = NULL; ++ ++ /* Not a process */ ++ if ((topproc_dent->d_name0 < '0') || (topproc_dent->d_name0 > '9')) ++ continue; ++ ++ pid = atoi(topproc_dent->d_name); ++ if (pid == my_pid) ++ continue; ++ ++ uid = getpiduid(pid); ++ ++ st = get_pidstat(pid); ++ scan_dev = st ? st->st_dev : 0; ++ ++ if ((dev != NULL) && (scan_dev == dev->device)) ++ add_matched_proc(dev->name, pid, uid); ++ ++ if ((ino != NULL) && (scan_dev == ino->device)) { ++ if (!st) ++ st = get_pidstat(pid); ++ ++ if (st && (st->st_dev == ino->device) && (st->st_ino == ino->inode)) ++ add_matched_proc(ino->name, pid, uid); ++ } ++ ++ if (st) ++ free(st); ++ ++ check_dir(pid, "fd", dev, ino, uid); ++ } // end while ++ ++ closedir(topproc_dir); ++ return 0; ++} ++ ++static void add_special_proc(struct name *name, const uid_t uid, const char *command) { ++ struct procs *pptr = NULL; ++ ++ if (name == NULL) { ++ manager_status_printf(NULL, STATUS_TYPE_NORMAL, NULL, ++ "Name should not be null in add_special_proc."); ++ return; ++ } ++ ++ for (pptr = name->matched_procs; pptr != NULL; pptr = pptr->next) { ++ if (pptr->command != NULL && strcmp(pptr->command, command) == 0) ++ return; ++ } ++ ++ if ((pptr = malloc(sizeof(struct procs))) == NULL) { ++ manager_status_printf(NULL, STATUS_TYPE_NORMAL, NULL, ++ "Can't allocate memory for add_special_proc() proc"); ++ return; ++ } ++ ++ pptr->pid = 0; ++ pptr->uid = uid; ++ pptr->next = name->matched_procs; ++ pptr->command = strdup(command); ++ ++ name->matched_procs = pptr; ++} ++ ++static void scan_mounts_and_swaps(const struct name *name, const struct inode *ino, ++ const struct device *dev, const char *file) { ++ FILE *fp = NULL; ++ char linePATH_MAX; ++ char *find_mountp = NULL; ++ char *find_space_mounts = NULL; ++ char *find_space_swaps = NULL; ++ struct stat st; ++ ++ if (name == NULL) { ++ manager_status_printf(NULL, STATUS_TYPE_NORMAL, NULL, ++ "Name should not be null in scan_mounts_and_swaps."); ++ return; ++ } ++ ++ if ((ino == NULL) && (dev == NULL)) { ++ manager_status_printf(NULL, STATUS_TYPE_NORMAL, NULL, ++ "Ino and dev should not be null in scan_mounts_and_swaps."); ++ return; ++ } ++ ++ fp = fopen(file, "r"); ++ if (fp == NULL) { ++ manager_status_printf(NULL, STATUS_TYPE_NORMAL, NULL, ++ "Can't open file %s", file); ++ return; ++ } ++ ++ while (fgets(line, PATH_MAX, fp) != NULL) { ++ if (strcmp(file, PROC_MOUNTS) == 0) { ++ if ((find_mountp = strchr(line, ' ')) == NULL) ++ continue; ++ ++ find_mountp++; ++ ++ find_space_mounts = strchr(find_mountp, ' '); ++ if (find_space_mounts == NULL) ++ continue; ++ ++ *find_space_mounts = '\0'; ++ ++ if (stat(find_mountp, &st) != 0) ++ continue; ++ } else { ++ find_space_swaps = strchr(line, ' '); ++ if (find_space_swaps == NULL) ++ continue; ++ ++ *find_space_swaps = '\0'; ++ find_space_swaps++; ++ ++ while (*find_space_swaps == ' ') { ++ find_space_swaps++; ++ ++ if (*find_space_swaps == '\0') ++ continue; ++ } ++ ++ if (stat(line, &st) != 0) { ++ continue; ++ } ++ } ++ ++ if ((dev != NULL) && (st.st_dev == dev->device)) { ++ if (strcmp(file, PROC_MOUNTS) == 0) ++ add_special_proc(dev->name, 0, find_mountp); ++ ++ if (strcmp(file, PROC_SWAPS) == 0) ++ add_special_proc(dev->name, 0, line); ++ } ++ ++ if ((ino != NULL) && (st.st_dev == ino->device) && (st.st_ino == ino->inode)) { ++ if (strcmp(file, PROC_MOUNTS) == 0) ++ add_special_proc(ino->name, 0, find_mountp); ++ ++ if (strcmp(file, PROC_SWAPS) == 0) ++ add_special_proc(ino->name, 0, line); ++ } ++ } // end while ++ ++ fclose(fp); ++} ++ ++static void print_matches(const struct name *name) { ++ struct procs *pptr = NULL; ++ struct passwd *pwent = NULL; ++ static char P_cmd_longMAX_COMM_LEN; ++ char cmd_pathPATH_MAX; ++ int r = 0; ++ ++ if (name == NULL) { ++ manager_status_printf(NULL, STATUS_TYPE_NORMAL, NULL, ++ "Name should not be null in print_matches."); ++ return; ++ } ++ ++ manager_status_printf(NULL, STATUS_TYPE_NORMAL, NULL, ++ "\t\tUSER\t\tPID\tCOMMAND"); ++ manager_status_printf(NULL, STATUS_TYPE_NORMAL, NULL, ++ "%s:", name->filename); ++ ++ for (pptr = name->matched_procs; pptr != NULL; pptr = pptr->next) { ++ if (pwent == NULL || pwent->pw_uid != pptr->uid) ++ pwent = getpwuid(pptr->uid); //get username ++ ++ r = snprintf(cmd_path, sizeof(cmd_path), "/proc/%d", pptr->pid); ++ if (r <= 0) { ++ manager_status_printf(NULL, STATUS_TYPE_NORMAL, NULL, "Can't snprintf /proc/%d.", pptr->pid); ++ return; ++ } ++ ++ read_cmdline(P_cmd_long, sizeof(P_cmd_long), cmd_path, "cmdline", ' '); ++ ++ if (strlen(P_cmd_long) != 0){ ++ free(pptr->command); ++ pptr->command = strdup(P_cmd_long); ++ } ++ ++ if (pptr->command == NULL) ++ continue; ++ ++ if (pwent != NULL) { ++ if (pptr->pid != 0) ++ manager_status_printf(NULL, STATUS_TYPE_NORMAL, NULL, ++ "\t\t%-s\t\t%-d\t%-s", pwent->pw_name, pptr->pid, pptr->command); ++ else ++ manager_status_printf(NULL, STATUS_TYPE_NORMAL, NULL, ++ "\t\t%-s\t\t%-s\t%-s", pwent->pw_name, "kernel", pptr->command); ++ } else { ++ if (pptr->pid != 0) ++ manager_status_printf(NULL, STATUS_TYPE_NORMAL, NULL, ++ "\t\t%-u\t\t%-d\t%-s", pptr->uid, pptr->pid, pptr->command); ++ else ++ manager_status_printf(NULL, STATUS_TYPE_NORMAL, NULL, ++ "\t\t%-u\t\t%-s\t%-s", pptr->uid, "kernel", pptr->command); ++ } ++ } ++} ++ ++static void free_matched_procs(struct procs *matched_procs) { ++ struct procs *procs_tmp = NULL; ++ struct procs *procs_next = NULL; ++ ++ procs_tmp = matched_procs; ++ ++ while (procs_tmp != NULL) { ++ procs_next = procs_tmp->next; ++ ++ if (procs_tmp->command) ++ free(procs_tmp->command); ++ ++ free(procs_tmp); ++ ++ procs_tmp = procs_next; ++ } ++} ++ ++int fuser(const char *dir) { ++ struct name this_name; ++ struct inode match_inode; ++ struct device match_device; ++ int r = 0; ++ ++ if (dir == NULL) { ++ manager_status_printf(NULL, STATUS_TYPE_NORMAL, NULL, ++ "Dir should not be NULL."); ++ return -1; ++ } ++ ++ this_name.matched_procs = NULL; ++ ++ this_name.filename = strdup(dir); //need to free ++ if (this_name.filename == NULL) { ++ manager_status_printf(NULL, STATUS_TYPE_NORMAL, NULL, ++ "Can't allocate memory for fuser() this_name->filename."); ++ return -1; ++ } ++ ++ r = parse_dir(&this_name, &match_inode); ++ if (r < 0) { ++ manager_status_printf(NULL, STATUS_TYPE_NORMAL, NULL, ++ "%s", "Failed to parse file."); ++ free(this_name.filename); ++ return -1; ++ } ++ ++ r = parse_mounts(&this_name, &match_device); ++ if (r < 0) { ++ manager_status_printf(NULL, STATUS_TYPE_NORMAL, NULL, ++ "%s", "Failed to parse mounts."); ++ free(this_name.filename); ++ return -1; ++ } ++ ++ r = scan_procs(&this_name, &match_inode, &match_device); ++ if (r < 0) { ++ manager_status_printf(NULL, STATUS_TYPE_NORMAL, NULL, ++ "%s", "Failed to scan_procs."); ++ free(this_name.filename); ++ return -1; ++ } ++ ++ scan_mounts_and_swaps(&this_name, &match_inode, &match_device, PROC_MOUNTS); ++ scan_mounts_and_swaps(&this_name, &match_inode, &match_device, PROC_SWAPS); ++ print_matches(&this_name); ++ ++ free_matched_procs(this_name.matched_procs); ++ free(this_name.filename); ++ return 0; ++} +diff --git a/src/core/fuser.h b/src/core/fuser.h +new file mode 100644 +index 0000000..b74b879 +--- /dev/null ++++ b/src/core/fuser.h +@@ -0,0 +1,55 @@ ++#pragma once ++ ++#include <sys/types.h> ++#include <sys/stat.h> ++#include <stdio.h> ++#include <sys/types.h> ++#include <sys/stat.h> ++#include <fcntl.h> ++#include <stdlib.h> ++#include <dirent.h> ++#include <ctype.h> ++#include <unistd.h> ++#include <pwd.h> ++#include <string.h> ++#include <limits.h> ++#include <errno.h> ++ ++#include "manager.h" ++ ++struct procs { ++ pid_t pid; ++ uid_t uid; ++ char *username; ++ char *command; ++ struct procs *next; ++}; ++ ++struct name { ++ char *filename; ++ struct stat st; ++ struct procs *matched_procs; ++}; ++ ++struct inode { ++ struct name *name; ++ dev_t device; ++ ino_t inode; ++}; ++ ++struct device { ++ struct name *name; ++ dev_t device; ++}; ++ ++#ifndef PATH_MAX ++#define PATH_MAX 4096 ++#endif /* PATH_MAX */ ++ ++#define CMD_NAME_LEN 100 ++#define COMM_LEN 64 ++#define MAX_COMM_LEN 1024 ++#define PROC_MOUNTS "/proc/mounts" ++#define PROC_SWAPS "/proc/swaps" ++ ++int fuser(const char *dir); +diff --git a/src/core/job.c b/src/core/job.c +index 032554a..d7ad85a 100644 +--- a/src/core/job.c ++++ b/src/core/job.c +@@ -27,6 +27,9 @@ + #include "terminal-util.h" + #include "unit.h" + #include "virt.h" ++#include "fuser.h" ++#include "mount.h" ++#include "process-util.h" + + Job* job_new_raw(Unit *unit) { + Job *j; +@@ -701,6 +704,8 @@ static const char* job_done_mid(JobType type, JobResult result) { + static void job_emit_done_message(Unit *u, uint32_t job_id, JobType t, JobResult result) { + _cleanup_free_ char *free_ident = NULL; + const char *ident, *format; ++ int r = 0; ++ pid_t pid; + + assert(u); + assert(t >= 0); +@@ -797,6 +802,37 @@ static void job_emit_done_message(Unit *u, uint32_t job_id, JobType t, JobResult + "See 'systemctl status %s' for details.", quoted); + } + } ++ ++ if (FLAGS_SET(manager_state(u->manager), MANAGER_STOPPING) && u->manager->default_dfx_reboot && ++ ((u->type == UNIT_MOUNT || u->type == UNIT_AUTOMOUNT) && t == JOB_STOP && result == JOB_FAILED)) { ++ ++ Mount *m = MOUNT(u); ++ ++ r = safe_fork("(fuser-shutdown)", FORK_RESET_SIGNALS, &pid); ++ if (r < 0) { ++ manager_status_printf(NULL, STATUS_TYPE_NORMAL, NULL, ++ "Failed to fork for fuser!"); ++ return; ++ } ++ if (r == 0) { ++ manager_status_printf(NULL, STATUS_TYPE_NORMAL, NULL, ++ "-------------fuser -mv %s----------------", m->where); ++ ++ r = fuser(m->where); ++ if (r < 0) ++ manager_status_printf(NULL, STATUS_TYPE_NORMAL, NULL, "Can't run fuser."); ++ ++ manager_status_printf(NULL, STATUS_TYPE_NORMAL, NULL, ++ "%s","----------------------------------------------------------------------"); ++ _exit(r < 0 ? EXIT_FAILURE : EXIT_SUCCESS); ++ } ++ ++ r = wait_for_terminate_with_timeout(pid, 3 * USEC_PER_SEC); ++ if (r == -ETIMEDOUT) { ++ manager_status_printf(NULL, STATUS_TYPE_NORMAL, NULL, "Timeout to run (fuser-shutdown)."); ++ (void) kill(pid, SIGKILL); ++ } ++ } + } + + static int job_perform_on_unit(Job **j) { +diff --git a/src/core/main.c b/src/core/main.c +index 9f62b9d..eaae658 100644 +--- a/src/core/main.c ++++ b/src/core/main.c +@@ -123,6 +123,7 @@ bool arg_dump_core; + int arg_crash_chvt; + bool arg_crash_shell; + bool arg_crash_reboot; ++static bool arg_default_dfx_reboot; + static char *arg_confirm_spawn; + static ShowStatus arg_show_status; + static StatusUnitFormat arg_status_unit_format; +@@ -630,6 +631,7 @@ static int parse_config_file(void) { + { "Manager", "CrashChangeVT", config_parse_crash_chvt, 0, &arg_crash_chvt }, + { "Manager", "CrashShell", config_parse_bool, 0, &arg_crash_shell }, + { "Manager", "CrashReboot", config_parse_bool, 0, &arg_crash_reboot }, ++ { "Manager", "DefaultDFXReboot", config_parse_bool, 0, &arg_default_dfx_reboot }, + { "Manager", "ShowStatus", config_parse_show_status, 0, &arg_show_status }, + { "Manager", "StatusUnitFormat", config_parse_status_unit_format, 0, &arg_status_unit_format }, + { "Manager", "CPUAffinity", config_parse_cpu_affinity2, 0, &arg_cpu_affinity }, +@@ -754,6 +756,7 @@ static void set_manager_defaults(Manager *m) { + m->default_restart_usec = arg_default_restart_usec; + m->default_start_limit_interval = arg_default_start_limit_interval; + m->default_start_limit_burst = arg_default_start_limit_burst; ++ m->default_dfx_reboot = arg_default_dfx_reboot; + + /* On 4.15+ with unified hierarchy, CPU accounting is essentially free as it doesn't require the CPU + * controller to be enabled, so the default is to enable it unless we got told otherwise. */ +@@ -1512,19 +1515,21 @@ static int become_shutdown(int objective, int retval) { + + char log_levelDECIMAL_STR_MAX(int) + 1, + exit_codeDECIMAL_STR_MAX(uint8_t) + 1, +- timeoutDECIMAL_STR_MAX(usec_t) + 1; ++ timeoutDECIMAL_STR_MAX(usec_t) + 1, ++ dfx_rebootDECIMAL_STR_MAX(bool)+1; + +- const char* command_line13 = { ++ const char* command_line15 = { + SYSTEMD_SHUTDOWN_BINARY_PATH, + tableobjective, + "--timeout", timeout, + "--log-level", log_level, ++ "--dfx-reboot", dfx_reboot, + "--log-target", + }; + + _cleanup_strv_free_ char **env_block = NULL; + usec_t watchdog_timer = 0; +- size_t pos = 7; ++ size_t pos = 9; + int r; + + assert(objective >= 0 && objective < _MANAGER_OBJECTIVE_MAX); +@@ -1534,6 +1539,7 @@ static int become_shutdown(int objective, int retval) { + + xsprintf(log_level, "%d", log_get_max_level()); + xsprintf(timeout, "%" PRI_USEC "us", arg_default_timeout_stop_usec); ++ xsprintf(dfx_reboot, "%d", arg_default_dfx_reboot); + + switch (log_get_target()) { + +@@ -2421,6 +2427,7 @@ static void reset_arguments(void) { + arg_crash_chvt = -1; + arg_crash_shell = false; + arg_crash_reboot = false; ++ arg_default_dfx_reboot = false; + arg_confirm_spawn = mfree(arg_confirm_spawn); + arg_show_status = _SHOW_STATUS_INVALID; + arg_status_unit_format = STATUS_UNIT_FORMAT_DEFAULT; +diff --git a/src/core/manager.c b/src/core/manager.c +index 011de6b..4fa20f8 100644 +--- a/src/core/manager.c ++++ b/src/core/manager.c +@@ -828,6 +828,7 @@ int manager_new(LookupScope scope, ManagerTestRunFlags test_run_flags, Manager * + *m = (Manager) { + .unit_file_scope = scope, + .objective = _MANAGER_OBJECTIVE_INVALID, ++ .default_dfx_reboot = false, + + .status_unit_format = STATUS_UNIT_FORMAT_DEFAULT, + +diff --git a/src/core/manager.h b/src/core/manager.h +index 0196c52..d3f6aa2 100644 +--- a/src/core/manager.h ++++ b/src/core/manager.h +@@ -339,6 +339,8 @@ struct Manager { + /* Have we ever changed the "kernel.pid_max" sysctl? */ + bool sysctl_pid_max_changed; + ++ bool default_dfx_reboot; ++ + ManagerTestRunFlags test_run_flags; + + /* If non-zero, exit with the following value when the systemd +diff --git a/src/core/meson.build b/src/core/meson.build +index 981b46f..b03fcdd 100644 +--- a/src/core/meson.build ++++ b/src/core/meson.build +@@ -66,6 +66,7 @@ libcore_sources = files( + 'unit-printf.c', + 'unit-serialize.c', + 'unit.c', ++ 'fuser.c', + ) + + if conf.get('BPF_FRAMEWORK') == 1 +diff --git a/src/core/system.conf.in b/src/core/system.conf.in +index a44511b..e9a5420 100644 +--- a/src/core/system.conf.in ++++ b/src/core/system.conf.in +@@ -76,6 +76,7 @@ DefaultLimitMEMLOCK=64M + #DefaultLimitRTPRIO= + #DefaultLimitRTTIME= + #DefaultOOMPolicy=stop ++#DefaultDFXReboot=no + #DefaultSmackProcessLabel= + #ReloadLimitIntervalSec= + #ReloadLimitBurst= +diff --git a/src/shutdown/meson.build b/src/shutdown/meson.build +index d62032a..0ec8e76 100644 +--- a/src/shutdown/meson.build ++++ b/src/shutdown/meson.build +@@ -1,13 +1,18 @@ + # SPDX-License-Identifier: LGPL-2.1-or-later + ++shutdown_includes = includes, include_directories('.') ++ + systemd_shutdown_sources = files( + 'shutdown.c', + 'umount.c', ++ 'process-status.c', + ) + + tests += + files('test-umount.c', + 'umount.c'), +- , +- libmount, ++ libshared, ++ libcore, ++ libmount, ++ core_includes, + +diff --git a/src/shutdown/process-status.c b/src/shutdown/process-status.c +new file mode 100644 +index 0000000..11837a2 +--- /dev/null ++++ b/src/shutdown/process-status.c +@@ -0,0 +1,143 @@ ++#include "process-status.h" ++#include "process-util.h" ++ ++static uid_t P_uid; ++static int P_pid; ++static int P_ppid; ++static char P_statCOMM_LEN; ++static char P_cmd_shortCOMM_LEN; ++static char P_userCOMM_LEN; ++static char P_cmd_longCOMM_LEN; ++ ++static int read_from_stat(int pid) { ++ char bufPATH_MAX; ++ char cmd_pathPATH_MAX; ++ char pathnamePATH_MAX; ++ int fd = 0; ++ struct stat st; ++ int r = 0; ++ ++ memset(buf, 0, sizeof(buf)); ++ memset(cmd_path, 0, sizeof(cmd_path)); ++ memset(pathname, 0, sizeof(pathname)); ++ ++ r = snprintf(pathname, sizeof(pathname), "/proc/%d", pid); ++ if (r <= 0) { ++ manager_status_printf(NULL, STATUS_TYPE_NORMAL, NULL, ++ "Can't snprintf /proc/%d.", pid); ++ return -1; ++ } ++ ++ if (stat(pathname, &st) != 0) { ++ manager_status_printf(NULL, STATUS_TYPE_NORMAL, NULL, ++ "Can't stat %s.", pathname); ++ return -1; ++ } ++ ++ P_uid = st.st_uid; ++ ++ r = snprintf(buf, sizeof(buf), "/proc/%d/stat", pid); ++ if (r <= 0) { ++ manager_status_printf(NULL, STATUS_TYPE_NORMAL, NULL, ++ "Can't snprintf /proc/%d/stat.", pid); ++ return -1; ++ } ++ ++ fd = open(buf, O_RDONLY, 0); ++ if (fd == -1) { ++ manager_status_printf(NULL, STATUS_TYPE_NORMAL, NULL, ++ "Can't open %s.", buf); ++ return -1; ++ } ++ ++ r = read(fd, buf, sizeof(buf) - 1); ++ if (r < 0) { ++ manager_status_printf(NULL, STATUS_TYPE_NORMAL, NULL, ++ "Can't read /proc/%d/stat.", pid); ++ close(fd); ++ return -1; ++ } ++ ++ r = sscanf(buf, "%d %s %s %d", &P_pid, P_cmd_short, P_stat, &P_ppid); ++ if (r < 0) { ++ manager_status_printf(NULL, STATUS_TYPE_NORMAL, NULL, ++ "Can't run sscanf."); ++ close(fd); ++ return -1; ++ } ++ ++ close(fd); ++ ++ if(P_pid != pid) ++ return -1; ++ ++ r = snprintf(cmd_path, sizeof(cmd_path), "/proc/%d", pid); ++ if (r <= 0) { ++ manager_status_printf(NULL, STATUS_TYPE_NORMAL, NULL, "Can't snprintf /proc/%d.", pid); ++ return -1; ++ } ++ ++ /* read from /proc/$pid/cmdline */ ++ read_cmdline(P_cmd_long, sizeof(P_cmd_long), cmd_path, "cmdline", ' '); ++ ++ return 0; ++} ++ ++static void do_user(void) { ++ struct passwd *p = NULL; ++ ++ p = getpwuid(P_uid); ++ if (p) { ++ snprintf(P_user, sizeof(P_user), "%s", p->pw_name); ++ } else { ++ snprintf(P_user, sizeof(P_user), "%u", P_uid); ++ } ++} ++ ++static void print_proc(void) { ++ if ((P_ppid != KTHREADD) && (strcmp(P_cmd_short, "(kthreadd)") != 0)) { ++ if (strlen(P_cmd_long) != 0) { ++ manager_status_printf(NULL, STATUS_TYPE_NORMAL,"systemd-shutdown", ++ "%-s\t%-d\t%-d\t%-s", P_user, P_pid, P_ppid, P_cmd_long); ++ } else { ++ manager_status_printf(NULL, STATUS_TYPE_NORMAL,"systemd-shutdown", ++ "%-s\t%-d\t%-d\t%-s", P_user, P_pid, P_ppid, P_cmd_short); ++ } ++ } ++} ++ ++int process_status(void) { ++ manager_status_printf(NULL, STATUS_TYPE_NORMAL,"systemd-shutdown", ++ "%s", "-----------------------------------------------------------------"); ++ manager_status_printf(NULL, STATUS_TYPE_NORMAL,"systemd-shutdown", ++ "%s", "USER\tPID\tPPID\tCMD"); ++ ++ struct dirent *ent = NULL; ++ DIR *dir = NULL; ++ ++ dir = opendir("/proc"); ++ if (dir == NULL) { ++ manager_status_printf(NULL, STATUS_TYPE_NORMAL,"systemd-shutdown", ++ "%s", "can't open /proc"); ++ return -1; ++ } ++ ++ while((ent = readdir(dir))){ ++ if (*ent->d_name < '0' || *ent->d_name > '9') ++ continue; ++ ++ if (read_from_stat(atoi(ent->d_name)) != 0) ++ continue; ++ ++ do_user(); ++ ++ print_proc(); ++ } ++ ++ closedir(dir); ++ ++ manager_status_printf(NULL, STATUS_TYPE_NORMAL,"systemd-shutdown", ++ "%s", "------------------------------------------------------------------"); ++ ++ return 0; ++} +diff --git a/src/shutdown/process-status.h b/src/shutdown/process-status.h +new file mode 100644 +index 0000000..2f4333d +--- /dev/null ++++ b/src/shutdown/process-status.h +@@ -0,0 +1,24 @@ ++#pragma once ++ ++#include <fcntl.h> ++#include <stdio.h> ++#include <dirent.h> ++#include <string.h> ++#include <pwd.h> ++#include <stdlib.h> ++#include <unistd.h> ++#include <sys/stat.h> ++#include <limits.h> ++#include <errno.h> ++ ++#include "manager.h" ++ ++#define COMM_LEN 512 ++ ++#ifndef PATH_MAX ++#define PATH_MAX 4096 ++#endif ++ ++#define KTHREADD 2 ++ ++int process_status(void); +diff --git a/src/shutdown/shutdown.c b/src/shutdown/shutdown.c +index 42111d2..1bbabfb 100644 +--- a/src/shutdown/shutdown.c ++++ b/src/shutdown/shutdown.c +@@ -40,13 +40,17 @@ + #include "umount.h" + #include "virt.h" + #include "watchdog.h" ++#include "process-status.h" + + #define SYNC_PROGRESS_ATTEMPTS 3 + #define SYNC_TIMEOUT_USEC (10*USEC_PER_SEC) ++#define SHUTDOWN_TIMEOUT_MIN (0*USEC_PER_SEC) ++#define SHUTDOWN_TIMEOUT_INTERVAL (30*USEC_PER_SEC) + + static char* arg_verb; + static uint8_t arg_exit_code; + static usec_t arg_timeout = DEFAULT_TIMEOUT_USEC; ++static bool dfx_reboot = false; + + static int parse_argv(int argc, char *argv) { + enum { +@@ -57,6 +61,7 @@ static int parse_argv(int argc, char *argv) { + ARG_LOG_TIME, + ARG_EXIT_CODE, + ARG_TIMEOUT, ++ ARG_DFX_REBOOT, + }; + + static const struct option options = { +@@ -67,6 +72,7 @@ static int parse_argv(int argc, char *argv) { + { "log-time", optional_argument, NULL, ARG_LOG_TIME }, + { "exit-code", required_argument, NULL, ARG_EXIT_CODE }, + { "timeout", required_argument, NULL, ARG_TIMEOUT }, ++ { "dfx-reboot", required_argument, NULL, ARG_DFX_REBOOT }, + {} + }; + +@@ -80,6 +86,13 @@ static int parse_argv(int argc, char *argv) { + while ((c = getopt_long(argc, argv, "-", options, NULL)) >= 0) + switch (c) { + ++ case ARG_DFX_REBOOT: ++ if (streq(optarg, "1")) { ++ dfx_reboot = true; ++ } ++ ++ break; ++ + case ARG_LOG_LEVEL: + r = log_set_max_level_from_string(optarg); + if (r < 0) +@@ -340,6 +353,9 @@ int main(int argc, char *argv) { + _cleanup_free_ char *cgroup = NULL; + char *arguments3; + int cmd, r; ++ usec_t now_time, time_interval; ++ pid_t pid; ++ bool fork_failed = false; + + /* The log target defaults to console, but the original systemd process will pass its log target in through a + * command line argument, which will override this default. Also, ensure we'll never log to the journal or +@@ -425,8 +441,37 @@ int main(int argc, char *argv) { + need_dm_detach = !in_container, need_md_detach = !in_container, can_initrd, last_try = false; + can_initrd = !in_container && !in_initrd() && access("/run/initramfs/shutdown", X_OK) == 0; + ++ now_time = now(CLOCK_MONOTONIC); ++ time_interval = SHUTDOWN_TIMEOUT_MIN; + /* Unmount all mountpoints, swaps, and loopback devices */ + for (;;) { ++ if (dfx_reboot && (now(CLOCK_MONOTONIC) >= now_time + time_interval)) { ++ r = safe_fork("(process_status)", FORK_RESET_SIGNALS, &pid); ++ if (r < 0) { ++ manager_status_printf(NULL, STATUS_TYPE_NORMAL, NULL, ++ "Failed to fork for process_status!"); ++ fork_failed = true; ++ } ++ if (r == 0) { ++ r = process_status(); ++ if (r < 0) ++ manager_status_printf(NULL, STATUS_TYPE_NORMAL, NULL, "Can't run ps."); ++ ++ _exit(r < 0 ? EXIT_FAILURE : EXIT_SUCCESS); ++ } ++ ++ now_time = now(CLOCK_MONOTONIC); ++ time_interval = SHUTDOWN_TIMEOUT_INTERVAL; ++ ++ if (!fork_failed) { ++ r = wait_for_terminate_with_timeout(pid, 3 * USEC_PER_SEC); ++ if (r == -ETIMEDOUT) { ++ manager_status_printf(NULL, STATUS_TYPE_NORMAL, NULL, "Timeout to run (process_status)."); ++ (void) kill(pid, SIGKILL); ++ } ++ } ++ } ++ + bool changed = false; + + (void) watchdog_ping(); +diff --git a/src/shutdown/umount.c b/src/shutdown/umount.c +index 61bd9d2..ecba3d4 100644 +--- a/src/shutdown/umount.c ++++ b/src/shutdown/umount.c +@@ -48,6 +48,7 @@ + #include "sync-util.h" + #include "umount.h" + #include "virt.h" ++#include "manager.h" + + static void mount_point_free(MountPoint **head, MountPoint *m) { + assert(head); +@@ -678,6 +679,7 @@ static int umount_with_timeout(MountPoint *m, bool last_try) { + pfd0 = safe_close(pfd0); + + log_info("Unmounting '%s'.", m->path); ++ manager_status_printf(NULL, STATUS_TYPE_NORMAL, NULL, "Unmounting '%s'.", m->path); + + /* Start the mount operation here in the child Using MNT_FORCE causes some filesystems + * (e.g. FUSE and NFS and other network filesystems) to abort any pending requests and return +@@ -689,9 +691,12 @@ static int umount_with_timeout(MountPoint *m, bool last_try) { + (m->umount_lazily ? MNT_DETACH : MNT_FORCE))); + if (r < 0) { + log_full_errno(last_try ? LOG_ERR : LOG_INFO, r, "Failed to unmount %s: %m", m->path); ++ manager_status_printf(NULL, STATUS_TYPE_NORMAL, NULL, "Failed to unmount '%s'.", m->path); + + if (r == -EBUSY && last_try) + log_umount_blockers(m->path); ++ } else { ++ manager_status_printf(NULL, STATUS_TYPE_NORMAL, NULL, "Unmounted '%s'.", m->path); + } + + (void) write(pfd1, &r, sizeof(r)); /* try to send errno up */ +diff --git a/src/test/meson.build b/src/test/meson.build +index be99212..e0a40b8 100644 +--- a/src/test/meson.build ++++ b/src/test/meson.build +@@ -700,6 +700,21 @@ tests += + files('test-sha256.c'), + + files('test-open-file.c'), ++ ++ files('test-process-status.c', ++ '../shutdown/process-status.c'), ++ libcore, ++ libshared, ++ , ++ shutdown_includes, ++ core_includes, ++ ++ files('test-fuser.c', ++ '../core/fuser.c'), ++ libcore, ++ libshared, ++ , ++ core_includes, + + + ############################################################ +diff --git a/src/test/test-fuser.c b/src/test/test-fuser.c +new file mode 100644 +index 0000000..1527b5b +--- /dev/null ++++ b/src/test/test-fuser.c +@@ -0,0 +1,14 @@ ++#include "fuser.h" ++#include "tests.h" ++ ++int main(int argc, char *argv){ ++ test_setup_logging(LOG_DEBUG); ++ ++ assert_se(fuser("/") == 0); ++ assert_se(fuser(NULL) < 0); ++ assert_se(fuser("/dev") == 0); ++ assert_se(fuser("/dev/empty/mountpoint") < 0); ++ assert_se(fuser("") < 0); ++ ++ return 0; ++} +diff --git a/src/test/test-process-status.c b/src/test/test-process-status.c +new file mode 100644 +index 0000000..4a4c3da +--- /dev/null ++++ b/src/test/test-process-status.c +@@ -0,0 +1,10 @@ ++#include "process-status.h" ++#include "tests.h" ++ ++int main(int argc, char *argv){ ++ ++ assert_se(process_status() == 0); ++ ++ return 0; ++ ++} +-- +2.33.0 +
View file
_service:tar_scm:process-util-log-more-information-when-runnin.patch
Added
@@ -0,0 +1,147 @@ +From f4b4008495211c60bda7e1edda45beb36a553bc7 Mon Sep 17 00:00:00 2001 +From: licunlong<licunlong1@huawei.com> +Date: Thu, 14 Jan 2021 15:57:59 +0800 +Subject: PATCH process-util: log more information when running + systemctl. + + Print the PID and its cmdline to the system log when a process + runs systemctl command. +--- + src/basic/process-util.c | 31 +++++++++++++++++++++++++++++++ + src/basic/process-util.h | 1 + + src/systemctl/systemctl.c | 12 ++++++++++++ + src/test/test-process-util.c | 22 ++++++++++++++++++++++ + 4 files changed, 66 insertions(+) + +diff --git a/src/basic/process-util.c b/src/basic/process-util.c +index b6bf83c..aaf5e87 100644 +--- a/src/basic/process-util.c ++++ b/src/basic/process-util.c +@@ -49,6 +49,7 @@ + #include "stdio-util.h" + #include "string-table.h" + #include "string-util.h" ++#include "strv.h" + #include "terminal-util.h" + #include "user-util.h" + #include "utf8.h" +@@ -258,6 +259,36 @@ int get_process_cmdline(pid_t pid, size_t max_columns, ProcessCmdlineFlags flags + return 0; + } + ++int print_process_cmdline_with_arg(pid_t pid, int argc, char *argv, char *filter) { ++ bool is_filtered = false; ++ int r; ++ const char *arg_cmdline = ""; ++ _cleanup_free_ char *cmdline = NULL; ++ ++ r = get_process_cmdline(pid, SIZE_MAX, 0, &cmdline); ++ if (r < 0) { ++ syslog(LOG_INFO, "Failed to get cmdline of PID %d. Ignoring.", pid); ++ return r; ++ } else { ++ for (int i = 0; i < argc; i++ ) { ++ if (filter && strv_find(filter, argvi)) { ++ is_filtered = true; ++ break; ++ } ++ if (i == 0) { ++ arg_cmdline = strjoina(arg_cmdline, argvi); ++ } else { ++ arg_cmdline = strjoina(arg_cmdline, " ", argvi); ++ } ++ } ++ if (!is_filtered) { ++ syslog(LOG_INFO, "%s called by PID %d (%s)", arg_cmdline, pid, cmdline); ++ } ++ return 0; ++ } ++ ++} ++ + int container_get_leader(const char *machine, pid_t *pid) { + _cleanup_free_ char *s = NULL, *class = NULL; + const char *p; +diff --git a/src/basic/process-util.h b/src/basic/process-util.h +index 96da0bb..135386c 100644 +--- a/src/basic/process-util.h ++++ b/src/basic/process-util.h +@@ -40,6 +40,7 @@ typedef enum ProcessCmdlineFlags { + + int get_process_comm(pid_t pid, char **ret); + int get_process_cmdline(pid_t pid, size_t max_columns, ProcessCmdlineFlags flags, char **ret); ++int print_process_cmdline_with_arg(pid_t pid, int argc, char *argv, char *filter); + int get_process_exe(pid_t pid, char **ret); + int get_process_uid(pid_t pid, uid_t *ret); + int get_process_gid(pid_t pid, gid_t *ret); +diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c +index 4e7fd04..6143505 100644 +--- a/src/systemctl/systemctl.c ++++ b/src/systemctl/systemctl.c +@@ -2,6 +2,7 @@ + + #include <getopt.h> + #include <locale.h> ++#include <sys/types.h> + #include <unistd.h> + + #include "sd-daemon.h" +@@ -1153,6 +1154,14 @@ static int run(int argc, char *argv) { + _cleanup_(loop_device_unrefp) LoopDevice *loop_device = NULL; + _cleanup_(umount_and_rmdir_and_freep) char *mounted_dir = NULL; + int r; ++ pid_t ppid; ++ char *filter = { ++ "status", "show", "cat", ++ "is-active", "is-failed", "is-enabled", "is-system-running", ++ "list-units", "list-sockets", "list-timers", "list-dependencies", ++ "list-unit-files", "list-machines", "list-jobs", ++ "get-default", "show-environment", NULL ++ }; + + setlocale(LC_ALL, ""); + log_setup(); +@@ -1166,6 +1175,9 @@ static int run(int argc, char *argv) { + if (r <= 0) + goto finish; + ++ ppid = getppid(); ++ (void) print_process_cmdline_with_arg(ppid, argc, argv, filter); ++ + if (proc_mounted() == 0) + log_full(arg_no_warn ? LOG_DEBUG : LOG_WARNING, + "%s%s/proc/ is not mounted. This is not a supported mode of operation. Please fix\n" +diff --git a/src/test/test-process-util.c b/src/test/test-process-util.c +index 1864f8a..3a844cf 100644 +--- a/src/test/test-process-util.c ++++ b/src/test/test-process-util.c +@@ -798,4 +798,26 @@ static int intro(void) { + return EXIT_SUCCESS; + } + ++TEST(print_process_cmdline_with_arg) { ++ pid_t pid = getpid(); ++ char *arg_filter_empty = {"", NULL}; ++ char *arg_filter_1_in = {"status", NULL}; ++ char *arg_filter_1_no = {"stop", NULL}; ++ char *arg_filter_2_in = {"restart", "status", NULL}; ++ char *arg_filter_2_no = {"restart", "stop", NULL}; ++ char *arg_var_11 = {"systemctl"}; ++ char *arg_var_1010 = {"systemctl", "restart", "1", "2", "3", "4", "5", "6", "7", "8"}; ++ char *arg_var_filter3 = {"systemctl", "status", "dbus.service"}; ++ assert_se(print_process_cmdline_with_arg(pid, 0, NULL, NULL) >=0); ++ assert_se(print_process_cmdline_with_arg(pid, 1, arg_var_1, NULL) >= 0); ++ assert_se(print_process_cmdline_with_arg(pid, 10, arg_var_10, NULL) >= 0); ++ assert_se(print_process_cmdline_with_arg(897349, 1, arg_var_1, NULL) < 0); ++ assert_se(print_process_cmdline_with_arg(897349, 10, arg_var_10, NULL) < 0); ++ assert_se(print_process_cmdline_with_arg(pid, 3, arg_var_filter, arg_filter_empty) >= 0); ++ assert_se(print_process_cmdline_with_arg(pid, 3, arg_var_filter, arg_filter_1_in) >= 0); ++ assert_se(print_process_cmdline_with_arg(pid, 3, arg_var_filter, arg_filter_1_no) >= 0); ++ assert_se(print_process_cmdline_with_arg(pid, 3, arg_var_filter, arg_filter_2_in) >= 0); ++ assert_se(print_process_cmdline_with_arg(pid, 3, arg_var_filter, arg_filter_2_no) >= 0); ++} ++ + DEFINE_TEST_MAIN_WITH_INTRO(LOG_INFO, intro); +-- +2.33.0 +
View file
_service:tar_scm:resolved-create-etc-resolv.conf-symlink-at-runtime.patch
Added
@@ -0,0 +1,48 @@ +From 0c670fec00f3d5c103d9b7415d4e0510c61ad006 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl> +Date: Fri, 11 Mar 2016 17:06:17 -0500 +Subject: PATCH resolved: create /etc/resolv.conf symlink at runtime + +If the symlink doesn't exists, and we are being started, let's +create it to provie name resolution. + +If it exists, do nothing. In particular, if it is a broken symlink, +we cannot really know if the administator configured it to point to +a location used by some service that hasn't started yet, so we +don't touch it in that case either. + +https://bugzilla.redhat.com/show_bug.cgi?id=1313085 +--- + src/resolve/resolved.c | 5 +++++ + tmpfiles.d/systemd-resolve.conf | 2 -- + 2 files changed, 5 insertions(+), 2 deletions(-) + +diff --git a/src/resolve/resolved.c b/src/resolve/resolved.c +index d3bc902..a94d744 100644 +--- a/src/resolve/resolved.c ++++ b/src/resolve/resolved.c +@@ -58,6 +58,11 @@ static int run(int argc, char *argv) { + if (r < 0) + return log_error_errno(r, "Could not create runtime directory: %m"); + ++ r = symlink("../run/systemd/resolve/resolv.conf", "/etc/resolv.conf"); ++ if (r < 0 && errno != EEXIST) ++ log_warning_errno(errno, ++ "Could not create /etc/resolv.conf symlink: %m"); ++ + /* Drop privileges, but keep three caps. Note that we drop two of those too, later on (see below) */ + r = drop_privileges(uid, gid, + (UINT64_C(1) << CAP_NET_RAW)| /* needed for SO_BINDTODEVICE */ +diff --git a/tmpfiles.d/systemd-resolve.conf b/tmpfiles.d/systemd-resolve.conf +index cb1c56d..ce3d1a6 100644 +--- a/tmpfiles.d/systemd-resolve.conf ++++ b/tmpfiles.d/systemd-resolve.conf +@@ -6,5 +6,3 @@ + # (at your option) any later version. + + # See tmpfiles.d(5) for details +- +-L! /etc/resolv.conf - - - - ../run/systemd/resolve/stub-resolv.conf +-- +2.33.0 +
View file
_service:tar_scm:revert-rpm-restart-services-in-posttrans.patch
Added
@@ -0,0 +1,31 @@ +From 3b2ba67cfc83905a88e3ebb88a2b43222a06e869 Mon Sep 17 00:00:00 2001 +From: wangyuhang <wangyuhang27@huawei.com> +Date: Fri, 17 Jun 2022 14:26:16 +0800 +Subject: PATCH revert rpm: restart services in %posttrans +Reason:In version 22.03, if we do not add 'systemctl reload or restart --marked' in +%transfiletriggerpostun, %systemd_postun_with_restart will not restart the +service. In order to maintain compatibility with version 20.03, revert the commit +and use the version 20.03 scheme + +Conflict:NA +Reference:https://github.com/systemd/systemd/commit/fa97d2fcf64e0558054bee673f734f523373b146 +--- + src/rpm/macros.systemd.in | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/rpm/macros.systemd.in b/src/rpm/macros.systemd.in +index 8880078..b1a297e 100644 +--- a/src/rpm/macros.systemd.in ++++ b/src/rpm/macros.systemd.in +@@ -89,7 +89,7 @@ fi \ + %{expand:%%{?__systemd_someargs_%#:%%__systemd_someargs_%# systemd_postun_with_restart}} \ + if $1 -ge 1 && -x "{{SYSTEMD_UPDATE_HELPER_PATH}}" ; then \ + # Package upgrade, not uninstall \ +- {{SYSTEMD_UPDATE_HELPER_PATH}} mark-restart-system-units %{?*} || : \ ++ %{_bindir}/systemctl try-restart %{?*} || : \ + fi \ + %{nil} + +-- +2.33.0 +
View file
_service:tar_scm:rules-add-elevator-kernel-command-line-parameter.patch
Added
@@ -0,0 +1,42 @@ +From 1255584bb0a595fb555af7e14230ab1b7aa6adcd Mon Sep 17 00:00:00 2001 +From: Lukas Nykryn <lnykryn@redhat.com> +Date: Tue, 12 Feb 2019 16:58:16 +0100 +Subject: PATCH rules: add elevator= kernel command line parameter + +Kernel removed the elevator= option + +Resolves: #1670126 +--- + rules.d/40-elevator.rules | 20 ++++++++++++++++++++ + 1 file changed, 20 insertions(+) + create mode 100644 rules.d/40-elevator.rules + +diff --git a/rules.d/40-elevator.rules b/rules.d/40-elevator.rules +new file mode 100644 +index 0000000000..5f615bf51a +--- /dev/null ++++ b/rules.d/40-elevator.rules +@@ -0,0 +1,20 @@ ++# We aren't adding devices skip the elevator check ++ACTION!="add", GOTO="sched_out" ++ ++SUBSYSTEM!="block", GOTO="sched_out" ++ENV{DEVTYPE}!="disk", GOTO="sched_out" ++ ++# Technically, dm-multipath can be configured to use an I/O scheduler. ++# However, there are races between the 'add' uevent and the linking in ++# of the queue/scheduler sysfs file. For now, just skip dm- devices. ++KERNEL=="dm-*|md*", GOTO="sched_out" ++ ++# Skip bio-based devices, which don't support an I/O scheduler. ++ATTR{queue/scheduler}=="none", GOTO="sched_out" ++ ++# If elevator= is specified on the kernel command line, change the ++# scheduler to the one specified. ++IMPORT{cmdline}="elevator" ++ENV{elevator}!="", ATTR{queue/scheduler}="$env{elevator}" ++ ++LABEL="sched_out" +-- +2.23.0 +
View file
_service:tar_scm:rules-add-rule-for-naming-Dell-iDRAC-USB-Virtual-NIC.patch
Added
@@ -0,0 +1,40 @@ +From 2991b22f5f40a66ad1cc088e502e7f40ae1806c2 Mon Sep 17 00:00:00 2001 +From: Michal Sekletar <msekleta@redhat.com> +Date: Mon, 22 Sep 2014 07:53:52 +0200 +Subject: rules: add rule for naming Dell iDRAC USB Virtual NIC + as 'idrac' + +Related: #1523227 +--- + rules.d/73-idrac.rules | 6 ++++++ + rules.d/meson.build | 1 + + 2 files changed, 7 insertions(+) + create mode 100644 rules.d/73-idrac.rules + +diff --git a/rules.d/73-idrac.rules b/rules.d/73-idrac.rules +new file mode 100644 +index 0000000..d67fc42 +--- /dev/null ++++ b/rules.d/73-idrac.rules +@@ -0,0 +1,6 @@ ++# do not edit this file, it will be overwritten on update ++ ++# On Dell PowerEdge systems, the iDRAC7 and later support a USB Virtual NIC ++# with terminates in the iDRAC. Help identify this with 'idrac' ++ ++ACTION=="add", SUBSYSTEM=="net", SUBSYSTEMS=="usb", ATTRS{idVendor}=="413c", ATTRS{idProduct}=="a102", NAME="idrac" +diff --git a/rules.d/meson.build b/rules.d/meson.build +index cba9dd4..39e174d 100644 +--- a/rules.d/meson.build ++++ b/rules.d/meson.build +@@ -24,6 +24,7 @@ rules = + '70-joystick.rules', + '70-mouse.rules', + '70-touchpad.rules', ++ '73-idrac.rules', + '75-net-description.rules', + '75-probe_mtd.rules', + '78-sound-card.rules', +-- +2.33.0 +
View file
_service:tar_scm:rules-add-the-rule-that-adds-elevator-kernel-command.patch
Added
@@ -0,0 +1,29 @@ +From 16d1f6e5122038fa24392e166a0a88c6cab41dd0 Mon Sep 17 00:00:00 2001 +From: Lukas Nykryn <lnykryn@redhat.com> +Date: Tue, 26 Feb 2019 15:22:38 +0100 +Subject: PATCH rules: add the rule that adds elevator= kernel + command line parameter + +Resolves: #1670126 + +--- + rules.d/meson.build | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/rules.d/meson.build b/rules.d/meson.build +index 39e174d..e356183 100644 +--- a/rules.d/meson.build ++++ b/rules.d/meson.build +@@ -5,7 +5,8 @@ install_data( + install_dir : udevrulesdir) + + rules = +- files('60-autosuspend.rules', ++ files('40-elevator.rules', ++ '60-autosuspend.rules', + '60-block.rules', + '60-cdrom_id.rules', + '60-drm.rules', +-- +2.33.0 +
View file
_service:tar_scm:sd-bus-properly-initialize-containers.patch
Added
@@ -0,0 +1,31 @@ +From 220a60a61a91153fd8e49e58884b9b0b904888f6 Mon Sep 17 00:00:00 2001 +From: Jan Synacek <jsynacek@redhat.com> +Date: Wed, 31 Oct 2018 12:50:19 +0100 +Subject: PATCH sd-bus: properly initialize containers + +Fixes a SIGSEGV introduced by commit 38a5315a3a6fab745d8c86ff9e486faaf50b28d1. +The same problem doesn't exist upstream, as the container structure +there is initialized using a compound literal, which is zeroed out by +default. + +Related: #1635435 + +--- + src/libsystemd/sd-bus/bus-message.c | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/src/libsystemd/sd-bus/bus-message.c b/src/libsystemd/sd-bus/bus-message.c +index 9719f97..ec6cd57 100644 +--- a/src/libsystemd/sd-bus/bus-message.c ++++ b/src/libsystemd/sd-bus/bus-message.c +@@ -1783,6 +1783,7 @@ _public_ int sd_bus_message_open_container( + .enclosing = type, + .signature = TAKE_PTR(signature), + .array_size = array_size, ++ .peeked_signature = NULL, + .before = before, + .begin = begin, + }; +-- +2.33.0 +
View file
_service:tar_scm:set-forwardtowall-no-to-avoid-emerg-log-shown-on-she.patch
Added
@@ -0,0 +1,39 @@ +From 22f8c4c2a22d9766d86b23429bd404a0864b0a9e Mon Sep 17 00:00:00 2001 +From: linfeilong <linfeilong@huawei.com> +Date: Sat, 21 Oct 2017 14:48:18 +0800 +Subject: PATCH set forwardtowall no to avoid emerg log shown on shell + +--- + man/journald.conf.xml | 2 +- + src/journal/journald.conf | 2 +- + 2 files changed, 2 insertions(+), 2 deletions(-) + +diff --git a/man/journald.conf.xml b/man/journald.conf.xml +index 44fd0d2..8d38fe3 100644 +--- a/man/journald.conf.xml ++++ b/man/journald.conf.xml +@@ -292,7 +292,7 @@ + traditional syslog daemon, to the kernel log buffer (kmsg), to the system console, or sent as wall + messages to all logged-in users. These options take boolean arguments. If forwarding to syslog is + enabled but nothing reads messages from the socket, forwarding to syslog has no effect. By default, +- only forwarding to wall is enabled. These settings may be overridden at boot time with the kernel ++ these four configs are all disabled. These settings may be overridden at boot time with the kernel + command line options <literal>systemd.journald.forward_to_syslog</literal>, + <literal>systemd.journald.forward_to_kmsg</literal>, + <literal>systemd.journald.forward_to_console</literal>, and +diff --git a/src/journal/journald.conf b/src/journal/journald.conf +index 2f1c661..17dda27 100644 +--- a/src/journal/journald.conf ++++ b/src/journal/journald.conf +@@ -32,7 +32,7 @@ + #ForwardToSyslog=no + #ForwardToKMsg=no + #ForwardToConsole=no +-#ForwardToWall=yes ++ForwardToWall=no + #TTYPath=/dev/console + #MaxLevelStore=debug + #MaxLevelSyslog=debug +-- +2.19.1 +
View file
_service:tar_scm:set-the-cpuset.cpus-mems-of-machine.slice-to-all-by-.patch
Added
@@ -0,0 +1,46 @@ +From 14b69596b0bff64f7482d93ea3f043520a716921 Mon Sep 17 00:00:00 2001 +From: rpm-build <rpm-build> +Date: Thu, 8 Jun 2023 20:02:50 +0800 +Subject: PATCH set the cpuset.cpus/mems of machine.slice to all by default + This is necessary after merging core-cgroup-support-cpuset.patch. + +When creating a vm, libvirt will issue a dbus method_call to +systemd-machined. systemd-machined will start transient unit +usually named xxx.scope with Delegate=1 set after receiving +the method_call. If Delegate=1 is set, systemd will create +machine.slice in /sys/fs/cgroup for every cgroup subsystem, this +includes cpuset. cpuset is different, you can't migrate processes +to the created directory unless you have set proper cpuset.cpus +and cpuset.mems. + +Without this patch, libvirt sees machine.slice, it won't check +if cpuset.cpus or cpuset.mems is valid, and just migrate the vm +process to machine.slice. This action will fail because core-cgroup +-support-cpuset.patch only supports create the machine.slice +directory when Delegate=1 is set, but won't set cpuset.cpus +and cpuset.mems automatically. + +Now we have this patch, it will make systemd automatically set +cpuset.cpus and cpuset.mems according to /sys/fs/cgroup/cpuset/{ +cpuset.cpus, cpuset.mems}. Then libvirt can migrate vm processes +freely. +--- + units/machine.slice | 5 +++++ + 1 file changed, 5 insertions(+) + +diff --git a/units/machine.slice b/units/machine.slice +index 501d353..8d87851 100644 +--- a/units/machine.slice ++++ b/units/machine.slice +@@ -11,3 +11,8 @@ + Description=Virtual Machine and Container Slice + Documentation=man:systemd.special(7) + Before=slices.target ++ ++Slice ++CPUSetCpus=all ++CPUSetMems=all ++CPUSetCloneChildren=1 +-- +2.33.0 +
View file
_service:tar_scm:shutdown-reboot-when-recieve-crash-signal.patch
Added
@@ -0,0 +1,63 @@ +From 3ac4d1fc1a067afc0e0d4ca37a44ac252ee8b96b Mon Sep 17 00:00:00 2001 +From: xujing <xujing99@huawei.com> +Date: Tue, 8 Feb 2022 21:02:31 +0800 +Subject: PATCH shutdown: reboot when recieve crash signal + +--- + src/shutdown/shutdown.c | 33 +++++++++++++++++++++++++++++++++ + 1 file changed, 33 insertions(+) + +diff --git a/src/shutdown/shutdown.c b/src/shutdown/shutdown.c +index 1bbabfb..8f68559 100644 +--- a/src/shutdown/shutdown.c ++++ b/src/shutdown/shutdown.c +@@ -322,6 +322,26 @@ static void bump_sysctl_printk_log_level(int min_level) { + log_debug_errno(r, "Failed to bump kernel.printk to %i: %m", min_level + 1); + } + ++_noreturn_ static void crash(int sig) { ++ if (getpid_cached() != 1) ++ /* Pass this on immediately, if this is not PID 1 */ ++ (void) raise(sig); ++ else { ++ bool in_container = detect_container() > 0; ++ ++ log_info("Recieve signal %d.", sig); ++ ++ broadcast_signal(SIGTERM, true, true, arg_timeout); ++ broadcast_signal(SIGKILL, true, false, arg_timeout); ++ ++ if (!in_container) ++ sync_with_progress(); ++ ++ log_info("Rebooting now."); ++ (void) reboot(RB_AUTOBOOT); ++ } ++} ++ + static void init_watchdog(void) { + const char *s; + int r; +@@ -356,6 +376,19 @@ int main(int argc, char *argv) { + usec_t now_time, time_interval; + pid_t pid; + bool fork_failed = false; ++ static const struct sigaction sa = { ++ .sa_handler = crash, ++ .sa_flags = SA_NODEFER, /* So that we can raise the signal again from the signal handler */ ++ }; ++ ++ (void) reset_all_signal_handlers(); ++ (void) ignore_signals(SIGNALS_IGNORE, -1); ++ ++ /* We ignore the return value here, since, we don't mind if we ++ * cannot set up a crash handler */ ++ r = sigaction_many(&sa, SIGNALS_CRASH_HANDLER, -1); ++ if (r < 0) ++ log_debug_errno(r, "I had trouble setting up the crash handler, ignoring: %m"); + + /* The log target defaults to console, but the original systemd process will pass its log target in through a + * command line argument, which will override this default. Also, ensure we'll never log to the journal or +-- +2.33.0 +
View file
_service:tar_scm:support-disable-cgroup-controllers-we-don-t-want.patch
Added
@@ -0,0 +1,216 @@ +From ef31366523d784d92f25abd99b3782acda29a01c Mon Sep 17 00:00:00 2001 +From: xujing <xujing125@huawei.com> +Date: Fri, 8 Jul 2022 19:47:45 +0800 +Subject: PATCH support disable cgroup controllers we don't want + +--- + src/basic/cgroup-util.c | 14 +++++++++++ + src/basic/cgroup-util.h | 1 + + src/core/cgroup.c | 1 + + src/core/main.c | 7 ++++++ + src/core/manager.h | 2 ++ + src/core/system.conf.in | 1 + + src/shared/conf-parser.c | 54 ++++++++++++++++++++++++++++++++++++++++ + src/shared/conf-parser.h | 1 + + 8 files changed, 81 insertions(+) + +diff --git a/src/basic/cgroup-util.c b/src/basic/cgroup-util.c +index ac25693..a7c839c 100644 +--- a/src/basic/cgroup-util.c ++++ b/src/basic/cgroup-util.c +@@ -2052,6 +2052,20 @@ int cg_mask_supported(CGroupMask *ret) { + return cg_mask_supported_subtree(root, ret); + } + ++int cg_mask_disable_cgroup(CGroupMask disabled, CGroupMask *ret) { ++ int r; ++ ++ r = cg_all_unified(); ++ if (r < 0) ++ return r; ++ ++ /* We only care CGROUP_V1 */ ++ if (r == 0) ++ *ret &= ~disabled; ++ ++ return 0; ++} ++ + int cg_kernel_controllers(Set **ret) { + _cleanup_set_free_ Set *controllers = NULL; + _cleanup_fclose_ FILE *f = NULL; +diff --git a/src/basic/cgroup-util.h b/src/basic/cgroup-util.h +index 147c956..a539327 100644 +--- a/src/basic/cgroup-util.h ++++ b/src/basic/cgroup-util.h +@@ -295,6 +295,7 @@ typedef const char* (*cg_migrate_callback_t)(CGroupMask mask, void *userdata); + + int cg_mask_supported(CGroupMask *ret); + int cg_mask_supported_subtree(const char *root, CGroupMask *ret); ++int cg_mask_disable_cgroup(CGroupMask disabled, CGroupMask *ret); + int cg_mask_from_string(const char *s, CGroupMask *ret); + int cg_mask_to_string(CGroupMask mask, char **ret); + +diff --git a/src/core/cgroup.c b/src/core/cgroup.c +index 9987dac..af58b9b 100644 +--- a/src/core/cgroup.c ++++ b/src/core/cgroup.c +@@ -3646,6 +3646,7 @@ int manager_setup_cgroup(Manager *m) { + if (r < 0) + return log_error_errno(r, "Failed to determine supported bpf-based pseudo-controllers: %m"); + m->cgroup_supported |= mask; ++ m->system_cgroup_supported = m->cgroup_supported; + + /* 10. Log which controllers are supported */ + for (CGroupController c = 0; c < _CGROUP_CONTROLLER_MAX; c++) +diff --git a/src/core/main.c b/src/core/main.c +index 990e4d2..5404e24 100644 +--- a/src/core/main.c ++++ b/src/core/main.c +@@ -157,6 +157,7 @@ static nsec_t arg_timer_slack_nsec; + static usec_t arg_default_timer_accuracy_usec; + static Set* arg_syscall_archs; + static FILE* arg_serialization; ++static CGroupMask arg_disable_cgroup_controllers; + static int arg_default_cpu_accounting; + static bool arg_default_io_accounting; + static bool arg_default_ip_accounting; +@@ -684,6 +685,7 @@ static int parse_config_file(void) { + { "Manager", "DefaultLimitNICE", config_parse_rlimit, RLIMIT_NICE, arg_default_rlimit }, + { "Manager", "DefaultLimitRTPRIO", config_parse_rlimit, RLIMIT_RTPRIO, arg_default_rlimit }, + { "Manager", "DefaultLimitRTTIME", config_parse_rlimit, RLIMIT_RTTIME, arg_default_rlimit }, ++ { "Manager", "DisableCGroupControllers", config_parse_cgroup, 0, &arg_disable_cgroup_controllers }, + { "Manager", "DefaultCPUAccounting", config_parse_tristate, 0, &arg_default_cpu_accounting }, + { "Manager", "DefaultIOAccounting", config_parse_bool, 0, &arg_default_io_accounting }, + { "Manager", "DefaultIPAccounting", config_parse_bool, 0, &arg_default_ip_accounting }, +@@ -765,6 +767,10 @@ static void set_manager_defaults(Manager *m) { + m->default_start_limit_burst = arg_default_start_limit_burst; + m->default_dfx_reboot = arg_default_dfx_reboot; + ++ m->cgroup_disabled = arg_disable_cgroup_controllers; ++ m->cgroup_supported = m->system_cgroup_supported; ++ (void) cg_mask_disable_cgroup(m->cgroup_disabled, &m->cgroup_supported); ++ + /* On 4.15+ with unified hierarchy, CPU accounting is essentially free as it doesn't require the CPU + * controller to be enabled, so the default is to enable it unless we got told otherwise. */ + if (arg_default_cpu_accounting >= 0) +@@ -2494,6 +2500,7 @@ static void reset_arguments(void) { + + /* arg_serialization — ignore */ + ++ arg_disable_cgroup_controllers = 0; + arg_default_cpu_accounting = -1; + arg_default_io_accounting = false; + arg_default_ip_accounting = false; +diff --git a/src/core/manager.h b/src/core/manager.h +index ea95efe..9bf5454 100644 +--- a/src/core/manager.h ++++ b/src/core/manager.h +@@ -296,6 +296,8 @@ struct Manager { + /* Data specific to the cgroup subsystem */ + Hashmap *cgroup_unit; + CGroupMask cgroup_supported; ++ CGroupMask system_cgroup_supported; ++ CGroupMask cgroup_disabled; + char *cgroup_root; + + /* Notifications from cgroups, when the unified hierarchy is used is done via inotify. */ +diff --git a/src/core/system.conf.in b/src/core/system.conf.in +index 11936cd..e7aecfd 100644 +--- a/src/core/system.conf.in ++++ b/src/core/system.conf.in +@@ -52,6 +52,7 @@ + #DefaultStartLimitIntervalSec=10s + #DefaultStartLimitBurst=5 + #DefaultEnvironment= ++#DisableCGroupControllers=no + #DefaultCPUAccounting=no + #DefaultIOAccounting=no + #DefaultIPAccounting=no +diff --git a/src/shared/conf-parser.c b/src/shared/conf-parser.c +index 29051ca..2527d31 100644 +--- a/src/shared/conf-parser.c ++++ b/src/shared/conf-parser.c +@@ -10,6 +10,7 @@ + #include "alloc-util.h" + #include "conf-files.h" + #include "conf-parser.h" ++#include "cgroup-util.h" + #include "constants.h" + #include "dns-domain.h" + #include "escape.h" +@@ -1557,6 +1558,59 @@ int config_parse_rlimit( + return 0; + } + ++int config_parse_cgroup( ++ const char *unit, ++ const char *filename, ++ unsigned line, ++ const char *section, ++ unsigned section_line, ++ const char *lvalue, ++ int ltype, ++ const char *rvalue, ++ void *data, ++ void *userdata) { ++ assert(filename); ++ assert(lvalue); ++ assert(rvalue); ++ assert(data); ++ ++ CGroupMask *disabled_mask = data; ++ int r; ++ ++ for (;;) { ++ _cleanup_free_ char *word = NULL; ++ CGroupController cc; ++ int yes_or_no = 0; ++ ++ r = extract_first_word(&rvalue, &word, NULL, EXTRACT_UNQUOTE|EXTRACT_RETAIN_ESCAPE); ++ if (r == 0) ++ break; ++ if (r == -ENOMEM) ++ return log_oom(); ++ if (r < 0) { ++ log_syntax(unit, LOG_ERR, filename, line, r, "Invalid syntax, ignoring: %s", rvalue); ++ break; ++ } ++ ++ yes_or_no = parse_boolean(word); ++ if (yes_or_no == 0) { ++ *disabled_mask = 0; ++ break; ++ } else if (yes_or_no == 1) { ++ *disabled_mask = CGROUP_MASK_V1; ++ break; ++ } ++ ++ cc = cgroup_controller_from_string(word); ++ if (cc < 0) { ++ log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse DisableCGroupControllers, ignoring: %s", word); ++ break; ++ } ++ *disabled_mask |= CGROUP_CONTROLLER_TO_MASK(cc); ++ } ++ return 0; ++} ++ + int config_parse_permille( + const char* unit, + const char *filename, +diff --git a/src/shared/conf-parser.h b/src/shared/conf-parser.h +index e1765f5..2d8f21e 100644 +--- a/src/shared/conf-parser.h ++++ b/src/shared/conf-parser.h +@@ -200,6 +200,7 @@ CONFIG_PARSER_PROTOTYPE(config_parse_ifnames); + CONFIG_PARSER_PROTOTYPE(config_parse_ip_port); + CONFIG_PARSER_PROTOTYPE(config_parse_mtu); + CONFIG_PARSER_PROTOTYPE(config_parse_rlimit); ++CONFIG_PARSER_PROTOTYPE(config_parse_cgroup); + CONFIG_PARSER_PROTOTYPE(config_parse_vlanprotocol); + CONFIG_PARSER_PROTOTYPE(config_parse_hw_addr); + CONFIG_PARSER_PROTOTYPE(config_parse_hw_addrs); +-- +2.33.0 +
View file
_service:tar_scm:systemd-change-time-log-level.patch
Added
@@ -0,0 +1,35 @@ +From 7ca51ff9a4213025070f29c7814bba82984b90e7 Mon Sep 17 00:00:00 2001 +From: yefei25 <yefei25@huawei.com> +Date: Tue, 19 Nov 2019 21:49:52 +0800 +Subject: PATCH systemd: change time log level + + +Signed-off-by: yefei25 <yefei25@huawei.com> +--- + src/core/manager.c | 10 +++++----- + 1 file changed, 5 insertions(+), 5 deletions(-) + +diff --git a/src/core/manager.c b/src/core/manager.c +index 7b39479..1619f8c 100644 +--- a/src/core/manager.c ++++ b/src/core/manager.c +@@ -2937,11 +2937,11 @@ static int manager_dispatch_signal_fd(sd_event_source *source, int fd, uint32_t + static int manager_dispatch_time_change_fd(sd_event_source *source, int fd, uint32_t revents, void *userdata) { + Manager *m = ASSERT_PTR(userdata); + Unit *u; +- +- log_struct(LOG_DEBUG, +- "MESSAGE_ID=" SD_MESSAGE_TIME_CHANGE_STR, +- LOG_MESSAGE("Time has been changed")); +- ++ if (getpid_cached() == 1) { ++ log_struct(LOG_INFO, ++ "MESSAGE_ID=" SD_MESSAGE_TIME_CHANGE_STR, ++ LOG_MESSAGE("Time has been changed")); ++ } + /* Restart the watch */ + (void) manager_setup_time_change(m); + +-- +2.33.0 +
View file
_service:tar_scm:systemd-core-Add-new-rules-for-lower-priority-events.patch
Added
@@ -0,0 +1,227 @@ +From 135dce487e4637e8afc4090334ccb2cb9feccdf1 Mon Sep 17 00:00:00 2001 +From: yangbin <robin.yb@huawei.com> +Date: Fri, 3 Apr 2020 11:56:41 +0800 +Subject: PATCH systemd-core: Add new rules for lower priority events to + preempt over higher priority events + +1. When a high priority event happenes very frequent, and this event takes long time for execution,systemd will get into busy for handling this event only, and lower priority events will have no any change to dispatch and run. + +2. One example is the event for /proc/self/mountinfo, which have a very high priority with -10. +When there are many mountpoints in mountinfo(for example, there may be many netns mountpoints),this event will take long time to finish. +Then if now there are mountpoints in repeating mounting and unmounting(for example, /run/user/uid mountpoint will be mounted then unmounted when for one su command), +this event will take all time of systemd, and lower priority lower events will not be dispatched anyway. +This will case a very severity problem that zombie process will not be reaped, for the evnet for reaping zombies has a lower priority of -6. + +3. This patch fix this problem by add the following rules to allow lower priority events to preempt over higher priority events. +a) If a higher priority event has already been execute for a certain count in consecutive, it can be preempted by lower priority events. The default value for this count is 10, and can be configured through 'sd_event_source_set_preempt_dispatch_count'. +b) If a lower priority gets into pending for 10 times in consecutive, it can preempt over higher priority events. +c) If a lower priority is in pending, and is not dispatched over 50 iteration, it can preempt over higher priority events. +d) The above rules only works for events with priority equal or higher than 'SD_EVENT_PRIORITY_NORMAL' or evnets with type of SOURCE_DEFER, since SOURCE_DEFER events is used for job running queues. +--- + src/core/mount.c | 4 ++ + src/libsystemd/sd-event/event-source.h | 5 ++ + src/libsystemd/sd-event/sd-event.c | 81 ++++++++++++++++++++++++++ + src/systemd/sd-event.h | 1 + + 4 files changed, 91 insertions(+) + +diff --git a/src/core/mount.c b/src/core/mount.c +index f47c511..af0eae6 100644 +--- a/src/core/mount.c ++++ b/src/core/mount.c +@@ -1984,6 +1984,10 @@ static void mount_enumerate(Manager *m) { + goto fail; + } + ++ r = sd_event_source_set_preempt_dispatch_count(m->mount_event_source, 5); ++ if (r < 0) ++ goto fail; ++ + (void) sd_event_source_set_description(m->mount_event_source, "mount-monitor-dispatch"); + } + +diff --git a/src/libsystemd/sd-event/event-source.h b/src/libsystemd/sd-event/event-source.h +index 6092652..0b2ab7d 100644 +--- a/src/libsystemd/sd-event/event-source.h ++++ b/src/libsystemd/sd-event/event-source.h +@@ -70,6 +70,11 @@ struct sd_event_source { + uint64_t pending_iteration; + uint64_t prepare_iteration; + ++ uint64_t preempted_iteration; /*The iteration that dispatched_count is greater than preempt_dispatch_count*/ ++ unsigned pending_count; /*times of pending not dispatched*/ ++ unsigned dispatched_count; /*consecutive dispatched count*/ ++ unsigned preempt_dispatch_count; /*Will be preempted by lower priority if dispatched count reaches to this*/ ++ + sd_event_destroy_t destroy_callback; + sd_event_handler_t ratelimit_expire_callback; + +diff --git a/src/libsystemd/sd-event/sd-event.c b/src/libsystemd/sd-event/sd-event.c +index d3c2d3a..31d4feb 100644 +--- a/src/libsystemd/sd-event/sd-event.c ++++ b/src/libsystemd/sd-event/sd-event.c +@@ -29,6 +29,11 @@ + #include "strxcpyx.h" + #include "time-util.h" + ++#define DEFAULT_PREEMPTED_ITERATION_COUNT (3) ++#define DEFAULT_PREEMPT_DISPATCH_COUNT (10) ++#define DEFAULT_PREEMPT_PENDING_COUNT (10) ++#define DEFAULT_PREEMPT_ITERATION_COUNT (30) ++ + #define DEFAULT_ACCURACY_USEC (250 * USEC_PER_MSEC) + + static bool EVENT_SOURCE_WATCH_PIDFD(sd_event_source *s) { +@@ -154,6 +159,11 @@ struct sd_event { + + LIST_HEAD(sd_event_source, sources); + ++ /*last dispatched source, its type is sd_event_source, ++ * here use void to avoid accessing its members, ++ * for it may have been freed already.*/ ++ void *last_source; ++ + sd_event_source *sigint_event_source, *sigterm_event_source; + + usec_t last_run_usec, last_log_usec; +@@ -169,6 +179,39 @@ static sd_event *event_resolve(sd_event *e) { + return e == SD_EVENT_DEFAULT ? default_event : e; + } + ++static int preempt_prioq_compare(const sd_event_source *x, const sd_event_source *y) { ++ if((x->priority > SD_EVENT_PRIORITY_NORMAL && x->type != SOURCE_DEFER) ++ || (y->priority > SD_EVENT_PRIORITY_NORMAL && y->type != SOURCE_DEFER)) { ++ return 0; /*only high priority evnets can preempt*/ ++ } ++ ++ if(x->priority <= y->priority) { ++ if(x->dispatched_count >= x->preempt_dispatch_count) ++ return 1; ++ if(y->type != SOURCE_DEFER) { /*pending state for defer event is always true*/ ++ /*y has lower priority, but its pending count is greater than x, so y wins*/ ++ if(y->pending_count >= (x->pending_count + DEFAULT_PREEMPT_PENDING_COUNT)) ++ return 1; ++ /*y has lower priority, but is in pending longer than x, so y wins*/ ++ if(x->pending_iteration >= (y->pending_iteration + DEFAULT_PREEMPT_ITERATION_COUNT)) ++ return 1; ++ } ++ } else { ++ if(y->dispatched_count >= y->preempt_dispatch_count) ++ return -1; ++ if(x->type != SOURCE_DEFER) { /*pending state for defer event is always true*/ ++ /*x has lower priority, but its pending count is greater than y, so x wins*/ ++ if(x->pending_count >= (y->pending_count + DEFAULT_PREEMPT_PENDING_COUNT)) ++ return -1; ++ /*x has lower priority, but is in pending longer than y, so x wins*/ ++ if(y->pending_iteration >= (x->pending_iteration + DEFAULT_PREEMPT_ITERATION_COUNT)) ++ return -1; ++ } ++ } ++ ++ return 0; ++} ++ + static int pending_prioq_compare(const void *a, const void *b) { + const sd_event_source *x = a, *y = b; + int r; +@@ -186,6 +229,10 @@ static int pending_prioq_compare(const void *a, const void *b) { + if (r != 0) + return r; + ++ r = preempt_prioq_compare(a, b); ++ if(r != 0) ++ return r; ++ + /* Lower priority values first */ + r = CMP(x->priority, y->priority); + if (r != 0) +@@ -1031,6 +1078,17 @@ static int source_set_pending(sd_event_source *s, bool b) { + assert(s); + assert(s->type != SOURCE_EXIT); + ++ if (b && s->pending == b) ++ s->pending_count++; ++ else ++ s->pending_count = (b ? 1 : 0); ++ if (b && s->preempted_iteration && ++ (s->pending_count >= DEFAULT_PREEMPTED_ITERATION_COUNT || ++ s->event->iteration >= (s->preempted_iteration + DEFAULT_PREEMPTED_ITERATION_COUNT)) ) { ++ s->dispatched_count = 0; ++ s->preempted_iteration = 0; ++ } ++ + if (s->pending == b) + return 0; + +@@ -1090,6 +1148,7 @@ static sd_event_source *source_new(sd_event *e, bool floating, EventSourceType t + .type = type, + .pending_index = PRIOQ_IDX_NULL, + .prepare_index = PRIOQ_IDX_NULL, ++ .preempt_dispatch_count = DEFAULT_PREEMPT_DISPATCH_COUNT, + }; + + if (!floating) +@@ -2511,6 +2570,7 @@ static int event_source_offline( + s->enabled = enabled; + s->ratelimited = ratelimited; + ++ s->pending_count = 0; + switch (s->type) { + + case SOURCE_IO: +@@ -3605,6 +3665,19 @@ static int process_inotify(sd_event *e) { + return done; + } + ++static void source_dispatch_pre(sd_event_source *s) { ++ if(s->event->last_source == s) { ++ s->dispatched_count++; ++ if(s->dispatched_count >= s->preempt_dispatch_count) ++ s->preempted_iteration = s->event->iteration; ++ } else { ++ s->preempted_iteration = 0; ++ s->dispatched_count = 0; ++ } ++ s->event->last_source = s; ++ s->pending_count = 0; ++} ++ + static int source_dispatch(sd_event_source *s) { + EventSourceType saved_type; + sd_event *saved_event; +@@ -3659,6 +3732,7 @@ static int source_dispatch(sd_event_source *s) { + return r; + } + ++ source_dispatch_pre(s); + s->dispatching = true; + + switch (s->type) { +@@ -4624,6 +4698,13 @@ _public_ int sd_event_source_is_ratelimited(sd_event_source *s) { + return s->ratelimited; + } + ++_public_ int sd_event_source_set_preempt_dispatch_count(sd_event_source *s, unsigned count) { ++ assert_return(s, -EINVAL); ++ ++ s->preempt_dispatch_count = count; ++ return 0; ++} ++ + _public_ int sd_event_set_signal_exit(sd_event *e, int b) { + bool change = false; + int r; +diff --git a/src/systemd/sd-event.h b/src/systemd/sd-event.h +index cae4c86..6e70a32 100644 +--- a/src/systemd/sd-event.h ++++ b/src/systemd/sd-event.h +@@ -169,6 +169,7 @@ int sd_event_source_set_exit_on_failure(sd_event_source *s, int b); + int sd_event_source_set_ratelimit(sd_event_source *s, uint64_t interval_usec, unsigned burst); + int sd_event_source_get_ratelimit(sd_event_source *s, uint64_t *ret_interval_usec, unsigned *ret_burst); + int sd_event_source_is_ratelimited(sd_event_source *s); ++int sd_event_source_set_preempt_dispatch_count(sd_event_source *s, unsigned count); + int sd_event_source_set_ratelimit_expire_callback(sd_event_source *s, sd_event_handler_t callback); + + /* Define helpers so that __attribute__((cleanup(sd_event_unrefp))) and similar may be used. */ +-- +2.33.0 +
View file
_service:tar_scm:systemd-core-fix-problem-of-dbus-service-can-not-be-started.patch
Added
@@ -0,0 +1,40 @@ +From bf589755bd5b084f1b5dd099ea3e4917ac9911fd Mon Sep 17 00:00:00 2001 +From: huangkaibin <huangkaibin@huawei.com> +Date: Thu, 14 Sep 2017 12:54:01 +0800 +Subject: PATCH systemd-core: fix problem of dbus service can not be started + when dbus is dead and state of system dbus of systemd stay in + BUS_AUTHENTICATING. + +When systemd starts a dbus communication, it will first authenticate the bus by communicating with polkitd service, and then enter running state. +But if authenticating can not be establised within 25s(default timeout seconds) since authenticating starts +(maybe caused by polkitd service or dbus service can not be activated in time), the dbus state in systemd side will stays in BUS_AUTHENTICATING state, +and systemd will enter a mad state that it will handle authenticating(in bus_process_internal function) very frequently and will have no any change to +service for events of restarting services(by systemctl restart dbus.service --no-ask-password --no-block). So that the dbus service will never be restarted successfully. +systemd will enter such a state is caused by the timeout setting in sd_bus_get_timeout function. When in BUS_AUTHENTICATING state, the timeout is set +to a fix value of bus->auth_timeout(authenticating start time + 25s), if auth_timeout is an expired time, but not a furture time, systemd will always service +for the callback of function of dbus(time_callback) with no any delay when it got its chance, and leave no chance for events of restarting services. +This patch fix this problem by fixing the timeout to a furture time when bus->auth_timeout is expired. +--- + src/libsystemd/sd-bus/sd-bus.c | 6 +++++- + 1 file changed, 5 insertions(+), 1 deletion(-) + +diff --git a/src/libsystemd/sd-bus/sd-bus.c b/src/libsystemd/sd-bus/sd-bus.c +index b0a3237..ca626d3 100644 +--- a/src/libsystemd/sd-bus/sd-bus.c ++++ b/src/libsystemd/sd-bus/sd-bus.c +@@ -2267,7 +2267,11 @@ _public_ int sd_bus_get_timeout(sd_bus *bus, uint64_t *timeout_usec) { + switch (bus->state) { + + case BUS_AUTHENTICATING: +- *timeout_usec = bus->auth_timeout; ++ //delay 1 second to ensure it is a furture time but not an expired time ++ if(bus->auth_timeout <= now(CLOCK_MONOTONIC)) ++ *timeout_usec = now(CLOCK_MONOTONIC) + USEC_PER_SEC; ++ else ++ *timeout_usec = bus->auth_timeout; + return 1; + + case BUS_RUNNING: +-- +1.8.3.1 +
View file
_service:tar_scm:systemd-solve-that-rsyslog-reads-journal-s-object-of.patch
Added
@@ -0,0 +1,66 @@ +From 6aa35d7d911b6895043f222293703ef7cf60aca1 Mon Sep 17 00:00:00 2001 +From: yefei25 <yefei25@huawei.com> +Date: Thu, 5 Mar 2020 21:45:36 +0800 +Subject: PATCH systemd: solve that rsyslog reads journal's object of +size 0 + + +Signed-off-by: yefei25 <yefei25@huawei.com> + +--- + src/libsystemd/sd-journal/journal-file.c | 5 +++-- + src/libsystemd/sd-journal/sd-journal.c | 7 ++++++- + 2 files changed, 9 insertions(+), 3 deletions(-) + +diff --git a/src/libsystemd/sd-journal/journal-file.c b/src/libsystemd/sd-journal/journal-file.c +index 2ead295..9962d3b 100644 +--- a/src/libsystemd/sd-journal/journal-file.c ++++ b/src/libsystemd/sd-journal/journal-file.c +@@ -898,8 +898,9 @@ static int check_object(JournalFile *f, Object *o, uint64_t offset) { + le64toh(o->tag.epoch), offset); + + break; ++ default: ++ return -EBADMSG; + } +- + return 0; + } + +@@ -1804,7 +1805,7 @@ int journal_file_data_payload( + } + + size = le64toh(READ_NOW(o->object.size)); +- if (size < journal_file_data_payload_offset(f)) ++ if (size == 0 || o->object.type == 0 || size < journal_file_data_payload_offset(f)) + return -EBADMSG; + + size -= journal_file_data_payload_offset(f); +diff --git a/src/libsystemd/sd-journal/sd-journal.c b/src/libsystemd/sd-journal/sd-journal.c +index 898218e..f6090dd 100644 +--- a/src/libsystemd/sd-journal/sd-journal.c ++++ b/src/libsystemd/sd-journal/sd-journal.c +@@ -114,6 +114,10 @@ static void init_location(Location *l, LocationType type, JournalFile *f, Object + assert(IN_SET(type, LOCATION_DISCRETE, LOCATION_SEEK)); + assert(f); + ++ if(o->object.type != OBJECT_ENTRY || o->object.size == 0){ ++ return; ++ } ++ + *l = (Location) { + .type = type, + .seqnum = le64toh(o->entry.seqnum), +@@ -851,7 +855,8 @@ static int real_journal_next(sd_journal *j, direction_t direction) { + return r; + + set_location(j, new_file, o); +- ++ if(o->object.size == 0) ++ return -EBADMSG; + return 1; + } + +-- +2.33.0 +
View file
_service:tar_scm:treat-hyphen-as-valid-hostname-char.patch
Added
@@ -0,0 +1,51 @@ +From c04904a4f54f8949a6a7821a0859e2732366259b Mon Sep 17 00:00:00 2001 +From: licunlong <licunlong1@huawei.com> +Date: Tue, 24 Nov 2020 19:57:38 +0800 +Subject: PATCH treat hyphen as valid hostname char + +--- + src/basic/hostname-util.c | 14 ++++++++++++-- + 1 file changed, 12 insertions(+), 2 deletions(-) + +diff --git a/src/basic/hostname-util.c b/src/basic/hostname-util.c +index 5bfa028..b80a2b8 100644 +--- a/src/basic/hostname-util.c ++++ b/src/basic/hostname-util.c +@@ -77,6 +77,16 @@ bool valid_ldh_char(char c) { + c == '-'; + } + ++static bool hostname_valid_char(char c) { ++ return ++ (c >= 'a' && c <= 'z') || ++ (c >= 'A' && c <= 'Z') || ++ (c >= '0' && c <= '9') || ++ c == '-' || ++ c == '_' || ++ c == '.'; ++} ++ + bool hostname_is_valid(const char *s, ValidHostnameFlags flags) { + unsigned n_dots = 0; + const char *p; +@@ -117,7 +127,7 @@ bool hostname_is_valid(const char *s, bool allow_trailing_dot) { + hyphen = true; + + } else { +- if (!valid_ldh_char(*p)) ++ if (!hostname_valid_char(*p)) + return false; + + dot = false; +@@ -160,7 +170,7 @@ char* hostname_cleanup(char *s) { + dot = false; + hyphen = true; + +- } else if (valid_ldh_char(*p)) { ++ } else if (hostname_valid_char(*p)) { + *(d++) = *p; + dot = false; + hyphen = false; +-- +2.23.0 +
View file
_service:tar_scm:udev-add-actions-while-rename-netif-failed.patch
Added
@@ -0,0 +1,83 @@ +From e21318d22359c7160ea7c7f4a610b28a30d48c84 Mon Sep 17 00:00:00 2001 +From: systemd team <systemd-maint@redhat.com> +Date: Tue, 7 Mar 2017 08:20:10 +0000 +Subject: PATCH udev-add-actions-while-rename-netif-failed +--- + src/udev/udev-event.c | 47 +++++++++++++++++++++++++++++++++++++------ + 1 file changed, 41 insertions(+), 6 deletions(-) + +diff --git a/src/udev/udev-event.c b/src/udev/udev-event.c +index ec4ad30..d53a0aa 100644 +--- a/src/udev/udev-event.c ++++ b/src/udev/udev-event.c +@@ -908,6 +908,7 @@ static int rename_netif(UdevEvent *event) { + const char *s; + sd_device *dev; + int ifindex, r; ++ char nameIFNAMSIZ; + + assert(event); + +@@ -978,19 +979,53 @@ static int rename_netif(UdevEvent *event) { + goto revert; + } + +- r = rtnl_set_link_name(&event->rtnl, ifindex, event->name); ++ strscpy(name, IFNAMSIZ, event->name); ++ ++ r = rtnl_set_link_name(&event->rtnl, ifindex, name); + if (r < 0) { + if (r == -EBUSY) { + log_device_info(dev, "Network interface '%s' is already up, cannot rename to '%s'.", + old_sysname, event->name); + r = 0; +- } else +- log_device_error_errno(dev, r, "Failed to rename network interface %i from '%s' to '%s': %m", +- ifindex, old_sysname, event->name); +- goto revert; ++ goto revert; ++ } ++ int loop; ++ if (r != -EEXIST) { ++ log_error_errno(r, "error changing net interface name '%s' to '%s': %m", old_sysname, name); ++ goto revert; ++ } ++ ++ snprintf(name, IFNAMSIZ, "rename%d", ifindex); ++ r = rtnl_set_link_name(&event->rtnl, ifindex, name); ++ if (r < 0) { ++ log_error_errno(r, "error changing net interface name '%s' to '%s': %m", old_sysname, name); ++ goto revert; ++ } ++ ++ log_device_info(dev, "Network interface %i is renamed from '%s' to '%s'", ifindex, old_sysname, name); ++ ++ /* wait 90 seconds for our target to become available */ ++ loop = 90 * 20; ++ while (loop--) { ++ const struct timespec duration = { 0, 1000 * 1000 * 1000 / 20 }; ++ ++ r = rtnl_set_link_name(&event->rtnl, ifindex, event->name); ++ if (r == 0) { ++ log_device_info(dev, "Network interface %i is renamed from '%s' to '%s'", ifindex, name, event->name); ++ goto revert; ++ } ++ ++ if (r != -EEXIST) { ++ log_error_errno(r, "error changing net interface name '%s' to '%s': %m", name, event->name); ++ goto revert; ++ } ++ log_debug( "wait for netif '%s' to become free, loop=%i\n", ++ event->name, (90 * 20) - loop); ++ nanosleep(&duration, NULL); ++ } + } + +- log_device_debug(dev, "Network interface %i is renamed from '%s' to '%s'", ifindex, old_sysname, event->name); ++ log_device_info(dev, "Network interface %i is renamed from '%s' to '%s'", ifindex, old_sysname, event->name); + return 1; + + revert: +-- +2.33.0 +
View file
_service:tar_scm:udev-virsh-shutdown-vm.patch
Added
@@ -0,0 +1,23 @@ +From 3d5e0620b4a3298620c8d985cec42772c7f77c6d Mon Sep 17 00:00:00 2001 +From: openEuler Buildteam <buildteam@openeuler.org> +Date: Thu, 31 Jan 2019 02:24:16 -0500 +Subject: PATCH systemd:virsh shutdown vm + +--- + rules.d/70-power-switch.rules | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/rules.d/70-power-switch.rules b/rules.d/70-power-switch.rules +index 3fb954a..bc79410 100644 +--- a/rules.d/70-power-switch.rules ++++ b/rules.d/70-power-switch.rules +@@ -11,5 +11,6 @@ ACTION=="remove", GOTO="power_switch_end" + + SUBSYSTEM=="input", KERNEL=="event*", ENV{ID_INPUT_SWITCH}=="1", TAG+="power-switch" + SUBSYSTEM=="input", KERNEL=="event*", ENV{ID_INPUT_KEY}=="1", TAG+="power-switch" ++SUBSYSTEM=="input", KERNEL=="event*", SUBSYSTEMS=="platform", ATTRS{keys}=="116", TAG+="power-switch" + + LABEL="power_switch_end" +-- +2.33.0 +
View file
_service:tar_scm:unit-don-t-add-Requires-for-tmp.mount.patch
Added
@@ -0,0 +1,27 @@ +From 03e52d33bbdea731eaa79545bb1d30c5b21abe3d Mon Sep 17 00:00:00 2001 +From: Lukas Nykryn <lnykryn@redhat.com> +Date: Mon, 5 Sep 2016 12:47:09 +0200 +Subject: PATCH unit: don't add Requires for tmp.mount + +Resolves: #1619292 + +--- + src/core/unit.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/core/unit.c b/src/core/unit.c +index c9f756c..721d8d6 100644 +--- a/src/core/unit.c ++++ b/src/core/unit.c +@@ -1421,7 +1421,7 @@ static int unit_add_mount_dependencies(Unit *u) { + return r; + changed = changed || r > 0; + +- if (m->fragment_path) { ++ if (m->fragment_path && !streq(m->id, "tmp.mount")) { + r = unit_add_dependency(u, UNIT_REQUIRES, m, true, di.origin_mask); + if (r < 0) + return r; +-- +1.8.3.1 +
View file
_service:tar_scm:units-add-Install-section-to-tmp.mount.patch
Added
@@ -0,0 +1,25 @@ +From bb3d205bea1c83cbd0e27b504f5f1faa884fb602 Mon Sep 17 00:00:00 2001 +From: Jan Synacek <jsynacek@redhat.com> +Date: Tue, 22 Jan 2019 10:28:42 +0100 +Subject: PATCH units: add Install section to tmp.mount + +Resolves: #1667065 +--- + units/tmp.mount | 4 ++++ + 1 file changed, 4 insertions(+) + +diff --git a/units/tmp.mount b/units/tmp.mount +index cf68378..66d9a32 100644 +--- a/units/tmp.mount ++++ b/units/tmp.mount +@@ -23,3 +23,7 @@ What=tmpfs + Where=/tmp + Type=tmpfs + Options=mode=1777,strictatime,nosuid,nodev,size=50%%,nr_inodes=1m ++ ++# Make 'systemctl enable tmp.mount' work: ++Install ++WantedBy=local-fs.target +-- +2.23.0 +
View file
_service:tar_scm:update-rtc-with-system-clock-when-shutdown.patch
Added
@@ -0,0 +1,51 @@ +From a13f14c6a2da55b9f797b6f33449ba523c07dd46 Mon Sep 17 00:00:00 2001 +From: update-rtc-with-system-clock-when-shutdown +Date: Sat, 2 Feb 2019 02:54:52 -0500 +Subject: PATCH Module: modification summary +--- + units/hwclock-save.service.in | 19 +++++++++++++++++++ + units/meson.build | 2 ++ + 2 files changed, 21 insertions(+) + create mode 100644 units/hwclock-save.service.in + +diff --git a/units/hwclock-save.service.in b/units/hwclock-save.service.in +new file mode 100644 +index 0000000..db33418 +--- /dev/null ++++ b/units/hwclock-save.service.in +@@ -0,0 +1,19 @@ ++# This file is part of systemd. ++# ++# systemd is free software; you can redistribute it and/or modify it+ ++# under the terms of the GNU General Public License as published by ++# the Free Software Foundation; either version 2 of the License, or ++# (at your option) any later version. ++ ++Unit ++Description=Update RTC With System Clock ++ ++Service ++Type=oneshot ++ExecStart=/usr/bin/true ++ExecStop=/sbin/hwclock --systohc ++RemainAfterExit=yes ++ ++Install ++WantedBy=default.target ++ +diff --git a/units/meson.build b/units/meson.build +index aa2ed11..9992389 100644 +--- a/units/meson.build ++++ b/units/meson.build +@@ -220,6 +220,8 @@ in_units = + 'sysinit.target.wants/', + 'systemd-update-done.service', '', + 'sysinit.target.wants/', ++ 'hwclock-save.service', '', ++ 'sysinit.target.wants/', + 'systemd-update-utmp-runlevel.service', 'ENABLE_UTMP HAVE_SYSV_COMPAT', + 'multi-user.target.wants/ graphical.target.wants/ rescue.target.wants/', + 'systemd-update-utmp.service', 'ENABLE_UTMP', +-- +2.23.0 +
Locations
Projects
Search
Status Monitor
Help
Open Build Service
OBS Manuals
API Documentation
OBS Portal
Reporting a Bug
Contact
Mailing List
Forums
Chat (IRC)
Twitter
Open Build Service (OBS)
is an
openSUSE project
.
浙ICP备2022010568号-2