[sheepdog] [PATCH] tools/zk_control: add sort options for list subcommand

Liu Yuan namei.unix at gmail.com
Wed Mar 4 08:57:52 CET 2015


On Wed, Mar 04, 2015 at 02:02:11PM +0800, Meng Lingkun wrote:
> From: Meng Lingkun <menglingkun at cmss.chinamobile.com>
> 
> It's more useable to list the sequential znodes in queue with sort function.
> 
> Signed-off-by: Meng Lingkun <menglingkun at cmss.chinamobile.com>
> ---
>  tools/zk_control.c | 43 ++++++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 42 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/zk_control.c b/tools/zk_control.c
> index 75783e1..4bf47ff 100644
> --- a/tools/zk_control.c
> +++ b/tools/zk_control.c
> @@ -11,6 +11,8 @@
>   * along with this program. If not, see <http://www.gnu.org/licenses/>.
>   */
>  
> +#include <getopt.h>
> +#include <stdlib.h>
>  #include <zookeeper/zookeeper.h>
>  #include <string.h>
>  #include <arpa/inet.h>
> @@ -231,6 +233,16 @@ err:
>  	return -1;
>  }
>  
> +static int seq_cmp(const void *a, const void *b)
> +{
> +	return strcmp(*(const char **)b, *(const char **)a);
> +}
> +
> +static int seq_cmp2(const void *a, const void *b)
> +{
> +	return strcmp(*(const char **)a, *(const char **)b);
> +}
> +
>  static int do_list(int argc, char **argv)
>  {
>  	struct String_vector strs;
> @@ -242,6 +254,14 @@ static int do_list(int argc, char **argv)
>  	struct Stat stat;
>  	int32_t seq;
>  	struct node_id *nid;
> +	char opts[] = "sS", ch;
> +	int longindex;
> +	struct option lopts[] = {
> +		{ "sort", 0, NULL, 's' },
> +		{ "SORT", 0, NULL, 'S' },

Only one kind of sort is good enough and sort the list by default, no need to
add one unnecessary option.

Thanks,
Yuan



More information about the sheepdog mailing list