[lxc-devel] [PATCH 1/1] cgmanager: cgm_set: return the length we found
Stéphane Graber
stgraber at ubuntu.com
Wed Jan 22 20:06:10 UTC 2014
On Wed, Jan 22, 2014 at 01:53:04PM -0600, Serge Hallyn wrote:
> Signed-off-by: Serge Hallyn <serge.hallyn at ubuntu.com>
Acked-by: Stéphane Graber <stgraber at ubuntu.com>
> ---
> src/lxc/cgmanager.c | 12 ++++++++++--
> 1 file changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/src/lxc/cgmanager.c b/src/lxc/cgmanager.c
> index 033dc01..2fa49a7 100644
> --- a/src/lxc/cgmanager.c
> +++ b/src/lxc/cgmanager.c
> @@ -248,6 +248,7 @@ static char *cgm_get_cgroup(struct lxc_handler *handler, const char *subsystem)
> int cgm_get(const char *filename, char *value, size_t len, const char *name, const char *lxcpath)
> {
> char *result, *controller, *key, *cgroup;
> + size_t newlen;
>
> controller = alloca(strlen(filename)+1);
> strcpy(controller, filename);
> @@ -267,11 +268,18 @@ int cgm_get(const char *filename, char *value, size_t len, const char *name, con
> return -1;
> }
> free(cgroup);
> + newlen = strlen(result);
> strncpy(value, result, len);
> - if (strlen(result) >= len)
> + if (newlen >= len) {
> value[len-1] = '\0';
> + newlen = len-1;
> + } else if (newlen+1 < len) {
> + // cgmanager doesn't add eol to last entry
> + value[newlen++] = '\n';
> + value[newlen] = '\0';
> + }
> nih_free(result);
> - return len;
> + return newlen;
> }
>
> static int cgm_do_set(const char *controller, const char *file,
> --
> 1.8.5.3
>
> _______________________________________________
> lxc-devel mailing list
> lxc-devel at lists.linuxcontainers.org
> http://lists.linuxcontainers.org/listinfo/lxc-devel
--
Stéphane Graber
Ubuntu developer
http://www.ubuntu.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20140122/eeabeada/attachment.pgp>
More information about the lxc-devel
mailing list