From 0e1f7d8d722ca46d784fd9df289deaa9efeaa463 Mon Sep 17 00:00:00 2001 From: Jamie Cameron Date: Tue, 4 Jan 2022 22:41:34 -0800 Subject: [PATCH] Cache list of systemd services https://forum.virtualmin.com/t/new-way-to-copy-system-information-data/113433/12 --- init/init-lib.pl | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/init/init-lib.pl b/init/init-lib.pl index 596176198..b872aa1cb 100755 --- a/init/init-lib.pl +++ b/init/init-lib.pl @@ -2109,6 +2109,9 @@ systemd automatically includes init scripts). sub list_systemd_services { my ($noinit) = @_; +if (@list_systemd_services_cache && !$noinit) { + return @list_systemd_services_cache; + } # Get all systemd unit names my $out = &backquote_command("systemctl list-units --full --all -t service --no-legend"); @@ -2225,7 +2228,10 @@ if (!$noinit) { } } -return sort { $a->{'name'} cmp $b->{'name'} } @rv; +# Return actions sorted by name +@rv = sort { $a->{'name'} cmp $b->{'name'} } @rv; +@list_systemd_services_cache = @rv if (!$noinit); +return @rv; } =head2 start_systemd_service(name)