Reviewed-by: Steven Dake <sdake@xxxxxxxxxx> On 01/22/2012 05:37 PM, Angus Salkeld wrote: > Signed-off-by: Angus Salkeld <asalkeld@xxxxxxxxxx> > --- > tools/corosync-cmapctl.c | 35 +++++++++++++++++++++++++++++++++++ > 1 files changed, 35 insertions(+), 0 deletions(-) > > diff --git a/tools/corosync-cmapctl.c b/tools/corosync-cmapctl.c > index 69b9bce..c4456fe 100644 > --- a/tools/corosync-cmapctl.c > +++ b/tools/corosync-cmapctl.c > @@ -52,6 +52,7 @@ enum user_action { > ACTION_GET, > ACTION_SET, > ACTION_DELETE, > + ACTION_DELETE_PREFIX, > ACTION_PRINT_ALL, > ACTION_PRINT_PREFIX, > ACTION_TRACK, > @@ -114,6 +115,9 @@ static int print_help(void) > printf("Delete key:\n"); > printf(" corosync-cmapctl -d key_name...\n"); > printf("\n"); > + printf("Delete multiple keys with prefix:\n"); > + printf(" corosync-cmapctl -D key_prefix...\n"); > + printf("\n"); > printf("Get key:\n"); > printf(" corosync-cmapctl [-b] -g key_name...\n"); > printf("\n"); > @@ -372,6 +376,29 @@ static void print_iter(cmap_handle_t handle, const char *prefix) > } > } > > +static void delete_with_prefix(cmap_handle_t handle, const char *prefix) > +{ > + cmap_iter_handle_t iter_handle; > + char key_name[CMAP_KEYNAME_MAXLEN + 1]; > + size_t value_len; > + cmap_value_types_t type; > + cs_error_t err; > + cs_error_t err2; > + > + err = cmap_iter_init(handle, prefix, &iter_handle); > + if (err != CS_OK) { > + fprintf (stderr, "Failed to initialize iteration. Error %s\n", cs_strerror(err)); > + exit (EXIT_FAILURE); > + } > + > + while ((err = cmap_iter_next(handle, iter_handle, key_name, &value_len, &type)) == CS_OK) { > + err2 = cmap_delete(handle, key_name); > + if (err2 != CS_OK) { > + fprintf(stderr, "Can't delete key %s. Error %s\n", key_name, cs_strerror(err2)); > + } > + } > +} > + > static void cmap_notify_fn( > cmap_handle_t cmap_handle, > cmap_track_handle_t cmap_track_handle, > @@ -725,6 +752,9 @@ int main(int argc, char *argv[]) > case 'd': > action = ACTION_DELETE; > break; > + case 'D': > + action = ACTION_DELETE_PREFIX; > + break; > case 'p': > settings_file = optarg; > action = ACTION_LOAD; > @@ -796,6 +826,11 @@ int main(int argc, char *argv[]) > } > } > break; > + case ACTION_DELETE_PREFIX: > + for (i = 0; i < argc; i++) { > + delete_with_prefix(handle, argv[i]); > + } > + break; > case ACTION_LOAD: > read_in_config_file(handle, settings_file); > break; _______________________________________________ discuss mailing list discuss@xxxxxxxxxxxx http://lists.corosync.org/mailman/listinfo/discuss