From 2602f8dbe1753edbf6d65c2eb7f88ad1c7e58a97 Mon Sep 17 00:00:00 2001 From: Jamie Cameron Date: Tue, 4 Jan 2022 22:35:18 -0800 Subject: [PATCH] Don't read init scripts if not looking for one https://forum.virtualmin.com/t/new-way-to-copy-system-information-data/113433/12 --- init/init-lib.pl | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/init/init-lib.pl b/init/init-lib.pl index 8ed058bc2..596176198 100755 --- a/init/init-lib.pl +++ b/init/init-lib.pl @@ -2098,7 +2098,7 @@ my $ifile = "/etc/init.d/$name"; &unlink_logged($cfile, $ifile); } -=head2 list_systemd_services +=head2 list_systemd_services(skip-init) Returns a list of all known systemd services, each of which is a hash ref with 'name', 'desc', 'boot', 'status' and 'pid' keys. Also includes init.d @@ -2108,6 +2108,8 @@ systemd automatically includes init scripts). =cut sub list_systemd_services { +my ($noinit) = @_; + # Get all systemd unit names my $out = &backquote_command("systemctl list-units --full --all -t service --no-legend"); my $ex = $?; @@ -2201,24 +2203,26 @@ foreach my $name (keys %info) { } # Also add legacy init scripts -my @rls = &get_inittab_runlevel(); -foreach my $a (&list_actions()) { - $a =~ s/\s+\d+$//; - my $f = &action_filename($a); - my $s = { 'name' => $a, - 'legacy' => 1 }; - $s->{'boot'} = 0; - foreach my $rl (@rls) { - my $l = glob("/etc/rc$rl.d/S*$a"); - $s->{'boot'} = 1 if ($l); +if (!$noinit) { + my @rls = &get_inittab_runlevel(); + foreach my $a (&list_actions()) { + $a =~ s/\s+\d+$//; + my $f = &action_filename($a); + my $s = { 'name' => $a, + 'legacy' => 1 }; + $s->{'boot'} = 0; + foreach my $rl (@rls) { + my $l = glob("/etc/rc$rl.d/S*$a"); + $s->{'boot'} = 1 if ($l); + } + $s->{'desc'} = &init_description($f); + my $hasarg = &get_action_args($f); + if ($hasarg->{'status'}) { + my $r = &action_running($f); + $s->{'status'} = $r; + } + push(@rv, $s); } - $s->{'desc'} = &init_description($f); - my $hasarg = &get_action_args($f); - if ($hasarg->{'status'}) { - my $r = &action_running($f); - $s->{'status'} = $r; - } - push(@rv, $s); } return sort { $a->{'name'} cmp $b->{'name'} } @rv; @@ -2366,7 +2370,7 @@ Returns 1 if some service is managed by systemd sub is_systemd_service { my ($name) = @_; -foreach my $s (&list_systemd_services()) { +foreach my $s (&list_systemd_services(1)) { if ($s->{'name'} eq $name && !$s->{'legacy'}) { return 1; }