[Pkg-apache-commits] [SCM] Debian packaging for apache2 (Apache HTTPD 2.x) branch, next, updated. 9ec48db0b5d22d0a589e3b13eb011d1ecc1a1d56

Arno Töll arno at debian.org
Thu Apr 26 23:01:12 UTC 2012


The following commit has been merged in the next branch:
commit 08c7718af9782d3fb4d8d307e9c4caf1f34ee950
Author: Arno Töll <arno at debian.org>
Date:   Thu Apr 26 02:54:54 2012 +0200

    Impplement missing hooks in a2query. Now it can be told apart whether a piece
    of configuration was not found or disabled by us

diff --git a/debian/a2query.in b/debian/a2query.in
index 9064ae2..bf40d9c 100755
--- a/debian/a2query.in
+++ b/debian/a2query.in
@@ -71,6 +71,7 @@ our @MODULES = ();
 our @CONFS = ();
 our @SITES =();
 our @HELP = ();
+our %verbose_state = ( 'admin' => 'site administrator', 'maint' => 'maintainer script', 'unknown' => 'unknown' );
 
 =head1 SYNOPSIS
 
@@ -126,6 +127,14 @@ returns the currently installed Apache 2 HTTP server version
 
 =back
 
+=head1 EXIT CODES
+
+B<a2query> returns with a zero (S<0>) exit status if the requested operation was
+effectuated successfully and with a non-zero status otherwise. In case of an
+error it leaves with error code S<32> if a requested module, site or
+configuration was not found and S<33> if a module, site or configuration was
+disabled by a maintainer script.
+
 =head1 SEE ALSO
 
 L<apache2ctl>(8), L<apache2>(8), L<perl>(1)
@@ -237,6 +246,9 @@ sub switch_history
 	my $which = shift;
 	my $what = shift;
 	my $name = shift;
+
+	$name =~ s/\.conf$//;
+
 	foreach my $state (@STATES)
 	{
 		my $state_token = "$STATE_DIR/$which/$what" . "_by_$state/" . $name;
@@ -248,72 +260,66 @@ sub switch_history
 	return 0;
 }
 
-load_defaults();
-load_modules();
-
-my %opts;
-my $help = 1;
-getopt('m:s:c:havMd', \%opts);
-
 
-push @HELP, ["m [MODULE]", "checks whether the module MODULE is enabled, lists all enabled modules if no argument was given"];
-if (exists $opts{'m'})
+sub query_state
 {
-	--$help;
+	my $type    = shift;
+	my $pattern = shift;
+	my $listref = shift;
+
 	my $matches = 0;
-	if (not $opts{'m'})
+	if (not $pattern)
 	{
-		$opts{'m'} = ".";
+		$pattern = ".";
 	}
-	foreach my $module (grep { $_ =~ m/$opts{'m'}/ } @MODULES)
+	foreach my $module (grep { $_ =~ m/$pattern/ } @{ $listref })
 	{
-		my $state = switch_history("module", "enabled", $module);
+		my $state = switch_history($type, "enabled", $module);
 		if (!$state)
 		{
 			$state = "unknown";
 		}
-		print("$module (by $state)\n");
+		print("$module (enabled by $verbose_state{$state})\n");
 		$matches++;
 	}
 	if (!$matches)
 	{
-		my $reason = "No module matches $opts{'m'}";
+		my $reason = "No $type matches $pattern";
 		my $retval = $E_NOTFOUND;
-		#Figure out something for disabled modules
-		#$retval = $E_OFFBYMAINT;
+		my $state = switch_history($type, "disabled", $pattern);
+		if ($state)
+		{
+			$reason .= " (disabled by $verbose_state{$state})";
+			if ($state eq 'maint')
+			{
+				$retval = $E_OFFBYMAINT;
+			}
+		}
 		fail($reason, $retval);
 	}
 }
 
+load_defaults();
+load_modules();
+
+my %opts;
+my $help = 1;
+getopt('m:s:c:havMd', \%opts);
+
+
+push @HELP, ["m [MODULE]", "checks whether the module MODULE is enabled, lists all enabled modules if no argument was given"];
+if (exists $opts{'m'})
+{
+	--$help;
+	query_state('module', $opts{'m'}, \@MODULES);
+}
+
 push @HELP, ["s [SITE]", "checks whether the site SITE is enabled, lists all sites if no argument was given"];
 if (exists $opts{'s'})
 {
 	--$help;
 	load_sites();
-	my $matches = 0;
-	if (not $opts{'s'})
-	{
-		$opts{'s'} = ".";
-	}
-	foreach my $site (grep { $_ =~ m/$opts{'s'}/ } @SITES)
-	{
-		$site =~ s/\.conf$//;
-		my $state = switch_history("site", "enabled", $site);
-		if (!$state)
-		{
-			$state = "unknown";
-		}
-		print("$site (by $state)\n");
-		$matches++;
-	}
-	if (!$matches)
-	{
-		my $reason = "No site matches $opts{'s'}";
-		my $retval = $E_NOTFOUND;
-		#ditto
-		#$retval = $E_OFFBYMAINT;
-		fail($reason, $retval);
-	}
+	query_state('site', $opts{'s'}, \@SITES);
 }
 
 
@@ -322,30 +328,7 @@ if (exists $opts{'c'})
 {
 	--$help;
 	load_conf();
-	my $matches = 0;
-	if (not $opts{'c'})
-	{
-		$opts{'c'} = ".";
-	}
-	foreach my $conf (grep { $_ =~ m/$opts{'c'}/ } @CONFS)
-	{
-		$conf =~ s/\.conf$//;
-		my $state = switch_history("conf", "enabled", $conf);
-		if (!$state)
-		{
-			$state = "unknown";
-		}
-		print("$conf (by $state)\n");
-		$matches++;
-	}
-	if (!$matches)
-	{
-		my $reason = "No conf matches $opts{'c'}";
-		my $retval = $E_NOTFOUND;
-		#ditto
-		#$retval = $E_OFFBYMAINT;
-		fail($reason, $retval);
-	}
+	query_state('conf', $opts{'c'}, \@CONFS);
 }
 
 
@@ -384,10 +367,18 @@ if (exists $opts{'h'} or $help == 1)
 	my $usage = "$0 ";
 	map { $usage .= "-$_->[0] " } @HELP;
 	print("Usage: $usage\n");
+	my $switch_name;
+	my $description;
+	format STDOUT =
+@<<<<<<<<<<<<	^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+"-$switch_name",        $description,
+~~	        ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+			$description,
+.
 	foreach my $switch (@HELP)
 	{
-		my ($switch, $description) = ($switch->[0], $switch->[1]);
-		print("-$switch\t\t$description\n");
+		($switch_name, $description) = ($switch->[0], $switch->[1]);
+		write STDOUT;
 	}
 	exit $E_OK;
 }
diff --git a/debian/changelog b/debian/changelog
index 29b9372..ec12b3e 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -19,8 +19,9 @@ apache2 (2.4.2-2) experimental; urgency=low
   * Change various state and run directories used by Apache from
     /var/run/<basename> to /var/run/apache2/<basename>. This might change again
     for Wheezy+1 to adopt /run.
+  * Use more exit status codes for a2query, make its output more readable.
 
- -- Arno Töll <arno at debian.org>  Thu, 26 Apr 2012 00:51:22 +0200
+ -- Arno Töll <arno at debian.org>  Thu, 26 Apr 2012 03:22:05 +0200
 
 apache2 (2.4.2-1) experimental; urgency=low
 

-- 
Debian packaging for apache2 (Apache HTTPD 2.x)



More information about the Pkg-apache-commits mailing list