X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=ltt-sessiond%2Futils.c;fp=ltt-sessiond%2Futils.c;h=5b8e31b8d0b4e44623360fa68fa67288ba4a923d;hp=ff36ab187141e126dcfb1c720cdbe9083c26860b;hb=996b65c843a7ef76769e4f6cf66055c7c4acf3d0;hpb=7d8234d9e6f162ee642cdbec911f46c29b012c3d diff --git a/ltt-sessiond/utils.c b/ltt-sessiond/utils.c index ff36ab187..5b8e31b8d 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 @@ -44,7 +45,7 @@ const char *get_home_dir(void) * * 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 +71,19 @@ 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 +93,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: