[PATCH] swapon: make options --help and --version override --summary

Benno Schulenberg <[email protected]>
Newsgroups org.kernel.vger.util-linux
Message-ID <[email protected]>
When -h or --help is among the given options, most utilities
print a help text, ignoring all other options and arguments.
Make `swapon --summary --help` conform to this general pattern.

Signed-off-by: Benno Schulenberg <[email protected]>
---
 sys-utils/swapon.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/sys-utils/swapon.c b/sys-utils/swapon.c
index 419155d67..f7f82bbfb 100644
--- a/sys-utils/swapon.c
+++ b/sys-utils/swapon.c
@@ -145,6 +145,7 @@ struct swapon_ctl {
 		no_heading,		/* toggle --show headers */
 		raw,			/* toggle --show alignment */
 		show,			/* display --show information */
+		summarize,		/* display summary of swap use */
 		verbose;		/* be chatty */
 };
 
@@ -965,8 +966,8 @@ int main(int argc, char *argv[])
 			ctl.fix_page_size = 1;
 			break;
 		case 's':		/* status report */
-			status = display_summary();
-			return status;
+			ctl.summarize = 1;
+			break;
 		case 'v':		/* be chatty */
 			ctl.verbose = 1;
 			break;
@@ -1007,6 +1008,11 @@ int main(int argc, char *argv[])
 	}
 	argv += optind;
 
+	if (ctl.summarize) {
+		status = display_summary();
+		return status;
+	}
+
 	if (ctl.show || (!ctl.all && !numof_labels() && !numof_uuids() && *argv == NULL)) {
 		if (!ctl.ncolumns) {
 			/* default columns */
-- 
2.48.1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.