* [ltt-dev] [UST PATCH 1/6] Make app socket directories per-user v2
2011-04-01 7:32 [ltt-dev] [UST PATCH 1/6] Make app socket directories per-user v2 Nils Carlson
@ 2011-04-01 7:14 ` Nils Carlson
2011-04-01 7:32 ` [ltt-dev] [UST PATCH 2/6] Add mode setting to socket directory creation Nils Carlson
` (4 subsequent siblings)
5 siblings, 0 replies; 12+ messages in thread
From: Nils Carlson @ 2011-04-01 7:14 UTC (permalink / raw)
merged.
On 04/01/2011 09:32 AM, Nils Carlson wrote:
> Changes since v1:
> * Document memory allocation
>
> Make a separate app socket directories for each user, providing
> some basic security and also the possibility of consistent cleanup.
>
> Signed-off-by: Nils Carlson<nils.carlson at ericsson.com>
> ---
> libust/tracectl.c | 34 +++++++++++++++++++---------------
> libustcomm/ustcomm.c | 34 +++++++++++++++++++++++++++++-----
> libustcomm/ustcomm.h | 4 ++++
> 3 files changed, 52 insertions(+), 20 deletions(-)
>
> diff --git a/libust/tracectl.c b/libust/tracectl.c
> index 33c7280..ae92b7e 100644
> --- a/libust/tracectl.c
> +++ b/libust/tracectl.c
> @@ -1221,37 +1221,41 @@ static void auto_probe_connect(struct marker *m)
>
> static struct ustcomm_sock * init_app_socket(int epoll_fd)
> {
> - char *name;
> + char *dir_name, *sock_name;
> int result;
> - struct ustcomm_sock *sock;
> + struct ustcomm_sock *sock = NULL;
>
> - result = asprintf(&name, "%s/%d", SOCK_DIR, (int)getpid());
> + dir_name = ustcomm_user_sock_dir();
> + if (!dir_name)
> + return NULL;
> +
> + result = asprintf(&sock_name, "%s/%d", dir_name, (int)getpid());
> if (result< 0) {
> ERR("string overflow allocating socket name, "
> "UST thread bailing");
> - return NULL;
> + goto free_dir_name;
> }
>
> - result = ensure_dir_exists(SOCK_DIR);
> + result = ensure_dir_exists(dir_name);
> if (result == -1) {
> ERR("Unable to create socket directory %s, UST thread bailing",
> - SOCK_DIR);
> - goto free_name;
> + dir_name);
> + goto free_sock_name;
> }
>
> - sock = ustcomm_init_named_socket(name, epoll_fd);
> + sock = ustcomm_init_named_socket(sock_name, epoll_fd);
> if (!sock) {
> ERR("Error initializing named socket (%s). Check that directory"
> - "exists and that it is writable. UST thread bailing", name);
> - goto free_name;
> + "exists and that it is writable. UST thread bailing", sock_name);
> + goto free_sock_name;
> }
>
> - free(name);
> - return sock;
> +free_sock_name:
> + free(sock_name);
> +free_dir_name:
> + free(dir_name);
>
> -free_name:
> - free(name);
> - return NULL;
> + return sock;
> }
>
> static void __attribute__((constructor)) init()
> diff --git a/libustcomm/ustcomm.c b/libustcomm/ustcomm.c
> index 43f4289..dce1e52 100644
> --- a/libustcomm/ustcomm.c
> +++ b/libustcomm/ustcomm.c
> @@ -533,6 +533,21 @@ close_sock:
> return -1;
> }
>
> +/* Returns the current users socket directory, must be freed */
> +char *ustcomm_user_sock_dir(void)
> +{
> + int result;
> + char *sock_dir = NULL;
> +
> + result = asprintf(&sock_dir, "%s%s", USER_SOCK_DIR,
> + cuserid(NULL));
> + if (result< 0) {
> + ERR("string overflow allocating directory name");
> + return NULL;
> + }
> +
> + return sock_dir;
> +}
>
> /* Open a connection to a traceable app.
> *
> @@ -545,21 +560,30 @@ int ustcomm_connect_app(pid_t pid, int *app_fd)
> {
> int result;
> int retval = 0;
> - char *name;
> + char *dir_name, *sock_name;
> +
> + dir_name = ustcomm_user_sock_dir();
> + if (!dir_name)
> + return -ENOMEM;
>
> - result = asprintf(&name, "%s/%d", SOCK_DIR, pid);
> + result = asprintf(&sock_name, "%s/%d", dir_name, pid);
> if (result< 0) {
> ERR("failed to allocate socket name");
> - return -1;
> + retval = -1;
> + goto free_dir_name;
> }
>
> - result = ustcomm_connect_path(name, app_fd);
> + result = ustcomm_connect_path(sock_name, app_fd);
> if (result< 0) {
> ERR("failed to connect to app");
> retval = -1;
> + goto free_sock_name;
> }
>
> - free(name);
> +free_sock_name:
> + free(sock_name);
> +free_dir_name:
> + free(dir_name);
>
> return retval;
> }
> diff --git a/libustcomm/ustcomm.h b/libustcomm/ustcomm.h
> index 0ec04fc..db38119 100644
> --- a/libustcomm/ustcomm.h
> +++ b/libustcomm/ustcomm.h
> @@ -25,6 +25,7 @@
> #include<ust/kcompat/kcompat.h>
>
> #define SOCK_DIR "/tmp/ust-app-socks"
> +#define USER_SOCK_DIR "/tmp/ust-socks-"
>
> struct ustcomm_sock {
> struct cds_list_head list;
> @@ -156,6 +157,9 @@ extern int ustcomm_req(int sock,
> char *res_data);
>
> extern int ustcomm_request_consumer(pid_t pid, const char *channel);
> +
> +/* Returns the current users socket directory, must be freed */
> +extern char *ustcomm_user_sock_dir(void);
> extern int ustcomm_connect_app(pid_t pid, int *app_fd);
> extern int ustcomm_connect_path(const char *path, int *connection_fd);
>
^ permalink raw reply [flat|nested] 12+ messages in thread* [ltt-dev] [UST PATCH 2/6] Add mode setting to socket directory creation
2011-04-01 7:32 [ltt-dev] [UST PATCH 1/6] Make app socket directories per-user v2 Nils Carlson
2011-04-01 7:14 ` Nils Carlson
@ 2011-04-01 7:32 ` Nils Carlson
2011-04-01 7:15 ` Nils Carlson
2011-04-01 7:32 ` [ltt-dev] [UST PATCH 3/6] Restructure the ustctl_get_online_pids command v2 Nils Carlson
` (3 subsequent siblings)
5 siblings, 1 reply; 12+ messages in thread
From: Nils Carlson @ 2011-04-01 7:32 UTC (permalink / raw)
Set the mode when creating the personal socket directory,
this way all app sockets are private.
Signed-off-by: Nils Carlson <nils.carlson at ericsson.com>
---
libust/tracectl.c | 2 +-
libustcomm/ustcomm.c | 20 +++++++++++++-------
libustcomm/ustcomm.h | 2 +-
libustconsumer/libustconsumer.c | 2 +-
4 files changed, 16 insertions(+), 10 deletions(-)
diff --git a/libust/tracectl.c b/libust/tracectl.c
index ae92b7e..58b567f 100644
--- a/libust/tracectl.c
+++ b/libust/tracectl.c
@@ -1236,7 +1236,7 @@ static struct ustcomm_sock * init_app_socket(int epoll_fd)
goto free_dir_name;
}
- result = ensure_dir_exists(dir_name);
+ result = ensure_dir_exists(dir_name, S_IRWXU);
if (result == -1) {
ERR("Unable to create socket directory %s, UST thread bailing",
dir_name);
diff --git a/libustcomm/ustcomm.c b/libustcomm/ustcomm.c
index dce1e52..e401c42 100644
--- a/libustcomm/ustcomm.c
+++ b/libustcomm/ustcomm.c
@@ -588,28 +588,34 @@ free_dir_name:
return retval;
}
-int ensure_dir_exists(const char *dir)
+int ensure_dir_exists(const char *dir, mode_t mode)
{
struct stat st;
int result;
- if(!strcmp(dir, ""))
+ if (!strcmp(dir, ""))
return -1;
result = stat(dir, &st);
- if(result == -1 && errno != ENOENT) {
+ if (result < 0 && errno != ENOENT) {
return -1;
- }
- else if(result == -1) {
+ } else if (result < 0) {
/* ENOENT */
int result;
- /* mkdir mode to 0777 */
- result = mkdir_p(dir, S_IRWXU | S_IRWXG | S_IRWXO);
+ result = mkdir_p(dir, mode);
if(result != 0) {
ERR("executing in recursive creation of directory %s", dir);
return -1;
}
+ } else {
+ if (st.st_mode != mode) {
+ result = chmod(dir, mode);
+ if (result < 0) {
+ ERR("couldn't set directory mode on %s", dir);
+ return -1;
+ }
+ }
}
return 0;
diff --git a/libustcomm/ustcomm.h b/libustcomm/ustcomm.h
index db38119..d16aec7 100644
--- a/libustcomm/ustcomm.h
+++ b/libustcomm/ustcomm.h
@@ -119,7 +119,7 @@ struct ustcomm_notify_buf_mapped {
};
/* Ensure directory existence, usefull for unix sockets */
-extern int ensure_dir_exists(const char *dir);
+extern int ensure_dir_exists(const char *dir, mode_t mode);
/* Create and delete sockets */
extern struct ustcomm_sock * ustcomm_init_sock(int fd, int epoll_fd,
diff --git a/libustconsumer/libustconsumer.c b/libustconsumer/libustconsumer.c
index 8eb4424..eaee1fa 100644
--- a/libustconsumer/libustconsumer.c
+++ b/libustconsumer/libustconsumer.c
@@ -846,7 +846,7 @@ static int init_ustconsumer_socket(struct ustconsumer_instance *instance)
int result;
/* Only check if socket dir exists if we are using the default directory */
- result = ensure_dir_exists(SOCK_DIR);
+ result = ensure_dir_exists(SOCK_DIR, S_IRWXU | S_IRWXG | S_IRWXO);
if (result == -1) {
ERR("Unable to create socket directory %s", SOCK_DIR);
return -1;
--
1.7.1
^ permalink raw reply [flat|nested] 12+ messages in thread* [ltt-dev] [UST PATCH 2/6] Add mode setting to socket directory creation
2011-04-01 7:32 ` [ltt-dev] [UST PATCH 2/6] Add mode setting to socket directory creation Nils Carlson
@ 2011-04-01 7:15 ` Nils Carlson
0 siblings, 0 replies; 12+ messages in thread
From: Nils Carlson @ 2011-04-01 7:15 UTC (permalink / raw)
merged.
On 04/01/2011 09:32 AM, Nils Carlson wrote:
> Set the mode when creating the personal socket directory,
> this way all app sockets are private.
>
> Signed-off-by: Nils Carlson<nils.carlson at ericsson.com>
> ---
> libust/tracectl.c | 2 +-
> libustcomm/ustcomm.c | 20 +++++++++++++-------
> libustcomm/ustcomm.h | 2 +-
> libustconsumer/libustconsumer.c | 2 +-
> 4 files changed, 16 insertions(+), 10 deletions(-)
>
> diff --git a/libust/tracectl.c b/libust/tracectl.c
> index ae92b7e..58b567f 100644
> --- a/libust/tracectl.c
> +++ b/libust/tracectl.c
> @@ -1236,7 +1236,7 @@ static struct ustcomm_sock * init_app_socket(int epoll_fd)
> goto free_dir_name;
> }
>
> - result = ensure_dir_exists(dir_name);
> + result = ensure_dir_exists(dir_name, S_IRWXU);
> if (result == -1) {
> ERR("Unable to create socket directory %s, UST thread bailing",
> dir_name);
> diff --git a/libustcomm/ustcomm.c b/libustcomm/ustcomm.c
> index dce1e52..e401c42 100644
> --- a/libustcomm/ustcomm.c
> +++ b/libustcomm/ustcomm.c
> @@ -588,28 +588,34 @@ free_dir_name:
> return retval;
> }
>
> -int ensure_dir_exists(const char *dir)
> +int ensure_dir_exists(const char *dir, mode_t mode)
> {
> struct stat st;
> int result;
>
> - if(!strcmp(dir, ""))
> + if (!strcmp(dir, ""))
> return -1;
>
> result = stat(dir,&st);
> - if(result == -1&& errno != ENOENT) {
> + if (result< 0&& errno != ENOENT) {
> return -1;
> - }
> - else if(result == -1) {
> + } else if (result< 0) {
> /* ENOENT */
> int result;
>
> - /* mkdir mode to 0777 */
> - result = mkdir_p(dir, S_IRWXU | S_IRWXG | S_IRWXO);
> + result = mkdir_p(dir, mode);
> if(result != 0) {
> ERR("executing in recursive creation of directory %s", dir);
> return -1;
> }
> + } else {
> + if (st.st_mode != mode) {
> + result = chmod(dir, mode);
> + if (result< 0) {
> + ERR("couldn't set directory mode on %s", dir);
> + return -1;
> + }
> + }
> }
>
> return 0;
> diff --git a/libustcomm/ustcomm.h b/libustcomm/ustcomm.h
> index db38119..d16aec7 100644
> --- a/libustcomm/ustcomm.h
> +++ b/libustcomm/ustcomm.h
> @@ -119,7 +119,7 @@ struct ustcomm_notify_buf_mapped {
> };
>
> /* Ensure directory existence, usefull for unix sockets */
> -extern int ensure_dir_exists(const char *dir);
> +extern int ensure_dir_exists(const char *dir, mode_t mode);
>
> /* Create and delete sockets */
> extern struct ustcomm_sock * ustcomm_init_sock(int fd, int epoll_fd,
> diff --git a/libustconsumer/libustconsumer.c b/libustconsumer/libustconsumer.c
> index 8eb4424..eaee1fa 100644
> --- a/libustconsumer/libustconsumer.c
> +++ b/libustconsumer/libustconsumer.c
> @@ -846,7 +846,7 @@ static int init_ustconsumer_socket(struct ustconsumer_instance *instance)
> int result;
>
> /* Only check if socket dir exists if we are using the default directory */
> - result = ensure_dir_exists(SOCK_DIR);
> + result = ensure_dir_exists(SOCK_DIR, S_IRWXU | S_IRWXG | S_IRWXO);
> if (result == -1) {
> ERR("Unable to create socket directory %s", SOCK_DIR);
> return -1;
^ permalink raw reply [flat|nested] 12+ messages in thread
* [ltt-dev] [UST PATCH 3/6] Restructure the ustctl_get_online_pids command v2
2011-04-01 7:32 [ltt-dev] [UST PATCH 1/6] Make app socket directories per-user v2 Nils Carlson
2011-04-01 7:14 ` Nils Carlson
2011-04-01 7:32 ` [ltt-dev] [UST PATCH 2/6] Add mode setting to socket directory creation Nils Carlson
@ 2011-04-01 7:32 ` Nils Carlson
2011-04-01 7:15 ` Nils Carlson
2011-04-01 7:32 ` [ltt-dev] [UST PATCH 4/6] Add list-pids command to ustctl Nils Carlson
` (2 subsequent siblings)
5 siblings, 1 reply; 12+ messages in thread
From: Nils Carlson @ 2011-04-01 7:32 UTC (permalink / raw)
Changes since v1:
* Use list length, not the size in bytes
* Fix a possible bug for pid_t in a sscanf
* Use list length in the dir scanning function
Restructure the command to separate the pid gathering.
This will allow a root user to gather pid from multiple user
directories.
Signed-off-by: Nils Carlson <nils.carlson at ericsson.com>
---
libustctl/libustctl.c | 81 +++++++++++++++++++++++++++++++------------------
1 files changed, 51 insertions(+), 30 deletions(-)
diff --git a/libustctl/libustctl.c b/libustctl/libustctl.c
index d57e645..5625f43 100644
--- a/libustctl/libustctl.c
+++ b/libustctl/libustctl.c
@@ -88,53 +88,74 @@ int ustctl_connect_pid(pid_t pid)
return sock;
}
-pid_t *ustctl_get_online_pids(void)
+static void get_pids_in_dir(DIR *dir, pid_t **pid_list,
+ unsigned int *pid_list_size)
{
struct dirent *dirent;
- DIR *dir;
- unsigned int ret_size = 1 * sizeof(pid_t), i = 0;
-
- dir = opendir(SOCK_DIR);
- if (!dir) {
- return NULL;
- }
-
- pid_t *ret = (pid_t *) malloc(ret_size);
+ unsigned int read_pid;
while ((dirent = readdir(dir))) {
if (!strcmp(dirent->d_name, ".") ||
- !strcmp(dirent->d_name, "..")) {
+ !strcmp(dirent->d_name, "..") ||
+ !strcmp(dirent->d_name, "ust-consumer") ||
+ dirent->d_type == DT_DIR) {
continue;
}
- if (dirent->d_type != DT_DIR &&
- !!strcmp(dirent->d_name, "ust-consumer")) {
-
- sscanf(dirent->d_name, "%u", (unsigned int *) &ret[i]);
- /* FIXME: Here we previously called pid_is_online, which
- * always returned 1, now I replaced it with just 1.
- * We need to figure out an intelligent way of solving
- * this, maybe connect-disconnect.
- */
- if (1) {
- ret_size += sizeof(pid_t);
- ret = (pid_t *) realloc(ret, ret_size);
- ++i;
- }
+ sscanf(dirent->d_name, "%u", &read_pid);
+
+ (*pid_list)[*pid_list_size - 1] = read_pid;
+ /* FIXME: Here we previously called pid_is_online, which
+ * always returned 1, now I replaced it with just 1.
+ * We need to figure out an intelligent way of solving
+ * this, maybe connect-disconnect.
+ */
+ if (1) {
+ (*pid_list_size)++;
+ *pid_list = realloc(*pid_list,
+ *pid_list_size * sizeof(pid_t));
}
}
- ret[i] = 0; /* Array end */
+ (*pid_list)[*pid_list_size - 1] = 0; /* Array end */
+}
- if (ret[0] == 0) {
- /* No PID at all */
- free(ret);
+pid_t *ustctl_get_online_pids(void)
+{
+ char *dir_name;
+ DIR *dir;
+ unsigned int pid_list_size = 1;
+ pid_t *pid_list = NULL;
+
+ dir_name = ustcomm_user_sock_dir();
+ if (!dir_name) {
return NULL;
}
+ dir = opendir(dir_name);
+ if (!dir) {
+ goto free_dir_name;
+ }
+
+ pid_list = malloc(pid_list_size * sizeof(pid_t));
+
+ get_pids_in_dir(dir, &pid_list, &pid_list_size);
+
+ if (pid_list[0] == 0) {
+ /* No PID at all */
+ free(pid_list);
+ pid_list = NULL;
+ goto close_dir;
+ }
+
+close_dir:
closedir(dir);
- return ret;
+
+free_dir_name:
+ free(dir_name);
+
+ return pid_list;
}
/**
--
1.7.1
^ permalink raw reply [flat|nested] 12+ messages in thread* [ltt-dev] [UST PATCH 3/6] Restructure the ustctl_get_online_pids command v2
2011-04-01 7:32 ` [ltt-dev] [UST PATCH 3/6] Restructure the ustctl_get_online_pids command v2 Nils Carlson
@ 2011-04-01 7:15 ` Nils Carlson
0 siblings, 0 replies; 12+ messages in thread
From: Nils Carlson @ 2011-04-01 7:15 UTC (permalink / raw)
merged.
On 04/01/2011 09:32 AM, Nils Carlson wrote:
> Changes since v1:
> * Use list length, not the size in bytes
> * Fix a possible bug for pid_t in a sscanf
> * Use list length in the dir scanning function
>
> Restructure the command to separate the pid gathering.
> This will allow a root user to gather pid from multiple user
> directories.
>
> Signed-off-by: Nils Carlson<nils.carlson at ericsson.com>
> ---
> libustctl/libustctl.c | 81 +++++++++++++++++++++++++++++++------------------
> 1 files changed, 51 insertions(+), 30 deletions(-)
>
> diff --git a/libustctl/libustctl.c b/libustctl/libustctl.c
> index d57e645..5625f43 100644
> --- a/libustctl/libustctl.c
> +++ b/libustctl/libustctl.c
> @@ -88,53 +88,74 @@ int ustctl_connect_pid(pid_t pid)
> return sock;
> }
>
> -pid_t *ustctl_get_online_pids(void)
> +static void get_pids_in_dir(DIR *dir, pid_t **pid_list,
> + unsigned int *pid_list_size)
> {
> struct dirent *dirent;
> - DIR *dir;
> - unsigned int ret_size = 1 * sizeof(pid_t), i = 0;
> -
> - dir = opendir(SOCK_DIR);
> - if (!dir) {
> - return NULL;
> - }
> -
> - pid_t *ret = (pid_t *) malloc(ret_size);
> + unsigned int read_pid;
>
> while ((dirent = readdir(dir))) {
> if (!strcmp(dirent->d_name, ".") ||
> - !strcmp(dirent->d_name, "..")) {
> + !strcmp(dirent->d_name, "..") ||
> + !strcmp(dirent->d_name, "ust-consumer") ||
> + dirent->d_type == DT_DIR) {
>
> continue;
> }
>
> - if (dirent->d_type != DT_DIR&&
> - !!strcmp(dirent->d_name, "ust-consumer")) {
> -
> - sscanf(dirent->d_name, "%u", (unsigned int *)&ret[i]);
> - /* FIXME: Here we previously called pid_is_online, which
> - * always returned 1, now I replaced it with just 1.
> - * We need to figure out an intelligent way of solving
> - * this, maybe connect-disconnect.
> - */
> - if (1) {
> - ret_size += sizeof(pid_t);
> - ret = (pid_t *) realloc(ret, ret_size);
> - ++i;
> - }
> + sscanf(dirent->d_name, "%u",&read_pid);
> +
> + (*pid_list)[*pid_list_size - 1] = read_pid;
> + /* FIXME: Here we previously called pid_is_online, which
> + * always returned 1, now I replaced it with just 1.
> + * We need to figure out an intelligent way of solving
> + * this, maybe connect-disconnect.
> + */
> + if (1) {
> + (*pid_list_size)++;
> + *pid_list = realloc(*pid_list,
> + *pid_list_size * sizeof(pid_t));
> }
> }
>
> - ret[i] = 0; /* Array end */
> + (*pid_list)[*pid_list_size - 1] = 0; /* Array end */
> +}
>
> - if (ret[0] == 0) {
> - /* No PID at all */
> - free(ret);
> +pid_t *ustctl_get_online_pids(void)
> +{
> + char *dir_name;
> + DIR *dir;
> + unsigned int pid_list_size = 1;
> + pid_t *pid_list = NULL;
> +
> + dir_name = ustcomm_user_sock_dir();
> + if (!dir_name) {
> return NULL;
> }
>
> + dir = opendir(dir_name);
> + if (!dir) {
> + goto free_dir_name;
> + }
> +
> + pid_list = malloc(pid_list_size * sizeof(pid_t));
> +
> + get_pids_in_dir(dir,&pid_list,&pid_list_size);
> +
> + if (pid_list[0] == 0) {
> + /* No PID at all */
> + free(pid_list);
> + pid_list = NULL;
> + goto close_dir;
> + }
> +
> +close_dir:
> closedir(dir);
> - return ret;
> +
> +free_dir_name:
> + free(dir_name);
> +
> + return pid_list;
> }
>
> /**
^ permalink raw reply [flat|nested] 12+ messages in thread
* [ltt-dev] [UST PATCH 4/6] Add list-pids command to ustctl
2011-04-01 7:32 [ltt-dev] [UST PATCH 1/6] Make app socket directories per-user v2 Nils Carlson
` (2 preceding siblings ...)
2011-04-01 7:32 ` [ltt-dev] [UST PATCH 3/6] Restructure the ustctl_get_online_pids command v2 Nils Carlson
@ 2011-04-01 7:32 ` Nils Carlson
2011-04-01 7:16 ` Nils Carlson
2011-04-01 7:32 ` [ltt-dev] [UST PATCH 5/6] Make root see all available pids Nils Carlson
2011-04-01 7:32 ` [ltt-dev] [UST PATCH 6/6] Make root able to connect to any traceable app Nils Carlson
5 siblings, 1 reply; 12+ messages in thread
From: Nils Carlson @ 2011-04-01 7:32 UTC (permalink / raw)
Changes since v1:
* Case pid_t to long
Signed-off-by: Nils Carlson <nils.carlson at ericsson.com>
---
ustctl/ustctl.c | 28 ++++++++++++++++++++++++++++
1 files changed, 28 insertions(+), 0 deletions(-)
diff --git a/ustctl/ustctl.c b/ustctl/ustctl.c
index 807af8c..18f7d30 100644
--- a/ustctl/ustctl.c
+++ b/ustctl/ustctl.c
@@ -213,6 +213,25 @@ static int get_sock_path(int argc, char *argv[])
return 0;
}
+static int list_pids(int argc, char *argv[])
+{
+ pid_t *pid_list;
+ int i;
+
+ pid_list = ustctl_get_online_pids();
+ if (!pid_list) {
+ return -1;
+ }
+
+ for (i = 0; pid_list[i]; i++) {
+ printf("%ld\n", (long)pid_list[i]);
+ }
+
+ free(pid_list);
+
+ return 0;
+}
+
struct cli_cmd __cli_cmds general_cmds[] = {
{
.name = "list-trace-events",
@@ -241,4 +260,13 @@ struct cli_cmd __cli_cmds general_cmds[] = {
.desired_args = 1,
.desired_args_op = CLI_EQ,
},
+ {
+ .name = "list-pids",
+ .description = "List traceable pids",
+ .help_text = "list-pids\n"
+ "List the traceable pids for the current user\n",
+ .function = list_pids,
+ .desired_args = 0,
+ .desired_args_op = CLI_EQ,
+ },
};
--
1.7.1
^ permalink raw reply [flat|nested] 12+ messages in thread* [ltt-dev] [UST PATCH 4/6] Add list-pids command to ustctl
2011-04-01 7:32 ` [ltt-dev] [UST PATCH 4/6] Add list-pids command to ustctl Nils Carlson
@ 2011-04-01 7:16 ` Nils Carlson
0 siblings, 0 replies; 12+ messages in thread
From: Nils Carlson @ 2011-04-01 7:16 UTC (permalink / raw)
merged with v2 appended to patch name.
On 04/01/2011 09:32 AM, Nils Carlson wrote:
> Changes since v1:
> * Case pid_t to long
>
> Signed-off-by: Nils Carlson<nils.carlson at ericsson.com>
> ---
> ustctl/ustctl.c | 28 ++++++++++++++++++++++++++++
> 1 files changed, 28 insertions(+), 0 deletions(-)
>
> diff --git a/ustctl/ustctl.c b/ustctl/ustctl.c
> index 807af8c..18f7d30 100644
> --- a/ustctl/ustctl.c
> +++ b/ustctl/ustctl.c
> @@ -213,6 +213,25 @@ static int get_sock_path(int argc, char *argv[])
> return 0;
> }
>
> +static int list_pids(int argc, char *argv[])
> +{
> + pid_t *pid_list;
> + int i;
> +
> + pid_list = ustctl_get_online_pids();
> + if (!pid_list) {
> + return -1;
> + }
> +
> + for (i = 0; pid_list[i]; i++) {
> + printf("%ld\n", (long)pid_list[i]);
> + }
> +
> + free(pid_list);
> +
> + return 0;
> +}
> +
> struct cli_cmd __cli_cmds general_cmds[] = {
> {
> .name = "list-trace-events",
> @@ -241,4 +260,13 @@ struct cli_cmd __cli_cmds general_cmds[] = {
> .desired_args = 1,
> .desired_args_op = CLI_EQ,
> },
> + {
> + .name = "list-pids",
> + .description = "List traceable pids",
> + .help_text = "list-pids\n"
> + "List the traceable pids for the current user\n",
> + .function = list_pids,
> + .desired_args = 0,
> + .desired_args_op = CLI_EQ,
> + },
> };
^ permalink raw reply [flat|nested] 12+ messages in thread
* [ltt-dev] [UST PATCH 5/6] Make root see all available pids
2011-04-01 7:32 [ltt-dev] [UST PATCH 1/6] Make app socket directories per-user v2 Nils Carlson
` (3 preceding siblings ...)
2011-04-01 7:32 ` [ltt-dev] [UST PATCH 4/6] Add list-pids command to ustctl Nils Carlson
@ 2011-04-01 7:32 ` Nils Carlson
2011-04-01 7:17 ` Nils Carlson
2011-04-01 7:32 ` [ltt-dev] [UST PATCH 6/6] Make root able to connect to any traceable app Nils Carlson
5 siblings, 1 reply; 12+ messages in thread
From: Nils Carlson @ 2011-04-01 7:32 UTC (permalink / raw)
Changes since v1:
* Fix a whitespace
* Make functions that should be static static
Allow root (geteuid() == 0) to see all pids. This way the super-user
can connect to any program. A step on the way of carefully outlining
what UST does and doesn't.
Signed-off-by: Nils Carlson <nils.carlson at ericsson.com>
---
libustcomm/ustcomm.h | 4 ++-
libustctl/libustctl.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 63 insertions(+), 2 deletions(-)
diff --git a/libustcomm/ustcomm.h b/libustcomm/ustcomm.h
index d16aec7..9952958 100644
--- a/libustcomm/ustcomm.h
+++ b/libustcomm/ustcomm.h
@@ -25,7 +25,9 @@
#include <ust/kcompat/kcompat.h>
#define SOCK_DIR "/tmp/ust-app-socks"
-#define USER_SOCK_DIR "/tmp/ust-socks-"
+#define USER_TMP_DIR "/tmp"
+#define USER_SOCK_DIR_BASE "ust-socks-"
+#define USER_SOCK_DIR USER_TMP_DIR "/" USER_SOCK_DIR_BASE
struct ustcomm_sock {
struct cds_list_head list;
diff --git a/libustctl/libustctl.c b/libustctl/libustctl.c
index 5625f43..356d5ef 100644
--- a/libustctl/libustctl.c
+++ b/libustctl/libustctl.c
@@ -121,7 +121,7 @@ static void get_pids_in_dir(DIR *dir, pid_t **pid_list,
(*pid_list)[*pid_list_size - 1] = 0; /* Array end */
}
-pid_t *ustctl_get_online_pids(void)
+static pid_t *get_pids_non_root(void)
{
char *dir_name;
DIR *dir;
@@ -139,6 +139,9 @@ pid_t *ustctl_get_online_pids(void)
}
pid_list = malloc(pid_list_size * sizeof(pid_t));
+ if (!pid_list) {
+ goto close_dir;
+ }
get_pids_in_dir(dir, &pid_list, &pid_list_size);
@@ -158,6 +161,62 @@ free_dir_name:
return pid_list;
}
+static pid_t *get_pids_root(void)
+{
+ char *dir_name;
+ DIR *tmp_dir, *dir;
+ unsigned int pid_list_size = 1;
+ pid_t *pid_list = NULL;
+ struct dirent *dirent;
+
+ tmp_dir = opendir(USER_TMP_DIR);
+ if (!tmp_dir) {
+ return NULL;
+ }
+
+ pid_list = malloc(pid_list_size * sizeof(pid_t));
+ if (!pid_list) {
+ goto close_tmp_dir;
+ }
+
+ while ((dirent = readdir(tmp_dir))) {
+ /* Compare the dir to check for the USER_SOCK_DIR_BASE prefix */
+ if (!strncmp(dirent->d_name, USER_SOCK_DIR_BASE,
+ strlen(USER_SOCK_DIR_BASE))) {
+
+ if (asprintf(&dir_name, USER_TMP_DIR "/%s", dirent->d_name) < 0) {
+ goto close_tmp_dir;
+ }
+
+ dir = opendir(dir_name);
+
+ free(dir_name);
+
+ if (!dir) {
+ continue;
+ }
+
+ get_pids_in_dir(dir, &pid_list, &pid_list_size);
+
+ closedir(dir);
+ }
+ }
+
+close_tmp_dir:
+ closedir(tmp_dir);
+
+ return pid_list;
+}
+
+pid_t *ustctl_get_online_pids(void)
+{
+ if (geteuid()) {
+ return get_pids_non_root();
+ } else {
+ return get_pids_root();
+ }
+}
+
/**
* Sets marker state (USTCTL_MS_ON or USTCTL_MS_OFF).
*
--
1.7.1
^ permalink raw reply [flat|nested] 12+ messages in thread* [ltt-dev] [UST PATCH 5/6] Make root see all available pids
2011-04-01 7:32 ` [ltt-dev] [UST PATCH 5/6] Make root see all available pids Nils Carlson
@ 2011-04-01 7:17 ` Nils Carlson
0 siblings, 0 replies; 12+ messages in thread
From: Nils Carlson @ 2011-04-01 7:17 UTC (permalink / raw)
merged with v2 appended to patch name.
On 04/01/2011 09:32 AM, Nils Carlson wrote:
> Changes since v1:
> * Fix a whitespace
> * Make functions that should be static static
>
> Allow root (geteuid() == 0) to see all pids. This way the super-user
> can connect to any program. A step on the way of carefully outlining
> what UST does and doesn't.
>
> Signed-off-by: Nils Carlson<nils.carlson at ericsson.com>
> ---
> libustcomm/ustcomm.h | 4 ++-
> libustctl/libustctl.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++-
> 2 files changed, 63 insertions(+), 2 deletions(-)
>
> diff --git a/libustcomm/ustcomm.h b/libustcomm/ustcomm.h
> index d16aec7..9952958 100644
> --- a/libustcomm/ustcomm.h
> +++ b/libustcomm/ustcomm.h
> @@ -25,7 +25,9 @@
> #include<ust/kcompat/kcompat.h>
>
> #define SOCK_DIR "/tmp/ust-app-socks"
> -#define USER_SOCK_DIR "/tmp/ust-socks-"
> +#define USER_TMP_DIR "/tmp"
> +#define USER_SOCK_DIR_BASE "ust-socks-"
> +#define USER_SOCK_DIR USER_TMP_DIR "/" USER_SOCK_DIR_BASE
>
> struct ustcomm_sock {
> struct cds_list_head list;
> diff --git a/libustctl/libustctl.c b/libustctl/libustctl.c
> index 5625f43..356d5ef 100644
> --- a/libustctl/libustctl.c
> +++ b/libustctl/libustctl.c
> @@ -121,7 +121,7 @@ static void get_pids_in_dir(DIR *dir, pid_t **pid_list,
> (*pid_list)[*pid_list_size - 1] = 0; /* Array end */
> }
>
> -pid_t *ustctl_get_online_pids(void)
> +static pid_t *get_pids_non_root(void)
> {
> char *dir_name;
> DIR *dir;
> @@ -139,6 +139,9 @@ pid_t *ustctl_get_online_pids(void)
> }
>
> pid_list = malloc(pid_list_size * sizeof(pid_t));
> + if (!pid_list) {
> + goto close_dir;
> + }
>
> get_pids_in_dir(dir,&pid_list,&pid_list_size);
>
> @@ -158,6 +161,62 @@ free_dir_name:
> return pid_list;
> }
>
> +static pid_t *get_pids_root(void)
> +{
> + char *dir_name;
> + DIR *tmp_dir, *dir;
> + unsigned int pid_list_size = 1;
> + pid_t *pid_list = NULL;
> + struct dirent *dirent;
> +
> + tmp_dir = opendir(USER_TMP_DIR);
> + if (!tmp_dir) {
> + return NULL;
> + }
> +
> + pid_list = malloc(pid_list_size * sizeof(pid_t));
> + if (!pid_list) {
> + goto close_tmp_dir;
> + }
> +
> + while ((dirent = readdir(tmp_dir))) {
> + /* Compare the dir to check for the USER_SOCK_DIR_BASE prefix */
> + if (!strncmp(dirent->d_name, USER_SOCK_DIR_BASE,
> + strlen(USER_SOCK_DIR_BASE))) {
> +
> + if (asprintf(&dir_name, USER_TMP_DIR "/%s", dirent->d_name)< 0) {
> + goto close_tmp_dir;
> + }
> +
> + dir = opendir(dir_name);
> +
> + free(dir_name);
> +
> + if (!dir) {
> + continue;
> + }
> +
> + get_pids_in_dir(dir,&pid_list,&pid_list_size);
> +
> + closedir(dir);
> + }
> + }
> +
> +close_tmp_dir:
> + closedir(tmp_dir);
> +
> + return pid_list;
> +}
> +
> +pid_t *ustctl_get_online_pids(void)
> +{
> + if (geteuid()) {
> + return get_pids_non_root();
> + } else {
> + return get_pids_root();
> + }
> +}
> +
> /**
> * Sets marker state (USTCTL_MS_ON or USTCTL_MS_OFF).
> *
^ permalink raw reply [flat|nested] 12+ messages in thread
* [ltt-dev] [UST PATCH 6/6] Make root able to connect to any traceable app
2011-04-01 7:32 [ltt-dev] [UST PATCH 1/6] Make app socket directories per-user v2 Nils Carlson
` (4 preceding siblings ...)
2011-04-01 7:32 ` [ltt-dev] [UST PATCH 5/6] Make root see all available pids Nils Carlson
@ 2011-04-01 7:32 ` Nils Carlson
2011-04-01 7:17 ` Nils Carlson
5 siblings, 1 reply; 12+ messages in thread
From: Nils Carlson @ 2011-04-01 7:32 UTC (permalink / raw)
Make root able to connect to any traceable app, checking
(geteuid == 0).
Signed-off-by: Nils Carlson <nils.carlson at ericsson.com>
---
libustcomm/ustcomm.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 53 insertions(+), 1 deletions(-)
diff --git a/libustcomm/ustcomm.c b/libustcomm/ustcomm.c
index e401c42..dcf8cd8 100644
--- a/libustcomm/ustcomm.c
+++ b/libustcomm/ustcomm.c
@@ -18,6 +18,7 @@
/* API used by UST components to communicate with each other via sockets. */
#define _GNU_SOURCE
+#include <dirent.h>
#include <sys/types.h>
#include <signal.h>
#include <errno.h>
@@ -556,7 +557,7 @@ char *ustcomm_user_sock_dir(void)
* -1: error
*/
-int ustcomm_connect_app(pid_t pid, int *app_fd)
+static int connect_app_non_root(pid_t pid, int *app_fd)
{
int result;
int retval = 0;
@@ -588,6 +589,57 @@ free_dir_name:
return retval;
}
+
+
+static int connect_app_root(pid_t pid, int *app_fd)
+{
+ DIR *tmp_dir;
+ struct dirent *dirent;
+ char *sock_name;
+ int result;
+
+ tmp_dir = opendir(USER_TMP_DIR);
+ if (!tmp_dir) {
+ return -1;
+ }
+
+ while ((dirent = readdir(tmp_dir))) {
+ if (!strncmp(dirent->d_name, USER_SOCK_DIR_BASE,
+ strlen(USER_SOCK_DIR_BASE))) {
+
+ if (asprintf(&sock_name, USER_TMP_DIR "/%s/%u",
+ dirent->d_name, pid) < 0) {
+ goto close_tmp_dir;
+ }
+
+ result = ustcomm_connect_path(sock_name, app_fd);
+
+ free(sock_name);
+
+ if (result == 0) {
+ goto close_tmp_dir;
+ }
+ }
+ }
+
+close_tmp_dir:
+ closedir(tmp_dir);
+
+ return result;
+}
+
+int ustcomm_connect_app(pid_t pid, int *app_fd)
+{
+ *app_fd = 0;
+
+ if (geteuid()) {
+ return connect_app_non_root(pid, app_fd);
+ } else {
+ return connect_app_root(pid, app_fd);
+ }
+
+}
+
int ensure_dir_exists(const char *dir, mode_t mode)
{
struct stat st;
--
1.7.1
^ permalink raw reply [flat|nested] 12+ messages in thread* [ltt-dev] [UST PATCH 6/6] Make root able to connect to any traceable app
2011-04-01 7:32 ` [ltt-dev] [UST PATCH 6/6] Make root able to connect to any traceable app Nils Carlson
@ 2011-04-01 7:17 ` Nils Carlson
0 siblings, 0 replies; 12+ messages in thread
From: Nils Carlson @ 2011-04-01 7:17 UTC (permalink / raw)
merged.
On 04/01/2011 09:32 AM, Nils Carlson wrote:
> Make root able to connect to any traceable app, checking
> (geteuid == 0).
>
> Signed-off-by: Nils Carlson<nils.carlson at ericsson.com>
> ---
> libustcomm/ustcomm.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++-
> 1 files changed, 53 insertions(+), 1 deletions(-)
>
> diff --git a/libustcomm/ustcomm.c b/libustcomm/ustcomm.c
> index e401c42..dcf8cd8 100644
> --- a/libustcomm/ustcomm.c
> +++ b/libustcomm/ustcomm.c
> @@ -18,6 +18,7 @@
> /* API used by UST components to communicate with each other via sockets. */
>
> #define _GNU_SOURCE
> +#include<dirent.h>
> #include<sys/types.h>
> #include<signal.h>
> #include<errno.h>
> @@ -556,7 +557,7 @@ char *ustcomm_user_sock_dir(void)
> * -1: error
> */
>
> -int ustcomm_connect_app(pid_t pid, int *app_fd)
> +static int connect_app_non_root(pid_t pid, int *app_fd)
> {
> int result;
> int retval = 0;
> @@ -588,6 +589,57 @@ free_dir_name:
> return retval;
> }
>
> +
> +
> +static int connect_app_root(pid_t pid, int *app_fd)
> +{
> + DIR *tmp_dir;
> + struct dirent *dirent;
> + char *sock_name;
> + int result;
> +
> + tmp_dir = opendir(USER_TMP_DIR);
> + if (!tmp_dir) {
> + return -1;
> + }
> +
> + while ((dirent = readdir(tmp_dir))) {
> + if (!strncmp(dirent->d_name, USER_SOCK_DIR_BASE,
> + strlen(USER_SOCK_DIR_BASE))) {
> +
> + if (asprintf(&sock_name, USER_TMP_DIR "/%s/%u",
> + dirent->d_name, pid)< 0) {
> + goto close_tmp_dir;
> + }
> +
> + result = ustcomm_connect_path(sock_name, app_fd);
> +
> + free(sock_name);
> +
> + if (result == 0) {
> + goto close_tmp_dir;
> + }
> + }
> + }
> +
> +close_tmp_dir:
> + closedir(tmp_dir);
> +
> + return result;
> +}
> +
> +int ustcomm_connect_app(pid_t pid, int *app_fd)
> +{
> + *app_fd = 0;
> +
> + if (geteuid()) {
> + return connect_app_non_root(pid, app_fd);
> + } else {
> + return connect_app_root(pid, app_fd);
> + }
> +
> +}
> +
> int ensure_dir_exists(const char *dir, mode_t mode)
> {
> struct stat st;
^ permalink raw reply [flat|nested] 12+ messages in thread