X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=ltt-sessiond%2Futils.c;h=6b22d9693c693e59bfd389d273b9d1aee5dc2974;hp=ff36ab187141e126dcfb1c720cdbe9083c26860b;hb=050349bbb362ea993533591532643022efeab864;hpb=7823a9abb8f2ca69baba56f9fceb561a5f5516ad diff --git a/ltt-sessiond/utils.c b/ltt-sessiond/utils.c index ff36ab187..6b22d9693 100644 --- a/ltt-sessiond/utils.c +++ b/ltt-sessiond/utils.c @@ -1,5 +1,6 @@ /* - * Copyright (C) 2011 - David Goulet + * Copyright (C) 2011 - David Goulet + * Copyright (C) 2011 - Mathieu Desnoyers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -29,10 +30,9 @@ #include "utils.h" /* - * get_home_dir + * Return pointer to home directory path using the env variable HOME. * - * Return pointer to home directory path using the env variable HOME. - * No home, NULL is returned. + * No home, NULL is returned. */ const char *get_home_dir(void) { @@ -40,11 +40,9 @@ const char *get_home_dir(void) } /* - * mkdir_recursive - * - * Create recursively directory using the FULL path. + * Create recursively directory using the FULL path. */ -int mkdir_recursive(const char *path, mode_t mode) +int mkdir_recursive(const char *path, mode_t mode, uid_t uid, gid_t gid) { int ret; char *p, tmp[PATH_MAX]; @@ -70,7 +68,18 @@ int mkdir_recursive(const char *path, mode_t mode) if (ret < 0) { if (!(errno == EEXIST)) { perror("mkdir recursive"); - ret = errno; + ret = -errno; + goto umask_error; + } + } else if (ret == 0) { + /* + * We created the directory. Set its ownership to the + * user/group specified. + */ + ret = chown(tmp, uid, gid); + if (ret < 0) { + perror("chown in mkdir recursive"); + ret = -errno; goto umask_error; } } @@ -80,7 +89,18 @@ int mkdir_recursive(const char *path, mode_t mode) ret = mkdir(tmp, mode); if (ret < 0) { - ret = errno; + ret = -errno; + } else if (ret == 0) { + /* + * We created the directory. Set its ownership to the user/group + * specified. + */ + ret = chown(tmp, uid, gid); + if (ret < 0) { + perror("chown in mkdir recursive"); + ret = -errno; + goto umask_error; + } } umask_error: