diff options
author | Michael Stapelberg <stapelberg@debian.org> | 2013-06-18 20:16:51 +0200 |
---|---|---|
committer | Michael Stapelberg <michael@stapelberg.de> | 2013-06-18 20:16:51 +0200 |
commit | 4e227ef57a1870522a653665a8b201770e49f13c (patch) | |
tree | b803ec392f8c77d41ad53149be177eba27dd1600 | |
parent | 5556964d43dfab4164d8ab032fa1797062ef496f (diff) | |
download | init-system-helpers-4e227ef57a1870522a653665a8b201770e49f13c.tar.gz |
dh_systemd_{enable,disable}: don’t pass Also= and Alias= units on the cmdline
See previous commit.
-rwxr-xr-x | script/dh_systemd_disable | 62 | ||||
-rwxr-xr-x | script/dh_systemd_enable | 54 |
2 files changed, 4 insertions, 112 deletions
diff --git a/script/dh_systemd_disable b/script/dh_systemd_disable index 70bb1a1..904ff4f 100755 --- a/script/dh_systemd_disable +++ b/script/dh_systemd_disable @@ -74,43 +74,13 @@ when you are calling B<dh_systemd_after> manually. =cut init(options => { - "no-also" => \$dh{NO_ALSO}, "disable-in-prerm" => \$dh{DISABLE_IN_PRERM}, }); -# Extracts the Also= or Alias= line(s) from a unit file. -# In case this produces horribly wrong results, you can pass --no-also, but -# that should really not be necessary. Please report bugs to -# pkg-systemd-maintainers. -sub extract_key { - my ($unit_path, $key) = @_; - my @values; - my $fh; - - if ($dh{NO_ALSO}) { - return @values; - } - - if (!open($fh, '<', $unit_path)) { - warning("Cannot open($unit_path) for extracting the Also= line(s)"); - return; - } - while (my $line = <$fh>) { - chomp($line); - - if ($line =~ /^\s*$key=(.+)$/i) { - @values = (@values, shellwords($1)); - } - } - close($fh); - return @values; -} - foreach my $package (@{$dh{DOPACKAGES}}) { my $tmpdir = tmpdir($package); my @installed_units; my @units; - my %aliases; # XXX: This is duplicated in dh_installinit, which is unfortunate. # We do need the service files before running dh_installinit though, @@ -175,17 +145,8 @@ foreach my $package (@{$dh{DOPACKAGES}}) { # all unit files that are installed in this package. my @args = @ARGV > 0 ? @ARGV : @installed_units; - # This hash prevents us from looping forever in the following while loop. - # An actual real-world example of such a loop is systemd’s - # systemd-readahead-drop.service, which contains - # Also=systemd-readahead-collect.service, and that file in turn - # contains Also=systemd-readahead-drop.service, thus forming an endless - # loop. - my %seen; - # We use while/shift because we push to the list in the body. - while (@args) { - my $name = shift @args; + for my $name (@args) { my $base = basename($name); # Try to make the path absolute, so that the user can call @@ -211,31 +172,12 @@ foreach my $package (@{$dh{DOPACKAGES}}) { next; } - # Handle all unit files specified via Also= explicitly. - # This is not necessary for enabling, but for disabling, as we - # cannot read the unit file when disabling (it was already - # deleted). - my @also = grep { !exists($seen{$_}) } extract_key($name, 'Also'); - $seen{$_} = 1 for @also; - @args = (@args, @also); - - $aliases{$name} = [ extract_key($name, 'Alias') ]; push @units, $name; } next if @units == 0; - # These autoscripts contain a call to deb-systemd-helper disable, - # which needs to have all Aliases passed explicitly - # in order to properly cleanup the state file (the - # information is stored only in the symlinks which the - # admin might have removed). - my @both = @units; - for my $unit (@units) { - @both = (@both, @{$aliases{$unit}}); - } - - my $unitargs = join(" ", map { basename($_) } @both); + my $unitargs = join(" ", map { basename($_) } @units); if ($dh{DISABLE_IN_PRERM}) { autoscript($package, "prerm", "postrm-systemd", "s/#UNITFILES#/$unitargs/"); } diff --git a/script/dh_systemd_enable b/script/dh_systemd_enable index 5e91880..5865dc6 100755 --- a/script/dh_systemd_enable +++ b/script/dh_systemd_enable @@ -45,43 +45,12 @@ when you are calling B<dh_systemd_enable> manually. =cut -init(options => { - "no-also" => \$dh{NO_ALSO}, -}); - -# Extracts the Also= or Alias= line(s) from a unit file. -# In case this produces horribly wrong results, you can pass --no-also, but -# that should really not be necessary. Please report bugs to -# pkg-systemd-maintainers. -sub extract_key { - my ($unit_path, $key) = @_; - my @values; - my $fh; - - if ($dh{NO_ALSO}) { - return @values; - } - - if (!open($fh, '<', $unit_path)) { - warning("Cannot open($unit_path) for extracting the Also= line(s)"); - return; - } - while (my $line = <$fh>) { - chomp($line); - - if ($line =~ /^\s*$key=(.+)$/i) { - @values = (@values, shellwords($1)); - } - } - close($fh); - return @values; -} +init(); foreach my $package (@{$dh{DOPACKAGES}}) { my $tmpdir = tmpdir($package); my @installed_units; my @units; - my %aliases; # XXX: This is duplicated in dh_installinit, which is unfortunate. # We do need the service files before running dh_installinit though, @@ -146,17 +115,7 @@ foreach my $package (@{$dh{DOPACKAGES}}) { # all unit files that are installed in this package. my @args = @ARGV > 0 ? @ARGV : @installed_units; - # This hash prevents us from looping forever in the following while loop. - # An actual real-world example of such a loop is systemd’s - # systemd-readahead-drop.service, which contains - # Also=systemd-readahead-collect.service, and that file in turn - # contains Also=systemd-readahead-drop.service, thus forming an endless - # loop. - my %seen; - - # We use while/shift because we push to the list in the body. - while (@args) { - my $name = shift @args; + for my $name (@args) { my $base = basename($name); # Try to make the path absolute, so that the user can call @@ -182,15 +141,6 @@ foreach my $package (@{$dh{DOPACKAGES}}) { next; } - # Handle all unit files specified via Also= explicitly. - # This is not necessary for enabling, but for disabling, as we - # cannot read the unit file when disabling (it was already - # deleted). - my @also = grep { !exists($seen{$_}) } extract_key($name, 'Also'); - $seen{$_} = 1 for @also; - @args = (@args, @also); - - $aliases{$name} = [ extract_key($name, 'Alias') ]; push @units, $name; } |