X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=ltt-sessiond%2Futils.c;h=429d25b3b1a2ffa243d40f2d2cd32abbd1a89f27;hb=558e70e9829c97ecd228516f6e312768be0536d7;hp=ff36ab187141e126dcfb1c720cdbe9083c26860b;hpb=7823a9abb8f2ca69baba56f9fceb561a5f5516ad;p=lttng-tools.git diff --git a/ltt-sessiond/utils.c b/ltt-sessiond/utils.c index ff36ab187..429d25b3b 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 + * 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,24 @@ #include "utils.h" /* - * get_home_dir + * Write to writable pipe used to notify a thread. + */ +int notify_thread_pipe(int wpipe) +{ + int ret; + + ret = write(wpipe, "!", 1); + if (ret < 0) { + perror("write poll pipe"); + } + + return ret; +} + +/* + * 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 +55,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 +83,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 +104,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: