From: David Goulet Date: Mon, 16 Jan 2012 17:15:18 +0000 (-0500) Subject: Fix runas namespace X-Git-Tag: v2.0-pre17~12 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=e11d277bc11aafd396faebe83734971c814214e7;p=lttng-tools.git Fix runas namespace Signed-off-by: David Goulet --- diff --git a/common/runas.c b/common/runas.c index 22bd2fe8f..8ec7dc6b3 100644 --- a/common/runas.c +++ b/common/runas.c @@ -34,7 +34,7 @@ #include "runas.h" -#define CHILD_STACK_SIZE 10485760 +#define RUNAS_CHILD_STACK_SIZE 10485760 struct run_as_data { int (*cmd)(void *data); @@ -44,12 +44,12 @@ struct run_as_data { int retval_pipe; }; -struct mkdir_data { +struct run_as_mkdir_data { const char *path; mode_t mode; }; -struct open_data { +struct run_as_open_data { const char *path; int flags; mode_t mode; @@ -61,7 +61,7 @@ struct open_data { static int _mkdir_recursive(void *_data) { - struct mkdir_data *data = _data; + struct run_as_mkdir_data *data = _data; const char *path; char *p, tmp[PATH_MAX]; struct stat statbuf; @@ -118,14 +118,14 @@ error: static int _mkdir(void *_data) { - struct mkdir_data *data = _data; + struct run_as_mkdir_data *data = _data; return mkdir(data->path, data->mode); } static int _open(void *_data) { - struct open_data *data = _data; + struct run_as_open_data *data = _data; return open(data->path, data->flags, data->mode); } @@ -218,7 +218,7 @@ int run_as(int (*cmd)(void *data), void *data, uid_t uid, gid_t gid) run_as_data.uid = uid; run_as_data.gid = gid; run_as_data.retval_pipe = retval_pipe[1]; /* write end */ - child_stack = mmap(NULL, CHILD_STACK_SIZE, + child_stack = mmap(NULL, RUNAS_CHILD_STACK_SIZE, PROT_WRITE | PROT_READ, MAP_PRIVATE | MAP_GROWSDOWN | MAP_ANONYMOUS | MAP_STACK, -1, 0); @@ -231,7 +231,7 @@ int run_as(int (*cmd)(void *data), void *data, uid_t uid, gid_t gid) * Pointing to the middle of the stack to support architectures * where the stack grows up (HPPA). */ - pid = clone(child_run_as, child_stack + (CHILD_STACK_SIZE / 2), + pid = clone(child_run_as, child_stack + (RUNAS_CHILD_STACK_SIZE / 2), CLONE_FILES | SIGCHLD, &run_as_data, NULL); if (pid < 0) { @@ -263,7 +263,7 @@ int run_as(int (*cmd)(void *data), void *data, uid_t uid, gid_t gid) ret = -1; } unmap_stack: - ret = munmap(child_stack, CHILD_STACK_SIZE); + ret = munmap(child_stack, RUNAS_CHILD_STACK_SIZE); if (ret < 0) { perror("munmap"); } @@ -274,9 +274,9 @@ end: return retval.i; } -int mkdir_recursive_run_as(const char *path, mode_t mode, uid_t uid, gid_t gid) +int run_as_mkdir_recursive(const char *path, mode_t mode, uid_t uid, gid_t gid) { - struct mkdir_data data; + struct run_as_mkdir_data data; DBG3("mkdir() recursive %s with mode %d for uid %d and gid %d", path, mode, uid, gid); @@ -285,9 +285,9 @@ int mkdir_recursive_run_as(const char *path, mode_t mode, uid_t uid, gid_t gid) return run_as(_mkdir_recursive, &data, uid, gid); } -int mkdir_run_as(const char *path, mode_t mode, uid_t uid, gid_t gid) +int run_as_mkdir(const char *path, mode_t mode, uid_t uid, gid_t gid) { - struct mkdir_data data; + struct run_as_mkdir_data data; DBG3("mkdir() %s with mode %d for uid %d and gid %d", path, mode, uid, gid); @@ -300,9 +300,9 @@ int mkdir_run_as(const char *path, mode_t mode, uid_t uid, gid_t gid) * Note: open_run_as is currently not working. We'd need to pass the fd * opened in the child to the parent. */ -int open_run_as(const char *path, int flags, mode_t mode, uid_t uid, gid_t gid) +int run_as_open(const char *path, int flags, mode_t mode, uid_t uid, gid_t gid) { - struct open_data data; + struct run_as_open_data data; DBG3("open() %s with flags %X mode %d for uid %d and gid %d", path, flags, mode, uid, gid); diff --git a/common/runas.h b/common/runas.h index 544653d65..c8c485c1f 100644 --- a/common/runas.h +++ b/common/runas.h @@ -22,8 +22,8 @@ #include -int mkdir_recursive_run_as(const char *path, mode_t mode, uid_t uid, gid_t gid); -int mkdir_run_as(const char *path, mode_t mode, uid_t uid, gid_t gid); -int open_run_as(const char *path, int flags, mode_t mode, uid_t uid, gid_t gid); +int run_as_mkdir_recursive(const char *path, mode_t mode, uid_t uid, gid_t gid); +int run_as_mkdir(const char *path, mode_t mode, uid_t uid, gid_t gid); +int run_as_open(const char *path, int flags, mode_t mode, uid_t uid, gid_t gid); #endif /* _RUNAS_H */ diff --git a/liblttng-kconsumer/lttng-kconsumer.c b/liblttng-kconsumer/lttng-kconsumer.c index 2b69438ca..488d6b859 100644 --- a/liblttng-kconsumer/lttng-kconsumer.c +++ b/liblttng-kconsumer/lttng-kconsumer.c @@ -397,7 +397,7 @@ int lttng_kconsumer_on_recv_stream(struct lttng_consumer_stream *stream) /* Opening the tracefile in write mode */ if (stream->path_name != NULL) { - ret = open_run_as(stream->path_name, + ret = run_as_open(stream->path_name, O_WRONLY|O_CREAT|O_TRUNC, S_IRWXU|S_IRWXG|S_IRWXO, stream->uid, stream->gid); diff --git a/liblttng-ustconsumer/lttng-ustconsumer.c b/liblttng-ustconsumer/lttng-ustconsumer.c index bc262572a..10213c1c9 100644 --- a/liblttng-ustconsumer/lttng-ustconsumer.c +++ b/liblttng-ustconsumer/lttng-ustconsumer.c @@ -395,7 +395,7 @@ int lttng_ustconsumer_on_recv_stream(struct lttng_consumer_stream *stream) /* Opening the tracefile in write mode */ if (stream->path_name != NULL) { - ret = open_run_as(stream->path_name, + ret = run_as_open(stream->path_name, O_WRONLY|O_CREAT|O_TRUNC, S_IRWXU|S_IRWXG|S_IRWXO, stream->uid, stream->gid); diff --git a/lttng-sessiond/main.c b/lttng-sessiond/main.c index 6f34bb722..a2532d047 100644 --- a/lttng-sessiond/main.c +++ b/lttng-sessiond/main.c @@ -1749,7 +1749,7 @@ static int mount_debugfs(char *path) int ret; char *type = "debugfs"; - ret = mkdir_recursive_run_as(path, S_IRWXU | S_IRWXG, geteuid(), getegid()); + ret = run_as_mkdir_recursive(path, S_IRWXU | S_IRWXG, geteuid(), getegid()); if (ret < 0) { PERROR("Cannot create debugfs path"); goto error; @@ -1904,7 +1904,7 @@ static int create_ust_session(struct ltt_session *session, goto error; } - ret = mkdir_recursive_run_as(lus->pathname, S_IRWXU | S_IRWXG, + ret = run_as_mkdir_recursive(lus->pathname, S_IRWXU | S_IRWXG, session->uid, session->gid); if (ret < 0) { if (ret != -EEXIST) { @@ -1954,7 +1954,7 @@ static int create_kernel_session(struct ltt_session *session) session->kernel_session->consumer_fd = kconsumer_data.cmd_sock; } - ret = mkdir_recursive_run_as(session->kernel_session->trace_path, + ret = run_as_mkdir_recursive(session->kernel_session->trace_path, S_IRWXU | S_IRWXG, session->uid, session->gid); if (ret < 0) { if (ret != -EEXIST) { diff --git a/lttng-sessiond/session.c b/lttng-sessiond/session.c index 050942cee..1a79fd564 100644 --- a/lttng-sessiond/session.c +++ b/lttng-sessiond/session.c @@ -217,7 +217,7 @@ int session_create(char *name, char *path, uid_t uid, gid_t gid) new_session->uid = uid; new_session->gid = gid; - ret = mkdir_recursive_run_as(new_session->path, S_IRWXU | S_IRWXG, + ret = run_as_mkdir_recursive(new_session->path, S_IRWXU | S_IRWXG, new_session->uid, new_session->gid); if (ret < 0) { if (ret != -EEXIST) { diff --git a/lttng-sessiond/ust-app.c b/lttng-sessiond/ust-app.c index 209a7fed4..a9c1c764c 100644 --- a/lttng-sessiond/ust-app.c +++ b/lttng-sessiond/ust-app.c @@ -1192,7 +1192,7 @@ static int create_ust_app_metadata(struct ust_app_session *ua_sess, goto error; } - ret = mkdir_run_as(ua_sess->path, S_IRWXU | S_IRWXG, + ret = run_as_mkdir(ua_sess->path, S_IRWXU | S_IRWXG, ua_sess->uid, ua_sess->gid); if (ret < 0) { PERROR("mkdir UST metadata");