[4.0] 1af9e04 By default linux::getopt(3) mangles the argv order, such that

Poul-Henning Kamp phk at FreeBSD.org
Tue Jun 24 11:31:46 CEST 2014


commit 1af9e045df49393eba0951c67b65c924ab128f8f
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Mon May 12 12:04:27 2014 +0000

    By default linux::getopt(3) mangles the argv order, such that
    
    	varnishadm -n bla param.set foo -bar
    
    gets interpreted as
    
    	varnishadm -n bla -bar param.set foo
    
    This is counterintuitive and invites random script breaking if people
    don't know they have to add an ornamental '--' in front of the CLI command
    in Linux systems.
    
    This commit makes Linux work the same way as every other POSIX system.
    
    Fixes	#1496

diff --git a/bin/varnishadm/varnishadm.c b/bin/varnishadm/varnishadm.c
index 90016a9..4b219de 100644
--- a/bin/varnishadm/varnishadm.c
+++ b/bin/varnishadm/varnishadm.c
@@ -439,7 +439,15 @@ main(int argc, char * const *argv)
 	const char *n_arg = NULL;
 	int opt, sock;
 
-	while ((opt = getopt(argc, argv, "n:S:T:t:")) != -1) {
+	/*
+	 * By default linux::getopt(3) mangles the argv order, such that
+	 * 	varnishadm -n bla param.set foo -bar
+	 * gets interpreted as
+	 * 	varnishadm -n bla -bar param.set foo 
+	 * The '+' stops that from happening
+	 * See #1496
+	 */
+	while ((opt = getopt(argc, argv, "+n:S:T:t:")) != -1) {
 		switch (opt) {
 		case 'n':
 			n_arg = optarg;



More information about the varnish-commit mailing list