Added a check in get online pids to only send the pids that are currently online.

Signed-off-by: Matthew Khouzam <[email protected]>
---
 libustctl/libustctl.c |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)

diff --git a/libustctl/libustctl.c b/libustctl/libustctl.c
index d57e645..3b5ae84 100644
--- a/libustctl/libustctl.c
+++ b/libustctl/libustctl.c
@@ -92,8 +92,11 @@ pid_t *ustctl_get_online_pids(void)
 {
     struct dirent *dirent;
     DIR *dir;
+    DIR *proc_dir;
+    char proc_dir_path[80]; /* proc+ / + int always smaller than 80*/
     unsigned int ret_size = 1 * sizeof(pid_t), i = 0;

+    printf( "%s\n" , SOCK_DIR) ;
     dir = opendir(SOCK_DIR);
     if (!dir) {
         return NULL;
@@ -117,7 +120,11 @@ pid_t *ustctl_get_online_pids(void)
              * We need to figure out an intelligent way of solving
              * this, maybe connect-disconnect.
              */
-            if (1) {
+             snprintf( proc_dir_path, 80, "/proc/%u/" , ret[i]) ;
+             proc_dir = opendir(proc_dir_path);
+             /* maybe we should remove the empty dir in this pass too*/
+             if( proc_dir != NULL )
+            {
                 ret_size += sizeof(pid_t);
                 ret = (pid_t *) realloc(ret, ret_size);
                 ++i;
--
1.7.0.4

>From a24266e7bdb116f36c0f4ac70634fcd32877ca6a Mon Sep 17 00:00:00 2001
From: Matthew Khouzam <[email protected]>
Date: Fri, 25 Mar 2011 17:40:01 -0400
Subject: [PATCH] Added a check in get online pids to only send the pids that are currently online.


Signed-off-by: Matthew Khouzam <[email protected]>
---
 libustctl/libustctl.c |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)

diff --git a/libustctl/libustctl.c b/libustctl/libustctl.c
index d57e645..3b5ae84 100644
--- a/libustctl/libustctl.c
+++ b/libustctl/libustctl.c
@@ -92,8 +92,11 @@ pid_t *ustctl_get_online_pids(void)
 {
 	struct dirent *dirent;
 	DIR *dir;
+	DIR *proc_dir;
+	char proc_dir_path[80]; /* proc+ / + int always smaller than 80*/
 	unsigned int ret_size = 1 * sizeof(pid_t), i = 0;
 
+	printf( "%s\n" , SOCK_DIR) ;
 	dir = opendir(SOCK_DIR);
 	if (!dir) {
 		return NULL;
@@ -117,7 +120,11 @@ pid_t *ustctl_get_online_pids(void)
 			 * We need to figure out an intelligent way of solving
 			 * this, maybe connect-disconnect.
 			 */
-			if (1) {
+			 snprintf( proc_dir_path, 80, "/proc/%u/" , ret[i]) ; 
+			 proc_dir = opendir(proc_dir_path);
+			 /* maybe we should remove the empty dir in this pass too*/
+			 if( proc_dir != NULL )
+			{
 				ret_size += sizeof(pid_t);
 				ret = (pid_t *) realloc(ret, ret_size);
 				++i;
-- 
1.7.0.4

_______________________________________________
ltt-dev mailing list
[email protected]
http://lists.casi.polymtl.ca/cgi-bin/mailman/listinfo/ltt-dev

Reply via email to