Mirror of the lttng-dev mailing list
 help / color / mirror / Atom feed
* [ltt-dev] [PATCH] Only send the pids that are currently online in ustctl_get_online_pids().
@ 2011-04-01 20:23 Matthew Khouzam
  2011-04-01 20:26 ` Mathieu Desnoyers
  0 siblings, 1 reply; 4+ messages in thread
From: Matthew Khouzam @ 2011-04-01 20:23 UTC (permalink / raw)


Signed-off-by: Matthew Khouzam <matthew.khouzam at ericsson.com>
---
 libustctl/libustctl.c |   20 +++++++++++++++++++-
 1 files changed, 19 insertions(+), 1 deletions(-)

diff --git a/libustctl/libustctl.c b/libustctl/libustctl.c
index d57e645..b5a214b 100644
--- a/libustctl/libustctl.c
+++ b/libustctl/libustctl.c
@@ -92,6 +92,8 @@ pid_t *ustctl_get_online_pids(void)
 {
 	struct dirent *dirent;
 	DIR *dir;
+	DIR *proc_dir;
+	char proc_dir_path[PATH_MAX];
 	unsigned int ret_size = 1 * sizeof(pid_t), i = 0;
 
 	dir = opendir(SOCK_DIR);
@@ -117,11 +119,27 @@ 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, PATH_MAX, "/proc/%u/", ret[i]);
+			 proc_dir = opendir(proc_dir_path);
+			 /*
+			  * Note:
+			  * We should not remove the empty dir in this pass.
+			  * A process can die, a new process can be born and
+			  * assigned to that PID. the only way to avoid this
+			  * would be to de-register and register centrally.
+			  * Ltt-sessiond would be a good candidate for such a
+			  * location.
+			  */
+			 if (proc_dir) {
+				/* We only needed to check if it's valid
+	 			 * so we close it here
+				 */
+				closedir(proc_dir);
 				ret_size += sizeof(pid_t);
 				ret = (pid_t *) realloc(ret, ret_size);
 				++i;
 			}
+			
 		}
 	}
 
-- 
1.7.0.4




^ permalink raw reply	[flat|nested] 4+ messages in thread

* [ltt-dev] [PATCH] Only send the pids that are currently online in ustctl_get_online_pids().
  2011-04-01 20:23 [ltt-dev] [PATCH] Only send the pids that are currently online in ustctl_get_online_pids() Matthew Khouzam
@ 2011-04-01 20:26 ` Mathieu Desnoyers
  0 siblings, 0 replies; 4+ messages in thread
From: Mathieu Desnoyers @ 2011-04-01 20:26 UTC (permalink / raw)


* Matthew Khouzam (matthew.khouzam at gmail.com) wrote:
> Signed-off-by: Matthew Khouzam <matthew.khouzam at ericsson.com>
> ---
>  libustctl/libustctl.c |   20 +++++++++++++++++++-
>  1 files changed, 19 insertions(+), 1 deletions(-)
> 
> diff --git a/libustctl/libustctl.c b/libustctl/libustctl.c
> index d57e645..b5a214b 100644
> --- a/libustctl/libustctl.c
> +++ b/libustctl/libustctl.c
> @@ -92,6 +92,8 @@ pid_t *ustctl_get_online_pids(void)
>  {
>  	struct dirent *dirent;
>  	DIR *dir;
> +	DIR *proc_dir;
> +	char proc_dir_path[PATH_MAX];
>  	unsigned int ret_size = 1 * sizeof(pid_t), i = 0;
>  
>  	dir = opendir(SOCK_DIR);
> @@ -117,11 +119,27 @@ 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, PATH_MAX, "/proc/%u/", ret[i]);
> +			 proc_dir = opendir(proc_dir_path);
> +			 /*
> +			  * Note:
> +			  * We should not remove the empty dir in this pass.
> +			  * A process can die, a new process can be born and
> +			  * assigned to that PID. the only way to avoid this
> +			  * would be to de-register and register centrally.
> +			  * Ltt-sessiond would be a good candidate for such a
> +			  * location.
> +			  */
> +			 if (proc_dir) {
> +				/* We only needed to check if it's valid
> +	 			 * so we close it here
> +				 */
> +				closedir(proc_dir);
>  				ret_size += sizeof(pid_t);
>  				ret = (pid_t *) realloc(ret, ret_size);
>  				++i;
>  			}
> +	

Added whiteline and tab. Please fix (and double-check with checkpatch).

Thanks,

Mathieu
		
>  		}
>  	}
>  
> -- 
> 1.7.0.4
> 
> 
> _______________________________________________
> ltt-dev mailing list
> ltt-dev at lists.casi.polymtl.ca
> http://lists.casi.polymtl.ca/cgi-bin/mailman/listinfo/ltt-dev
> 

-- 
Mathieu Desnoyers
Operating System Efficiency R&D Consultant
EfficiOS Inc.
http://www.efficios.com




^ permalink raw reply	[flat|nested] 4+ messages in thread

* [ltt-dev] [PATCH] Only send the pids that are currently online in ustctl_get_online_pids().
  2011-04-01 15:10 Matthew Khouzam
@ 2011-04-01 15:34 ` Mathieu Desnoyers
  0 siblings, 0 replies; 4+ messages in thread
From: Mathieu Desnoyers @ 2011-04-01 15:34 UTC (permalink / raw)


* Matthew Khouzam (matthew.khouzam at gmail.com) wrote:
> Signed-off-by: Matthew Khouzam <matthew.khouzam at ericsson.com>
> ---
>  libustctl/libustctl.c |   16 +++++++++++++++-
>  1 files changed, 15 insertions(+), 1 deletions(-)
> 
> diff --git a/libustctl/libustctl.c b/libustctl/libustctl.c
> index d57e645..a456b41 100644
> --- a/libustctl/libustctl.c
> +++ b/libustctl/libustctl.c
> @@ -92,6 +92,8 @@ pid_t *ustctl_get_online_pids(void)
>  {
>  	struct dirent *dirent;
>  	DIR *dir;
> +	DIR *proc_dir;
> +	char proc_dir_path[PATH_MAX];
>  	unsigned int ret_size = 1 * sizeof(pid_t), i = 0;
>  
>  	dir = opendir(SOCK_DIR);
> @@ -117,11 +119,23 @@ 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, PATH_MAX, "/proc/%u/", ret[i]);
> +			 proc_dir = opendir(proc_dir_path);
> +			 /*
> +			  * Note:
> +			  * We should not remove the empty dir in this pass.
> +			  * A process can die, a new process can be born and
> +			  * assigned to that PID. the only way to avoid this
> +			  * would be to de-register and register centrally.
> +			  * Ltt-sessiond would be a good candidate for such a
> +			  * location.
> +			  */
> +			 if (proc_dir) {
>  				ret_size += sizeof(pid_t);
>  				ret = (pid_t *) realloc(ret, ret_size);
>  				++i;
>  			}

if  (proc_dir} {
   ...
   closedir(proc_dir);
}

The man page does not state that it is valid to call closedir on a NULL
parameter.

Thanks,

Mathieu
 

> +			closedir(proc_dir);
>  		}
>  	}
>  
> -- 
> 1.7.0.4
> 
> 
> _______________________________________________
> ltt-dev mailing list
> ltt-dev at lists.casi.polymtl.ca
> http://lists.casi.polymtl.ca/cgi-bin/mailman/listinfo/ltt-dev
> 

-- 
Mathieu Desnoyers
Operating System Efficiency R&D Consultant
EfficiOS Inc.
http://www.efficios.com




^ permalink raw reply	[flat|nested] 4+ messages in thread

* [ltt-dev] [PATCH] Only send the pids that are currently online in ustctl_get_online_pids().
@ 2011-04-01 15:10 Matthew Khouzam
  2011-04-01 15:34 ` Mathieu Desnoyers
  0 siblings, 1 reply; 4+ messages in thread
From: Matthew Khouzam @ 2011-04-01 15:10 UTC (permalink / raw)


Signed-off-by: Matthew Khouzam <matthew.khouzam at ericsson.com>
---
 libustctl/libustctl.c |   16 +++++++++++++++-
 1 files changed, 15 insertions(+), 1 deletions(-)

diff --git a/libustctl/libustctl.c b/libustctl/libustctl.c
index d57e645..a456b41 100644
--- a/libustctl/libustctl.c
+++ b/libustctl/libustctl.c
@@ -92,6 +92,8 @@ pid_t *ustctl_get_online_pids(void)
 {
 	struct dirent *dirent;
 	DIR *dir;
+	DIR *proc_dir;
+	char proc_dir_path[PATH_MAX];
 	unsigned int ret_size = 1 * sizeof(pid_t), i = 0;
 
 	dir = opendir(SOCK_DIR);
@@ -117,11 +119,23 @@ 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, PATH_MAX, "/proc/%u/", ret[i]);
+			 proc_dir = opendir(proc_dir_path);
+			 /*
+			  * Note:
+			  * We should not remove the empty dir in this pass.
+			  * A process can die, a new process can be born and
+			  * assigned to that PID. the only way to avoid this
+			  * would be to de-register and register centrally.
+			  * Ltt-sessiond would be a good candidate for such a
+			  * location.
+			  */
+			 if (proc_dir) {
 				ret_size += sizeof(pid_t);
 				ret = (pid_t *) realloc(ret, ret_size);
 				++i;
 			}
+			closedir(proc_dir);
 		}
 	}
 
-- 
1.7.0.4




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-04-01 20:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-04-01 20:23 [ltt-dev] [PATCH] Only send the pids that are currently online in ustctl_get_online_pids() Matthew Khouzam
2011-04-01 20:26 ` Mathieu Desnoyers
  -- strict thread matches above, loose matches on Subject: below --
2011-04-01 15:10 Matthew Khouzam
2011-04-01 15:34 ` Mathieu Desnoyers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox