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 - move the path concatenation functionality to a separate function 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 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/ Signed-off-by: Ivana Hutarova Varekova <varek...@redhat.com> --- 0 files changed, 0 insertions(+), 0 deletions(-) diff --git a/src/api.c b/src/api.c index 29de777..a4b7155 100644 --- a/src/api.c +++ b/src/api.c @@ -1099,6 +1099,20 @@ static inline pid_t cg_gettid(void) return syscall(__NR_gettid); } +static char *cg_concat_path(const char *pref, const char *suf, char *path) +{ + if ((pref[strlen(pref)-1] == '/') || + ((strlen(pref) == 0) && (suf[strlen(suf)-1] == '/'))) { + snprintf(path, FILENAME_MAX, "%s%s", suf, + pref+((pref[0] == '/') ? 1 : 0)); + } else { + snprintf(path, FILENAME_MAX, "%s%s/", suf, + pref+((pref[0] == '/') ? 1 : 0)); + } + path[FILENAME_MAX-1] = '\0'; + return path; +} + /* Call with cg_mount_table_lock taken */ /* path value have to have size at least FILENAME_MAX */ @@ -1125,9 +1139,7 @@ static char *cg_build_path_locked(const char *name, char *path, /* FIXME: missing OOM check here! */ - snprintf(path, FILENAME_MAX, "%s%s/", - tmp, name); - path[FILENAME_MAX-1] = '\0'; + cg_concat_path(name, tmp, path); free(tmp); } return path; ------------------------------------------------------------------------------ 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