From 29e2fa03969ce6c30217693df27e2d5c7b38267e Mon Sep 17 00:00:00 2001 From: Martin Whitaker Date: Tue, 15 Sep 2020 11:03:52 +0100 Subject: Include systemd sockets and timers in lists returned by services::services(). --- perl-install/services.pm | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) (limited to 'perl-install/services.pm') diff --git a/perl-install/services.pm b/perl-install/services.pm index 95e068770..69de0cb00 100644 --- a/perl-install/services.pm +++ b/perl-install/services.pm @@ -24,6 +24,13 @@ sub _base_name { $service =~ s/\.(service|socket|timer)$//; } +#- The name used in the lists returned by services(). For backwards compatibility, +#- use just the base name for .service units. +sub _list_name { + my ($name, $type) = @_; + $type eq 'service' ? $name : "$name.$type"; +} + sub description { my %services = ( acpid => N_("Listen and dispatch ACPI events from the kernel"), @@ -379,29 +386,31 @@ sub _systemd_services() { # even if systemd is not running, we can detect status of shorewell service which is not wanted by: my @opts = $::isInstall ? 'list-unit-files' : qw(--all --plain list-units); foreach (run_program::rooted_get_stdout($::prefix, '/bin/systemctl', '--no-legend', '--no-pager', '--full', @opts)) { - my ($name) = m!^(\S+)\.service\s+loaded!; - ($name) = m!^(\S+)\.service\s+enabled! if $::isInstall && !$name; + my ($name, $type) = m!^(\S+)\.(service|socket|timer)\s+loaded!; + ($name, $type) = m!^(\S+)\.(service|socket|timer)\s+enabled! if $::isInstall && !$name; + my $unit_name = "$name.$type"; if ($name) { # We only look at non-template, non-linked service files in /lib # We also check for any non-masked sysvinit files as these are # also handled by systemd - if ($name !~ /.*\@$/g && (-e "$::prefix/lib/systemd/system/$name.service" or -e "$::prefix/etc/rc.d/init.d/$name") && ! -l "$::prefix/lib/systemd/system/$name.service") { - push @services, [ $name, !!run_program::rooted($::prefix, '/bin/systemctl', '--quiet', 'is-enabled', "$name.service") ]; - $loaded{$name} = 1; + if ($name !~ /.*\@$/g && (-e "$::prefix/lib/systemd/system/$unit_name" or -e "$::prefix/etc/rc.d/init.d/$name") && ! -l "$::prefix/lib/systemd/system/$unit_name") { + push @services, [ _list_name($name, $type), !!run_program::rooted($::prefix, '/bin/systemctl', '--quiet', 'is-enabled', "$unit_name") ]; + $loaded{$unit_name} = 1; } } } # list-units will not list disabled units that can be enabled foreach (run_program::rooted_get_stdout($::prefix, '/bin/systemctl', '--no-legend', '--no-pager', '--full', 'list-unit-files')) { - if (my ($name) = m!^(\S+)\.service\s+disabled!) { + if (my ($name, $type) = m!^(\S+)\.(service|socket|timer)\s+disabled!) { + my $unit_name = "$name.$type"; # We only look at non-template, non-linked service files in /lib # We also check for any non-masked sysvinit files as these are # also handled by systemd - if (!exists $loaded{$name} && $name !~ /.*\@$/g && (-e "$::prefix/lib/systemd/system/$name.service" or -e "$::prefix/etc/rc.d/init.d/$name") && ! -l "$::prefix/lib/systemd/system/$name.service") { + if (!exists $loaded{$unit_name} && $name !~ /.*\@$/g && (-e "$::prefix/lib/systemd/system/$unit_name" or -e "$::prefix/etc/rc.d/init.d/$name") && ! -l "$::prefix/lib/systemd/system/$unit_name") { # Limit ourselves to "standard" targets which can be enabled - my $wantedby = cat_("$::prefix/lib/systemd/system/$name.service") =~ /^WantedBy=(graphical|multi-user).target$/sm ? $1 : ''; + my $wantedby = cat_("$::prefix/lib/systemd/system/$unit_name") =~ /^WantedBy=(graphical|multi-user).target$/sm ? $1 : ''; if ($wantedby) { - push @services, [ $name, 0 ]; + push @services, [ _list_name($name, $type), 0 ]; } } } @@ -421,11 +430,12 @@ sub _legacy_services() { # combine that with information from chkconfig regarding legacy sysvinit # scripts (which systemd will parse and include when running) log::explanations("Detected systemd installed. Using fake service+chkconfig introspection."); - foreach (glob_("$::prefix/lib/systemd/system/*.service")) { - my ($name) = m!([^/]*).service$!; + foreach (glob("$::prefix/lib/systemd/system/*.{service,socket,timer}")) { + my ($name, $type) = m!([^/]*)\.(service|socket|timer)$!; + my $unit_name = "$name.$type"; # We only look at non-template, non-symlinked service files - if (!(/.*\@\.service$/g) && ! -l $_) { + if ($name !~ /.*\@$/g && ! -l $_) { # Limit ourselves to "standard" targets my $wantedby = cat_($_) =~ /^WantedBy=(graphical|multi-user).target$/sm ? $1 : ''; if ($wantedby) { @@ -435,8 +445,8 @@ sub _legacy_services() { # setup where -e will fail if the symlink target does # exist which is typically the case when viewed outside # of the chroot. - if (!-l "$::prefix/lib/systemd/system/$wantedby.target.wants/$name.service") { - push @services, [ $name, !!-l "$::prefix/etc/systemd/system/$wantedby.target.wants/$name.service" ]; + if (!-l "$::prefix/lib/systemd/system/$wantedby.target.wants/$unit_name") { + push @services, [ _list_name($name, $type), !!-l "$::prefix/etc/systemd/system/$wantedby.target.wants/$unit_name" ]; } } } -- cgit v1.2.1