]> git.meshlink.io Git - meshlink/commitdiff
Warn when incorrect use of add or set causes variables to be removed.
authorGuus Sliepen <guus@tinc-vpn.org>
Thu, 25 Jul 2013 14:21:11 +0000 (16:21 +0200)
committerGuus Sliepen <guus@tinc-vpn.org>
Thu, 25 Jul 2013 15:30:47 +0000 (17:30 +0200)
src/tincctl.c

index f6e60fe6f263870935657c096279010ced04bc1b..d02bda52e1b2ded0cbbaa5072a9b2f1a7f4f627a 100644 (file)
@@ -1414,6 +1414,7 @@ static int cmd_config(int argc, char *argv[]) {
 
        /* Some simple checks. */
        bool found = false;
+       bool warnonremove = false;
 
        for(int i = 0; variables[i].name; i++) {
                if(strcasecmp(variables[i].name, variable))
@@ -1452,6 +1453,16 @@ static int cmd_config(int argc, char *argv[]) {
                                return 1;
                }
 
+               /* Change "add" into "set" for variables that do not allow multiple occurences.
+                  Turn on warnings when it seems variables might be removed unintentionally. */
+
+               if(action == 1 && !(variables[i].type & VAR_MULTIPLE)) {
+                       warnonremove = true;
+                       action = 0;
+               } else if(action == 0 && (variables[i].type & VAR_MULTIPLE)) {
+                       warnonremove = true;
+               }
+
                break;
        }
 
@@ -1534,9 +1545,14 @@ static int cmd_config(int argc, char *argv[]) {
                                }
                        // Set
                        } else if(action == 0) {
+                               // Warn if "set" was used for variables that can occur multiple times
+                               if(warnonremove && strcasecmp(bvalue, value))
+                                       fprintf(stderr, "Warning: removing %s = %s\n", variable, bvalue);
+
                                // Already set? Delete the rest...
                                if(set)
                                        continue;
+
                                // Otherwise, replace.
                                if(fprintf(tf, "%s = %s\n", variable, value) < 0) {
                                        fprintf(stderr, "Error writing to temporary file %s: %s\n", tmpfile, strerror(errno));