From mboxrd@z Thu Jan 1 00:00:00 1970 From: Tejun Heo Subject: [PATCH UPDATED cgroup/for-3.10] cgroup: make cgroup_path() not print double slashes Date: Sun, 14 Apr 2013 10:48:46 -0700 Message-ID: <20130414174846.GC3050@htj.dyndns.org> References: <20130414173704.GB3050@htj.dyndns.org> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:sender:date:from:to:cc:subject:message-id:references :mime-version:content-type:content-disposition:in-reply-to :user-agent; bh=NWC7xSKtAAUlIfxqrZPAWp5IS4JgVnAqpM2wO+iZ654=; b=weRnkJyKrlyKkqihDqFh0RRV1lx8xX40KeXUkbKw3IuOylOkk1228CXFjM+DC6F/sL hj562IgGfgdE/aeeOY7Tvq1AZqlpMGEJjBD0lRqwTlivVv1uB8bD2g1nEq/Rikp1Sbl0 cGzlNgbKi+jgKfaiYCStfsFYnpDvvOMscRqjazmBeejn4+ER62pFL29gZxDbcyHLVI3L vbdmjy14tUcl/2K3NURqF2MvhdAxhCzMmD8owDkuhl8cccKE6bdoh6Kk0fr7HCEXmyaZ //nxgrj4yXfwSIW/tHtPUh6u3E4GPyUDiKfcqM1jAvKBb0sN24Fkm9nE0PvkRHJhhwVg nwQg== Content-Disposition: inline In-Reply-To: <20130414173704.GB3050-Gd/HAXX7CRxy/B6EtB590w@public.gmane.org> List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: containers-bounces-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org Errors-To: containers-bounces-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org To: Li Zefan Cc: cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org >From da1f296fd2bfd5ad3c53d72a1ece593e821cf374 Mon Sep 17 00:00:00 2001 From: Tejun Heo Date: Sun, 14 Apr 2013 10:32:19 -0700 While reimplementing cgroup_path(), 65dff759d2 ("cgroup: fix cgroup_path() vs rename() race") introduced a bug where the path of a non-root cgroup would have two slahses at the beginning, which is caused by treating the root cgroup which has the name '/' like non-root cgroups. $ grep systemd /proc/self/cgroup 1:name=systemd://user/root/1 Fix it by special casing root cgroup case and not looping over it in the normal path. Signed-off-by: Tejun Heo Cc: Li Zefan --- The description was wrong. Updated. Thanks. kernel/cgroup.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/kernel/cgroup.c b/kernel/cgroup.c index 678a22c..faf55f5 100644 --- a/kernel/cgroup.c +++ b/kernel/cgroup.c @@ -1811,11 +1811,17 @@ int cgroup_path(const struct cgroup *cgrp, char *buf, int buflen) int ret = -ENAMETOOLONG; char *start; + if (!cgrp->parent) { + if (strlcpy(buf, "/", buflen) >= buflen) + return -ENAMETOOLONG; + return 0; + } + start = buf + buflen - 1; *start = '\0'; rcu_read_lock(); - while (cgrp) { + do { const char *name = cgroup_name(cgrp); int len; @@ -1824,15 +1830,12 @@ int cgroup_path(const struct cgroup *cgrp, char *buf, int buflen) goto out; memcpy(start, name, len); - if (!cgrp->parent) - break; - if (--start < buf) goto out; *start = '/'; cgrp = cgrp->parent; - } + } while (cgrp->parent); ret = 0; memmove(buf, start, buf + buflen - start); out: -- 1.8.1.4