Fix: destroy session removes the default config file
A message that is not in the archive (sent off-list or not yet received): [email protected]
Hi Partha,
First, thanks for the patch! Unfortunately, there are a couple of issues with this fix. Read on.
Quoted 21 lines · Partha Pratim Mukherjee
Destroy session command by default removes the default config file without checking the current session. As a result when we call any other command which expects a default session by calling
get_session_name()function, it fails.This patch will fix this by checking that the default config file gets removed only when destroy session is called with the current session.
Fixes #887Signed-off-by Partha Pratim Mukherjee <[email protected]>--- src/bin/lttng/commands/destroy.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)src/bin/lttng/commands/destroy.c +0
-0
src/bin/lttng/commands/destroy.c static int destroy_session(struct lttng_session *session) · line 94
Quoted 6 lines
src/bin/lttng/commands/destroy.c +1
-1@@ -90,7 +90,9 @@ static int destroy_session(struct lttng_session *session) }MSG ("Session %s destroyed" , session->name); -config_destroy_default (); +if (strncmp (session->name,get_session_name (),NAME_MAX ) ==0 ) {
This will leak the string returned by get_session_name().
Moreover, config_read_session_name(), which is called by get_session_name() will spam the error logs anytime an .lttngrc file can't be found; the error logging statement should be moved out to the different callers.
Looking forward to a v2!
Jérémie
Quoted 14 lines
src/bin/lttng/commands/destroy.c +2
-0+config_destroy_default (); + }if (lttng_opt_mi) {ret = mi_lttng_session(writer, session, 0);--
1.7.10.4_______________________________________________
lttng-dev mailing list
[email protected]
http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
Signature · 3 lines
Jérémie Galarneau EfficiOS Inc. http://www.efficios.com
_______________________________________________
lttng-dev mailing list
[email protected]
http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
A message that is not in the archive (sent off-list or not yet received): CA+jJMxsMHrN7D7XhAte8jSn9=yd2+aSvJM9e5jNexTYaexXcLg@mail.gmail.com
A message that is not in the archive (sent off-list or not yet received): [email protected]
Hi Partha,
CC-ing lttng-dev and inlining your patch to ease the review... Read on.
Review
Quoted 1 line
(quoted diff) +0
-0
b/src/bin/lttng/commands/destroy.c
src/bin/lttng/commands/destroy.c static int destroy_session(struct lttng_session
Quoted 12 lines
index 95343c9..2d1200f 100644
src/bin/lttng/commands/destroy.c +1
-0@@ -75,6 +75,7 @@ static void usage(FILE *ofp)static int destroy_session (struct lttng_session *session) {int ret; +char *session_name =NULL ; ret =lttng_destroy_session (session->name);if (ret <0 ) {@@ -90,7 +91,18 @@ static int destroy_session(struct lttng_session
*session)
src/bin/lttng/commands/destroy.c static int destroy_session(struct lttng_session · line 100
Quoted 11 lines
src/bin/lttng/commands/destroy.c +7
-1}MSG ("Session %s destroyed" , session->name); -config_destroy_default (); + + session_name =get_session_name (); +if (session_name ==NULL ) { + ret =CMD_ERROR ; + goto error; + } +
This may not be an error.get_session_name() will return NULL whenever a default session is not defined. This will happen, for instance, when loading a session configuration.
The test_load script, under lttng-tools/tests/regression/tools/save-load will perform:
$ lttng load -i load-42.lttng $ lttng destroy load-42 Session load-42 destroyed Error: Can't find valid lttng config /home/jgalar/.lttngrc Did you create a session? (lttng create <my_session>) Error: Command error
(make sure you delete ~/.lttngrc beforehand to test this properly)
src/bin/lttng/commands/destroy.c static int destroy_session(struct lttng_session · line 104
Quoted 4 lines
src/bin/lttng/commands/destroy.c +4
-0+if (strncmp (session->name, session_name,NAME_MAX ) ==0 ) { +config_destroy_default (); + } +
We should skip this check if get_session_name() returned NULL with something like:
if (session_name && strncmp(session->name, session_name, NAME_MAX) == 0) {
...
Quoted 22 lines
src/bin/lttng/commands/destroy.c +1
-0+free (session_name);if (lttng_opt_mi) { ret =mi_lttng_session (writer, session,0 );src/bin/lttng/conf.c +0
-2@@ -199,8 +199,6 @@ char *config_read_session_name(char *path) fp =open_config (path,"r" );if (fp ==NULL ) { -ERR ("Can't find valid lttng config %s/.lttngrc" , path); -MSG ("Did you create a session? (lttng create <my_session>)" );free (session_name); goto error; }src/bin/lttng/utils.c +0
-0
src/bin/lttng/utils.c char *get_session_name(void) · line 65
Quoted 7 lines
src/bin/lttng/utils.c +2
-0@@ -59,6 +59,8 @@ char *get_session_name(void)/* Get session name from config */ session_name =config_read_session_name (path);if (session_name ==NULL ) { +ERR ("Can't find valid lttng config %s/.lttngrc" , path); +MSG ("Did you create a session? (lttng create <my_session>)" ); goto error; }
get_session_name() should not log this when an .lttngrc file can't be found; it might not be an error.
It should be handled on a case-by-case basis by its callers.
Thanks,
Jérémie
Quoted 4 lines
src/bin/lttng/utils.c +0
-1--1.7.9.5
Quoted 59 lines · Partha Pratim Mukherjee
Quoted 3 lines · Jérémie Galarneau
Hi Partha,
First, thanks for the patch! Unfortunately, there are a couple of issues
with this fix. Read on.
Quoted 2 lines
On Wed, May 20, 2015 at 2:59 PM, Partha Pratim Mukherjee <
Quoted 7 lines · [email protected]> wrote:
Destroy session command by default removes the default config file without checking the current session. As a result when we call any other command which expects a default session by calling
get_session_name()function, it fails.This patch will fix this by checking that the default config file
gets
Quoted 10 lines
removed only when destroy session is called with the current session.
Fixes #887Signed-off-by Partha Pratim Mukherjee <[email protected]>---
src/bin/lttng/commands/destroy.c| 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)diff --git
a/src/bin/lttng/commands/destroy.c
b/src/bin/lttng/commands/destroy.cQuoted 4 lines
index 95343c9..3fcecc2 100644 --- a/src/bin/lttng/commands/destroy.c +++ b/src/bin/lttng/commands/destroy.c @@ -90,7 +90,9 @@ static int destroy_session(struct lttng_session*session)
Quoted 5 lines
}
MSG("Session %s destroyed", session->name);
-config_destroy_default();
+ if (strncmp(session->name, get_session_name(), NAME_MAX)==0) {
Quoted 4 lines
This will leak the string returned by
get_session_name().Moreover,
config_read_session_name(), which is calledby
get_session_name()will spam the error logs anytime an .lttngrc file can't be found;Quoted 4 lines
the error logging statement should be moved out to the different callers.
Looking forward to a v2!
JérémieHi Jérémie,
Thanks for the review comments. I have incorporated your comments in the attached patch. Please review.
Thanks,
Partha
Signature · 3 lines
Jérémie Galarneau EfficiOS Inc. http://www.efficios.com
_______________________________________________
lttng-dev mailing list
[email protected]
http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
A message that is not in the archive (sent off-list or not yet received): CA+jJMxtQ-=CXzXpA_eaY8ogwDjYp8hGxH=HRns+UixF15PLWmg@mail.gmail.com
Jérémie Galarneau <[email protected]> writes:
...
Quoted 15 lines
This may not be an error.
get_session_name()will return NULL whenever a default session is not defined. This will happen, for instance, when loading a session configuration.The
test_loadscript, under lttng-tools/tests/regression/tools/save-load will perform:$ lttng load -i load-42.lttng $ lttng destroy load-42 Session load-42 destroyed Error: Can't find valid lttng config /home/jgalar/.lttngrc Did you create a session? (lttng create <my_session>) Error: Command error(make sure you delete ~/.lttngrc beforehand to test this properly)
Quoted 9 lines
Quoted 4 lines
+ if (
strncmp(session->name, session_name, NAME_MAX)== 0) {
+config_destroy_default();
+ }
+We should skip this check if
get_session_name()returned NULL with something like:if (
session_name&&strncmp(session->name, session_name, NAME_MAX)== 0) { ...
I did not know about load option which may load single/multiple sessions from a file. So we can't set a default session. I agree on your suggestion. This may be handled like this.
session_name = get_session_name();
if (session_name && strncmp(session->name, session_name, NAME_MAX) == 0) {
config_destroy_default();
}
free(session_name);Quoted 4 lines
get_session_name()should not log this when an .lttngrc file can't be found; it might not be an error. It should be handled on a case-by-case basis by its callers.
Now if we remove the error messages from get_session_name() as you have suggested, then we have to handle other commands which are looking for a default session like enable-event which now gives a very generic error message like this
Error: Command error
So we have to add error messages on all those commands which are expecting a default session. As per the help message the following commands need to be modified.
destroy, disable-channel, disable-event, enable-channel, enable-event, save, snapshot, start, stop, track, untrack, view
If yes, then I will create another patch and send.
What do you suggest?
Thanks,
Partha
Quoted 3 lines
Thanks,
Jérémie
_______________________________________________
lttng-dev mailing list
[email protected]
http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 62 lines · Partha Pratim Mukherjee
Jérémie Galarneau <[email protected]> writes:
...
Quoted 2 lines
This may not be an error.
get_session_name()will return NULL whenever a default session is notdefined. This will happen, for instance, when loading a session
Quoted 3 lines
configuration.
The
test_loadscript, under lttng-tools/tests/regression/tools/save-loadwill perform:
Quoted 8 lines
$ lttng load -i load-42.lttng $ lttng destroy load-42 Session load-42 destroyed Error: Can't find valid lttng config /home/jgalar/.lttngrc Did you create a session? (lttng create <my_session>) Error: Command errorQuoted 8 lines
(make sure you delete ~/.lttngrc beforehand to test this properly)
Quoted 4 lines
+ if (
strncmp(session->name, session_name, NAME_MAX)== 0) {
+config_destroy_default();
+ }
+We should skip this check if
get_session_name()returned NULL withsomething like:
Quoted 2 lines
if (
session_name&&strncmp(session->name, session_name, NAME_MAX)== 0){ ...
Quoted 1 line
I did not know about load option which may load single/multiple sessions from a file. So we can't set a default session. I agree on your suggestion. This may be handled like this.
session_name = get_session_name(); if (session_name && strncmp(session->name, session_name, NAME_MAX) == 0) { config_destroy_default(); } free(session_name);Quoted 2 lines
get_session_name()should not log this when an .lttngrc file can't befound; it might not be an error.
Quoted 2 lines
It should be handled on a case-by-case basis by its callers.
Now if we remove the error messages from
get_session_name()as you have suggested, then we have to handle other commands which are looking for a default session like enable-event which now gives a very generic error message like thisError: Command error
So we have to add error messages on all those commands which are expecting a default session. As per the help message the following commands need to be modified.
Quoted 8 lines
destroy, disable-channel, disable-event, enable-channel, enable-event, save, snapshot, start, stop, track, untrack, view
If yes, then I will create another patch and send.
What do you suggest?
Sounds good to me. Thanks!
Jérémie
Quoted 7 lines
Thanks,
ParthaQuoted 3 lines
Thanks,
Jérémie
Signature · 3 lines
Jérémie Galarneau EfficiOS Inc. http://www.efficios.com
_______________________________________________
lttng-dev mailing list
[email protected]
http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
A message that is not in the archive (sent off-list or not yet received): CA+jJMxsJNzy294Stve-ajKJzk_8eFFRvW_ObNs-t2kpCcz0jnQ@mail.gmail.com
Quoted 5 lines · Jérémie Galarneau
Sounds good to me. Thanks!
Jérémie
Hi,
As discussed please find the patch which takes care of all your suggestions. Please review.
Thanks once again.
Partha
Destroy session command by default removes the default config file without checking the current session. As a result when we call any other command which expects a default session by calling get_session_name() function, it fails.
This patch will fix this by checking that the default config file gets removed only when destroy session is called with the current session.
This patch also moves error messages from get_session_name() to its callers.
--- src/bin/lttng/commands/destroy.c | 15 ++++++++++++++- src/bin/lttng/commands/disable_channels.c | 5 +++++ src/bin/lttng/commands/disable_events.c | 6 +++++- src/bin/lttng/commands/enable_channels.c | 4 ++++ src/bin/lttng/commands/enable_events.c | 5 +++++ src/bin/lttng/commands/snapshot.c | 4 ++++ src/bin/lttng/commands/start.c | 5 +++++ src/bin/lttng/commands/stop.c | 5 +++++ src/bin/lttng/commands/track-untrack.c | 5 +++++ src/bin/lttng/commands/view.c | 5 +++++ src/bin/lttng/conf.c | 2 -- 11 files changed, 57 insertions(+), 4 deletions(-)
src/bin/lttng/commands/destroy.c +14 -1
@@ -1,3 +1,4 @@ +/* * Copyright (C) 2011 - David Goulet <[email protected]> *
@@ -29,6 +30,7 @@#include <common/mi-lttng.h> #include <common/sessiond-comm/sessiond-comm.h> +#include <common/utils.h> static char *opt_session_name;static int opt_destroy_all;
@@ -75,6 +77,7 @@ static void usage(FILE *ofp)static int destroy_session (struct lttng_session *session) {int ret; +char *session_name =NULL ; ret =lttng_destroy_session (session->name);if (ret <0 ) {
@@ -90,7 +93,13 @@ static int destroy_session(struct lttng_session *session) }MSG ("Session %s destroyed" , session->name); -config_destroy_default (); + + session_name =get_session_name (); +if (session_name &&strncmp (session->name, session_name,NAME_MAX ) ==0 ) { +config_destroy_default (); + } +free (session_name); +if (lttng_opt_mi) { ret =mi_lttng_session (writer, session,0 );
@@ -144,6 +153,7 @@ int cmd_destroy(int argc, const char **argv)struct lttng_session *sessions;int count;int found; +char *path; pc =poptGetContext (NULL , argc, argv, long_options,0 );poptReadDefaultConfig (pc,0 );
@@ -217,6 +227,9 @@ int cmd_destroy(int argc, const char **argv)/* No session name specified, lookup default */ session_name =get_session_name ();if (session_name ==NULL ) { + path =utils_get_home_dir (); +ERR ("Can't find valid lttng config %s/.lttngrc" , path); +MSG ("Did you create a session? (lttng create <my_session>)" ); command_ret =CMD_ERROR ; success =0 ; goto mi_closing;
src/bin/lttng/commands/disable_channels.c +5 -0
@@ -27,6 +27,7 @@#include <assert.h> #include <common/mi-lttng.h> +#include <common/utils.h> #include "../command.h"
@@ -239,6 +240,7 @@ int cmd_disable_channels(int argc, const char **argv)int opt, ret =CMD_SUCCESS , command_ret =CMD_SUCCESS , success =1 ;static poptContext pc;char *session_name =NULL ; +char *path; pc =poptGetContext (NULL , argc, argv, long_options,0 );poptReadDefaultConfig (pc,0 );
@@ -272,6 +274,9 @@ int cmd_disable_channels(int argc, const char **argv)if (!opt_session_name) { session_name =get_session_name ();if (session_name ==NULL ) { + path =utils_get_home_dir (); +ERR ("Can't find valid lttng config %s/.lttngrc" , path); +MSG ("Did you create a session? (lttng create <my_session>)" ); ret =CMD_ERROR ; goto end; }
src/bin/lttng/commands/disable_events.c +5 -1
@@ -27,7 +27,7 @@#include <assert.h> #include <common/mi-lttng.h> - +#include <common/utils.h> #include "../command.h" static char *opt_event_list;
@@ -338,6 +338,7 @@ int cmd_disable_events(int argc, const char **argv)static poptContext pc;char *session_name =NULL ;int event_type =-1 ; +char *path; pc =poptGetContext (NULL , argc, argv, long_options,0 );poptReadDefaultConfig (pc,0 );
@@ -388,6 +389,9 @@ int cmd_disable_events(int argc, const char **argv)if (!opt_session_name) { session_name =get_session_name ();if (session_name ==NULL ) { + path =utils_get_home_dir (); +ERR ("Can't find valid lttng config %s/.lttngrc" , path); +MSG ("Did you create a session? (lttng create <my_session>)" ); ret =CMD_ERROR ; goto end; }
src/bin/lttng/commands/enable_channels.c +4 -0
@@ -393,6 +393,7 @@ int cmd_enable_channels(int argc, const char **argv)static poptContext pc;char *session_name =NULL ;char *opt_arg =NULL ; +char *path;init_channel_config ();
@@ -607,6 +608,9 @@ int cmd_enable_channels(int argc, const char **argv)if (!opt_session_name) { session_name =get_session_name ();if (session_name ==NULL ) { + path =utils_get_home_dir (); +ERR ("Can't find valid lttng config %s/.lttngrc" , path); +MSG ("Did you create a session? (lttng create <my_session>)" ); command_ret =CMD_ERROR ; success =0 ; goto mi_closing;
src/bin/lttng/commands/enable_events.c +5 -0
@@ -32,6 +32,7 @@/* Mi dependancy */ #include <common/mi-lttng.h> +#include <common/utils.h> #include "../command.h"
@@ -1345,6 +1346,7 @@ int cmd_enable_events(int argc, const char **argv)static poptContext pc;char *session_name =NULL ;int event_type =-1 ; +char *path; pc =poptGetContext (NULL , argc, argv, long_options,0 );poptReadDefaultConfig (pc,0 );
@@ -1441,6 +1443,9 @@ int cmd_enable_events(int argc, const char **argv)if (!opt_session_name) { session_name =get_session_name ();if (session_name ==NULL ) { + path =utils_get_home_dir (); +ERR ("Can't find valid lttng config %s/.lttngrc" , path); +MSG ("Did you create a session? (lttng create <my_session>)" ); command_ret =CMD_ERROR ; success =0 ; goto mi_closing;
src/bin/lttng/commands/snapshot.c +4 -0
@@ -684,6 +684,7 @@ int cmd_snapshot(int argc, const char **argv)int opt, ret =CMD_SUCCESS , command_ret =CMD_SUCCESS , success =1 ;char *session_name =NULL ;static poptContext pc; +char *path; pc =poptGetContext (NULL , argc, argv, snapshot_opts,0 );poptReadDefaultConfig (pc,0 );
@@ -749,6 +750,9 @@ int cmd_snapshot(int argc, const char **argv)if (!opt_session_name) { session_name =get_session_name ();if (session_name ==NULL ) { + path =utils_get_home_dir (); +ERR ("Can't find valid lttng config %s/.lttngrc" , path); +MSG ("Did you create a session? (lttng create <my_session>)" ); ret =CMD_ERROR ; goto end; }
src/bin/lttng/commands/start.c +5 -0
@@ -27,6 +27,7 @@#include <common/sessiond-comm/sessiond-comm.h> #include <common/mi-lttng.h> +#include <common/utils.h> #include "../command.h"
@@ -101,10 +102,14 @@ static int start_tracing(void) {int ret;char *session_name; +char *path;if (opt_session_name ==NULL ) { session_name =get_session_name ();if (session_name ==NULL ) { + path =utils_get_home_dir (); +ERR ("Can't find valid lttng config %s/.lttngrc" , path); +MSG ("Did you create a session? (lttng create <my_session>)" ); ret =CMD_ERROR ; goto error; }
src/bin/lttng/commands/stop.c +5 -0
@@ -28,6 +28,7 @@#include <common/sessiond-comm/sessiond-comm.h> #include <common/mi-lttng.h> +#include <common/utils.h> #include "../command.h"
@@ -107,10 +108,14 @@ static int stop_tracing(void) {int ret;char *session_name; +char *path;if (opt_session_name ==NULL ) { session_name =get_session_name ();if (session_name ==NULL ) { + path =utils_get_home_dir (); +ERR ("Can't find valid lttng config %s/.lttngrc" , path); +MSG ("Did you create a session? (lttng create <my_session>)" ); ret =CMD_ERROR ; goto error; }
src/bin/lttng/commands/track-untrack.c +5 -0
@@ -30,6 +30,7 @@#include <urcu/list.h> #include <common/mi-lttng.h> +#include <common/utils.h> #include "../command.h"
@@ -305,6 +306,7 @@ int cmd_track_untrack(enum cmd_type cmd_type, const char *cmd_str,static poptContext pc;char *session_name =NULL ;struct mi_writer *writer =NULL ; +char *path;if (argc <1 ) {usage (stderr, cmd_str);
@@ -344,6 +346,9 @@ int cmd_track_untrack(enum cmd_type cmd_type, const char *cmd_str,if (!opt_session_name) { session_name =get_session_name ();if (session_name ==NULL ) { + path =utils_get_home_dir (); +ERR ("Can't find valid lttng config %s/.lttngrc" , path); +MSG ("Did you create a session? (lttng create <my_session>)" ); ret =CMD_ERROR ; goto end; }
src/bin/lttng/commands/view.c +5 -0
@@ -27,6 +27,7 @@#include "../command.h" #include <config.h> +#include <common/utils.h> static char *opt_session_name;static char *opt_viewer;
@@ -328,6 +329,7 @@ static int view_trace(void)int ret;char *session_name, *trace_path =NULL ;struct lttng_session *sessions =NULL ; +char *path;/* * Safety net. If lttng is suid at some point for *any* useless reasons,
@@ -351,6 +353,9 @@ static int view_trace(void) }else if (opt_session_name ==NULL ) { session_name =get_session_name ();if (session_name ==NULL ) { + path =utils_get_home_dir (); +ERR ("Can't find valid lttng config %s/.lttngrc" , path); +MSG ("Did you create a session? (lttng create <my_session>)" ); ret =CMD_ERROR ; goto error; }
src/bin/lttng/conf.c +0 -2
@@ -199,8 +199,6 @@ char *config_read_session_name(char *path) fp =open_config (path,"r" );if (fp ==NULL ) { -ERR ("Can't find valid lttng config %s/.lttngrc" , path); -MSG ("Did you create a session? (lttng create <my_session>)" );free (session_name); goto error; }
Signature · 1 line
1.7.9.5
_______________________________________________
lttng-dev mailing list
[email protected]
http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
A message that is not in the archive (sent off-list or not yet received): [email protected]
Merged in master, stable-2.6 and stable-2.5.
Thanks!
Jérémie
Quoted 17 lines · Partha Pratim Mukherjee
Quoted 5 lines · Jérémie Galarneau
Sounds good to me. Thanks!
Jérémie
Hi,
As discussed please find the patch which takes care of all your suggestions. Please review.
Thanks once again.
Partha
Signature · 3 lines
Jérémie Galarneau EfficiOS Inc. http://www.efficios.com
_______________________________________________
lttng-dev mailing list
[email protected]
http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev