ends/starts with character "/" itself. This character is added now only in
cases it is wanted and it was not set.

Changelog
- incorporate Jan's feedback - fix typo in patch description, use snprintf 
instead of sprintf
- deal with the situation if directory name is empty as well

Example:
Old version:
cg_build_path("", path, memory);
returns /sys/fs/cgroup/memory//
cg_build_path("/3", path, memory);
returns /sys/fs/cgroup/memory//3/
cg_build_path("3/", path, memory);
returns /sys/fs/cgroup/memory/3//

New verison:
cg_build_path("", path, memory);
returns /sys/fs/cgroup/memory/
cg_build_path("/3", path, memory);
returns /sys/fs/cgroup/memory/3/
cg_build_path("3/", path, memory);
returns /sys/fs/cgroup/memory/3/

Signed-off-by: Ivana Hutarova Varekova <varek...@redhat.com>
---

 src/api.c |   14 ++++++++++++--
 1 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/src/api.c b/src/api.c
index 29de777..b8045a1 100644
--- a/src/api.c
+++ b/src/api.c
@@ -1125,8 +1125,18 @@ static char *cg_build_path_locked(const char *name, char 
*path,
 
                                /* FIXME: missing OOM check here! */
 
-                               snprintf(path, FILENAME_MAX, "%s%s/",
-                                       tmp, name);
+                               if ((name[strlen(name)-1] == '/') ||
+                                   ((strlen(name) == 0) &&
+                                   (tmp[strlen(tmp)-1] == '/')))
+                                       snprintf(path, FILENAME_MAX,
+                                               "%s%s", tmp,
+                                               name+((name[0] == '/') ?
+                                                       1 : 0));
+                               else
+                                       snprintf(path, FILENAME_MAX,
+                                               "%s%s/", tmp,
+                                               name+((name[0] == '/') ?
+                                                       1 : 0));
                                path[FILENAME_MAX-1] = '\0';
                                free(tmp);
                        }


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Libcg-devel mailing list
Libcg-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libcg-devel

Reply via email to