Re: [PATCH] Extend corosync-cmapctl -p option by allowing keys to be deleted.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Vladislav,

> Hi Jan!

14.07.2014 18:23, Jan Friesse wrote:
Vladislav,
I really like your patch, but I have problem with '-' character.
Actually key name beginning with '-' is valid. So my proposed solution
is to:
- escape '-' character
- or (preferred) use some other character which is NOT valid key name.


It doesn't really matter for me, so which one do you prefer?
^?
*?
some other?

I was thinking about !,@,#,$,%,^,&,* ;). Actually, ^ seems to be closest (* is also good, but one day we may decide to use it for regexp).

Regards,
  Honza


Function which checks key name validity:

static int icmap_is_valid_name_char(char c)
{
         return ((c >= 'a' && c <= 'z') ||
                 (c >= 'A' && c <= 'Z') ||
                 (c >= '0' && c <= '9') ||
                 c == '.' || c == '_' || c == '-' || c == '/' || c == ':');
}

So basically ^[a-zA-Z0-9._-/:].

Regards,
   Honza

Vladislav Bogdanov napsal(a):
Signed-off-by: Vladislav Bogdanov <bubble@xxxxxxxxxxxxx>
---
   man/corosync-cmapctl.8   |   10 +++++++++-
   tools/corosync-cmapctl.c |   29 ++++++++++++++++++++++++-----
   2 files changed, 33 insertions(+), 6 deletions(-)

diff --git a/man/corosync-cmapctl.8 b/man/corosync-cmapctl.8
index 02fbdc4..aeb0115 100644
--- a/man/corosync-cmapctl.8
+++ b/man/corosync-cmapctl.8
@@ -49,7 +49,15 @@ for bin, value is file name (or \- for stdin)
   corosync\-cmapctl \fB\-p\fR filename
   .IP
   the format of the file is:
-<key_name> <type> <value>
+[-[-]]<key_name>[ <type> <value>]
+.IP
+Keys prefixed with single dash ('-') are deleted (see \fB\-d\fR).
+.IP
+Keys (actually prefixes) prefixed with double dash ('--') are deleted
by prefix (see \fB\-D\fR).
+.IP
+<type> and <value> are optional (not checked) in above cases.
+.IP
+Other keys are set (see \fB\-s\fR) so both <type> and <value> are
required.
   .SS "Delete key:"
   .IP
   corosync\-cmapctl \fB\-d\fR key_name...
diff --git a/tools/corosync-cmapctl.c b/tools/corosync-cmapctl.c
index 7e23ab0..3fa4985 100644
--- a/tools/corosync-cmapctl.c
+++ b/tools/corosync-cmapctl.c
@@ -110,7 +110,11 @@ static int print_help(void)
       printf("    corosync-cmapctl -p filename\n");
       printf("\n");
       printf("    the format of the file is:\n");
-    printf("    <key_name> <type> <value>\n");
+    printf("    [-[-]]<key_name>[ <type> <value>]\n");
+    printf("    Keys prefixed with single dash ('-') are deleted (see
-d).\n");
+    printf("    Keys (actually prefixes) prefixed with double dash
('--') are deleted by prefix (see -D).\n");
+    printf("    <type> and <value> are optional (not checked) in
above cases.\n");
+    printf("    Other keys are set (see -s) so both <type> and
<value> are required.\n");
       printf("\n");
       printf("Delete key:\n");
       printf("    corosync-cmapctl -d key_name...\n");
@@ -705,12 +709,27 @@ static void read_in_config_file(cmap_handle_t
handle, char * filename)

           /*
            * should be:
-         * <key> <type> <value>
+         * [-[-]]<key>[ <type> <value>]
            */
           key_name = strtok(line, " \n");
-        key_type_s = strtok(NULL, " \n");
-        key_value_s = strtok(NULL, " \n");
-        set_key(handle, key_name, key_type_s, key_value_s);
+        if (key_name && *key_name == '-') {
+            key_name++;
+            if (*key_name == '-') {
+                key_name++;
+                delete_with_prefix(handle, key_name);
+            } else {
+                cs_error_t err;
+
+                err = cmap_delete(handle, key_name);
+                if (err != CS_OK) {
+                    fprintf(stderr, "Can't delete key %s. Error
%s\n", key_name, cs_strerror(err));
+                }
+            }
+        } else {
+            key_type_s = strtok(NULL, " \n");
+            key_value_s = strtok(NULL, " \n");
+            set_key(handle, key_name, key_type_s, key_value_s);
+        }
       }

       fclose (fh);




_______________________________________________
discuss mailing list
discuss@xxxxxxxxxxxx
http://lists.corosync.org/mailman/listinfo/discuss




[Index of Archives]     [Linux Clusters]     [Corosync Project]     [Linux USB Devel]     [Linux Audio Users]     [Photo]     [Yosemite News]    [Yosemite Photos]    [Linux Kernel]     [Linux SCSI]     [X.Org]

  Powered by Linux