Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
ret = run_as_mkdir_recursive(msg.u.snapshot_channel.pathname,
S_IRWXU | S_IRWXG, uid, gid);
if (ret < 0) {
ret = run_as_mkdir_recursive(msg.u.snapshot_channel.pathname,
S_IRWXU | S_IRWXG, uid, gid);
if (ret < 0) {
ERR("Trace directory creation error");
goto error;
}
ERR("Trace directory creation error");
goto error;
}
/* Create directory */
ret = run_as_mkdir_recursive(pathname, S_IRWXU | S_IRWXG, uid, gid);
if (ret < 0) {
/* Create directory */
ret = run_as_mkdir_recursive(pathname, S_IRWXU | S_IRWXG, uid, gid);
if (ret < 0) {
ERR("Trace directory creation error");
goto error;
}
ERR("Trace directory creation error");
goto error;
}
session->kernel_session->consumer->dst.trace_path,
S_IRWXU | S_IRWXG, session->uid, session->gid);
if (ret < 0) {
session->kernel_session->consumer->dst.trace_path,
S_IRWXU | S_IRWXG, session->uid, session->gid);
if (ret < 0) {
ERR("Trace directory creation error");
goto error;
}
ERR("Trace directory creation error");
goto error;
}
ret = run_as_mkdir_recursive(usess->consumer->dst.trace_path,
S_IRWXU | S_IRWXG, ua_sess->euid, ua_sess->egid);
if (ret < 0) {
ret = run_as_mkdir_recursive(usess->consumer->dst.trace_path,
S_IRWXU | S_IRWXG, ua_sess->euid, ua_sess->egid);
if (ret < 0) {
ERR("Trace directory creation error");
goto error_unlock;
}
ERR("Trace directory creation error");
goto error_unlock;
}
ret = run_as_mkdir_recursive(pathname, S_IRWXU | S_IRWXG,
ua_sess->euid, ua_sess->egid);
if (ret < 0) {
ret = run_as_mkdir_recursive(pathname, S_IRWXU | S_IRWXG,
ua_sess->euid, ua_sess->egid);
if (ret < 0) {
ERR("Trace directory creation error");
goto error;
}
ERR("Trace directory creation error");
goto error;
}
S_IRWXU | S_IRWXG,
euid, egid);
if (ret) {
S_IRWXU | S_IRWXG,
euid, egid);
if (ret) {
PERROR("run_as_mkdir_recursive");
goto error;
}
PERROR("run_as_mkdir_recursive");
goto error;
}
O_WRONLY | O_CREAT | O_EXCL,
S_IRUSR | S_IWUSR, euid, egid);
if (ret < 0) {
O_WRONLY | O_CREAT | O_EXCL,
S_IRUSR | S_IWUSR, euid, egid);
if (ret < 0) {
PERROR("Opening metadata file");
goto error;
}
PERROR("Opening metadata file");
goto error;
}
/* Create index directory if necessary. */
ret = utils_mkdir(fullpath, S_IRWXU | S_IRWXG, uid, gid);
if (ret < 0) {
/* Create index directory if necessary. */
ret = utils_mkdir(fullpath, S_IRWXU | S_IRWXG, uid, gid);
if (ret < 0) {
PERROR("Index trace directory creation error");
goto error;
}
PERROR("Index trace directory creation error");
goto error;
}
+struct run_as_ret {
+ int ret;
+ int _errno;
+};
+
#ifdef VALGRIND
static
int use_clone(void)
#ifdef VALGRIND
static
int use_clone(void)
static
int _mkdir(void *_data)
{
static
int _mkdir(void *_data)
{
struct run_as_mkdir_data *data = _data;
struct run_as_mkdir_data *data = _data;
- ret = mkdir(data->path, data->mode);
- if (ret < 0) {
- ret = -errno;
- }
-
- return ret;
+ return mkdir(data->path, data->mode);
}
static
int _open(void *_data)
{
struct run_as_open_data *data = _data;
}
static
int _open(void *_data)
{
struct run_as_open_data *data = _data;
return open(data->path, data->flags, data->mode);
}
static
int _unlink(void *_data)
{
return open(data->path, data->flags, data->mode);
}
static
int _unlink(void *_data)
{
struct run_as_unlink_data *data = _data;
struct run_as_unlink_data *data = _data;
- ret = unlink(data->path);
- if (ret < 0) {
- ret = -errno;
- }
-
- return ret;
+ return unlink(data->path);
}
static
int _recursive_rmdir(void *_data)
{
}
static
int _recursive_rmdir(void *_data)
{
struct run_as_recursive_rmdir_data *data = _data;
struct run_as_recursive_rmdir_data *data = _data;
- ret = utils_recursive_rmdir(data->path);
- if (ret < 0) {
- ret = -errno;
- }
-
- return ret;
+ return utils_recursive_rmdir(data->path);
int ret;
struct run_as_data *data = _data;
ssize_t writelen;
int ret;
struct run_as_data *data = _data;
ssize_t writelen;
+ struct run_as_ret sendret;
/*
* Child: it is safe to drop egid and euid while sharing the
/*
* Child: it is safe to drop egid and euid while sharing the
ret = setegid(data->gid);
if (ret < 0) {
PERROR("setegid");
ret = setegid(data->gid);
if (ret < 0) {
PERROR("setegid");
ret = seteuid(data->uid);
if (ret < 0) {
PERROR("seteuid");
ret = seteuid(data->uid);
if (ret < 0) {
PERROR("seteuid");
* Also set umask to 0 for mkdir executable bit.
*/
umask(0);
* Also set umask to 0 for mkdir executable bit.
*/
umask(0);
- sendret = (*data->cmd)(data->data);
+ ret = (*data->cmd)(data->data);
+ sendret.ret = ret;
+ sendret._errno = errno;
/* send back return value */
writelen = lttng_write(data->retval_pipe, &sendret, sizeof(sendret));
if (writelen < sizeof(sendret)) {
/* send back return value */
writelen = lttng_write(data->retval_pipe, &sendret, sizeof(sendret));
if (writelen < sizeof(sendret)) {
pid_t pid;
int retval_pipe[2];
void *child_stack;
pid_t pid;
int retval_pipe[2];
void *child_stack;
+ struct run_as_ret recvret;
/*
* If we are non-root, we can only deal with our own uid.
*/
if (geteuid() != 0) {
if (uid != geteuid()) {
/*
* If we are non-root, we can only deal with our own uid.
*/
if (geteuid() != 0) {
if (uid != geteuid()) {
+ recvret.ret = -1;
+ recvret._errno = EPERM;
ERR("Client (%d)/Server (%d) UID mismatch (and sessiond is not root)",
uid, geteuid());
ERR("Client (%d)/Server (%d) UID mismatch (and sessiond is not root)",
uid, geteuid());
}
}
ret = pipe(retval_pipe);
if (ret < 0) {
}
}
ret = pipe(retval_pipe);
if (ret < 0) {
+ recvret.ret = -1;
+ recvret._errno = errno;
goto end;
}
run_as_data.data = data;
goto end;
}
run_as_data.data = data;
MAP_PRIVATE | MAP_GROWSDOWN | MAP_ANONYMOUS | LTTNG_MAP_STACK,
-1, 0);
if (child_stack == MAP_FAILED) {
MAP_PRIVATE | MAP_GROWSDOWN | MAP_ANONYMOUS | LTTNG_MAP_STACK,
-1, 0);
if (child_stack == MAP_FAILED) {
+ recvret.ret = -1;
+ recvret._errno = ENOMEM;
pid = lttng_clone_files(child_run_as, child_stack + (RUNAS_CHILD_STACK_SIZE / 2),
&run_as_data);
if (pid < 0) {
pid = lttng_clone_files(child_run_as, child_stack + (RUNAS_CHILD_STACK_SIZE / 2),
&run_as_data);
if (pid < 0) {
+ recvret.ret = -1;
+ recvret._errno = errno;
goto unmap_stack;
}
/* receive return value */
goto unmap_stack;
}
/* receive return value */
- readlen = lttng_read(retval_pipe[0], &retval, sizeof(retval));
- if (readlen < sizeof(retval)) {
- ret = -1;
+ readlen = lttng_read(retval_pipe[0], &recvret, sizeof(recvret));
+ if (readlen < sizeof(recvret)) {
+ recvret.ret = -1;
+ recvret._errno = errno;
*/
pid = waitpid(pid, &status, 0);
if (pid < 0 || !WIFEXITED(status) || WEXITSTATUS(status) != 0) {
*/
pid = waitpid(pid, &status, 0);
if (pid < 0 || !WIFEXITED(status) || WEXITSTATUS(status) != 0) {
+ recvret.ret = -1;
+ recvret._errno = errno;
}
unmap_stack:
ret = munmap(child_stack, RUNAS_CHILD_STACK_SIZE);
if (ret < 0) {
}
unmap_stack:
ret = munmap(child_stack, RUNAS_CHILD_STACK_SIZE);
if (ret < 0) {
+ recvret.ret = -1;
+ recvret._errno = errno;
}
close_pipe:
ret = close(retval_pipe[0]);
if (ret) {
}
close_pipe:
ret = close(retval_pipe[0]);
if (ret) {
+ recvret.ret = -1;
+ recvret._errno = errno;
PERROR("close");
}
ret = close(retval_pipe[1]);
if (ret) {
PERROR("close");
}
ret = close(retval_pipe[1]);
if (ret) {
+ recvret.ret = -1;
+ recvret._errno = errno;
+ errno = recvret._errno;
+ return recvret.ret;
static
int run_as_noclone(int (*cmd)(void *data), void *data, uid_t uid, gid_t gid)
{
static
int run_as_noclone(int (*cmd)(void *data), void *data, uid_t uid, gid_t gid)
{
mode_t old_mask;
old_mask = umask(0);
ret = cmd(data);
mode_t old_mask;
old_mask = umask(0);
ret = cmd(data);
closeret = run_as_unlink(shm_path,
channel->uid, channel->gid);
if (closeret) {
closeret = run_as_unlink(shm_path,
channel->uid, channel->gid);
if (closeret) {
PERROR("unlink %s", shm_path);
}
}
PERROR("unlink %s", shm_path);
}
}
}
ret = run_as_unlink(shm_path, chan->uid, chan->gid);
if (ret) {
}
ret = run_as_unlink(shm_path, chan->uid, chan->gid);
if (ret) {
PERROR("unlink %s", shm_path);
}
}
PERROR("unlink %s", shm_path);
}
}
ret = unlink(path);
} else {
ret = run_as_unlink(path, uid, gid);
ret = unlink(path);
} else {
ret = run_as_unlink(path, uid, gid);
- if (ret < 0) {
- errno = -ret;
- ret = -1;
- }
}
if (ret < 0) {
goto error;
}
if (ret < 0) {
goto error;