[lxc-devel] [PATCH] lxc-ls: Restore old [filter] behaviour
Stéphane Graber
stgraber at stgraber.org
Thu Jan 28 11:06:00 UTC 2016
On Wed, Jan 20, 2016 at 01:54:45AM +0100, Christian Brauner wrote:
> In the Python implementation users could pass a regex without a parameter flag
> as additional argument on the command line. The C implementation gained the
> flag -r/--regex for this. To not irritate users we restore the old behaviour
> and additionally rename -r/--regex to --filter to allow eplicitly passing the
> regex.
>
> Signed-off-by: Christian Brauner <christian.brauner at mailbox.org>
Hello,
This doesn't apply to git master right now, can you re-send a version
which does?
Thanks!
> ---
> src/lxc/arguments.h | 2 +-
> src/lxc/lxc_ls.c | 14 ++++++++------
> 2 files changed, 9 insertions(+), 7 deletions(-)
>
> diff --git a/src/lxc/arguments.h b/src/lxc/arguments.h
> index a3d2932..46fecbf 100644
> --- a/src/lxc/arguments.h
> +++ b/src/lxc/arguments.h
> @@ -123,7 +123,7 @@ struct lxc_arguments {
> /* lxc-ls */
> char *ls_fancy_format;
> char *ls_groups;
> - char *ls_regex;
> + char *ls_filter;
> unsigned int ls_nesting; /* maximum allowed nesting level */
> bool ls_active;
> bool ls_fancy;
> diff --git a/src/lxc/lxc_ls.c b/src/lxc/lxc_ls.c
> index b270ff1..5bbff1e 100644
> --- a/src/lxc/lxc_ls.c
> +++ b/src/lxc/lxc_ls.c
> @@ -49,6 +49,7 @@ lxc_log_define(lxc_ls, lxc);
> #define LS_ACTIVE 3
> #define LS_RUNNING 4
> #define LS_NESTING 5
> +#define LS_FILTER 6
>
> /* Store container info. */
> struct ls {
> @@ -161,7 +162,7 @@ static const struct option my_longopts[] = {
> {"stopped", no_argument, 0, LS_STOPPED},
> {"nesting", optional_argument, 0, LS_NESTING},
> {"groups", required_argument, 0, 'g'},
> - {"regex", required_argument, 0, 'r'},
> + {"filter", required_argument, 0, LS_FILTER},
> LXC_COMMON_OPTIONS
> };
>
> @@ -354,9 +355,10 @@ static int ls_get(struct ls **m, size_t *size, const struct lxc_arguments *args,
> char *name = containers[i];
>
> /* Filter container names by regex the user gave us. */
> - if (args->ls_regex) {
> + if (args->ls_filter || args->argc == 1) {
> regex_t preg;
> - check = regcomp(&preg, args->ls_regex, REG_NOSUB | REG_EXTENDED);
> + tmp = args->ls_filter ? args->ls_filter : args->argv[0];
> + check = regcomp(&preg, tmp, REG_NOSUB | REG_EXTENDED);
> if (check == REG_ESPACE) /* we're out of memory */
> goto out;
> else if (check != 0)
> @@ -923,8 +925,8 @@ static int my_parser(struct lxc_arguments *args, int c, char *arg)
> case 'g':
> args->groups = arg;
> break;
> - case 'r':
> - args->ls_regex = arg;
> + case LS_FILTER:
> + args->ls_filter = arg;
> break;
> case 'F':
> args->ls_fancy_format = arg;
> @@ -986,7 +988,7 @@ static int ls_remove_lock(const char *path, const char *name,
> }
>
> int check = snprintf(*lockpath, *len_lockpath, "%s/lxc/lock/%s/%s", RUNTIME_PATH, path, name);
> - if (check < 0 || check >= *len_lockpath)
> + if (check < 0 || (size_t)check >= *len_lockpath)
> return -1;
>
> lxc_rmdir_onedev(*lockpath, NULL);
> --
> 2.7.0
>
> _______________________________________________
> lxc-devel mailing list
> lxc-devel at lists.linuxcontainers.org
> http://lists.linuxcontainers.org/listinfo/lxc-devel
--
Stéphane
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20160128/0a33ec8c/attachment.sig>
More information about the lxc-devel
mailing list