Re: [lttng-dev] [PATCH lttng-tools] Tests: Added autoloading session test cases
Merged in master, stable-2.10, and stable-2.9. Thanks! Jérémie On Thu, May 17, 2018 at 10:50:41PM +0200, Anders Wallin wrote: > lttng-sessiond can auto load sessions at startup; > - with "--load" option to lttng-sessiond, load one file > or all sessions files in that directory > - from session files in $LTTNG_HOME/.lttng/sessions/auto/ > - from session files in $sysconfdir/lttng/sessions/auto > > This test case validate the two first scenarios. > > Signed-off-by: Anders Wallin > --- > tests/fast_regression | 1 + > .../regression/tools/save-load/test_autoload | 107 ++ > 2 files changed, 108 insertions(+) > create mode 100755 tests/regression/tools/save-load/test_autoload > > diff --git a/tests/fast_regression b/tests/fast_regression > index bbce068f..2f02f872 100644 > --- a/tests/fast_regression > +++ b/tests/fast_regression > @@ -13,6 +13,7 @@ regression/tools/snapshots/test_ust_fast > regression/tools/snapshots/test_ust_streaming > regression/tools/save-load/test_save > regression/tools/save-load/test_load > +regression/tools/save-load/test_autoload > regression/tools/mi/test_mi > regression/tools/wildcard/test_event_wildcard > regression/tools/crash/test_crash > diff --git a/tests/regression/tools/save-load/test_autoload > b/tests/regression/tools/save-load/test_autoload > new file mode 100755 > index ..26193be6 > --- /dev/null > +++ b/tests/regression/tools/save-load/test_autoload > @@ -0,0 +1,107 @@ > +#!/bin/bash > +# > +# Copyright (C) - 2018 Anders Wallin > +# > +# This library is free software; you can redistribute it and/or modify it > under > +# the terms of the GNU Lesser General Public License as published by the Free > +# Software Foundation; version 2.1 of the License. > +# > +# This library is distributed in the hope that it will be useful, but WITHOUT > +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or > FITNESS > +# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for > more > +# details. > +# > +# You should have received a copy of the GNU Lesser General Public License > +# along with this library; if not, write to the Free Software Foundation, > Inc., > +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA > + > +TEST_DESC="Auto load session(s)" > + > +CURDIR=$(dirname $0)/ > +CONFIG_DIR="${CURDIR}/configuration" > +TESTDIR=$CURDIR/../../../ > +SESSIOND_BIN="lttng-sessiond" > +RELAYD_BIN="lttng-relayd" > +LTTNG_BIN="lttng" > +export LTTNG_SESSION_CONFIG_XSD_PATH=$(readlink -m > ${TESTDIR}../src/common/config/) > + > +DIR=$(readlink -f $TESTDIR) > + > +NUM_TESTS=10 > + > +source $TESTDIR/utils/utils.sh > + > +# MUST set TESTDIR before calling those functions > +plan_tests $NUM_TESTS > + > +print_test_banner "$TEST_DESC" > + > +function test_auto_load_file() > +{ > + diag "Test auto load file" > + > + export LTTNG_HOME= > + > + start_lttng_sessiond $CURDIR/load-42.lttng > + list_lttng_with_opts load-42 > + stop_lttng_sessiond > +} > + > +function test_auto_load_dir() > +{ > + diag "Test auto load directory" > + > + export LTTNG_HOME= > + export LTTNG_DIR=$(mktemp -d) > + cp -f $CURDIR/load-42.lttng $LTTNG_DIR/ > + > + start_lttng_sessiond $LTTNG_DIR > + list_lttng_with_opts load-42 > + stop_lttng_sessiond > + > + rm -rf $LTTNG_DIR > +} > + > +function test_auto_load_lttng_home() > +{ > + diag "Test auto load by setting LTTNG_HOME" > + > + export LTTNG_HOME=$(mktemp -d) > + mkdir -p $LTTNG_HOME/.lttng/sessions/auto > + cp -f $CURDIR/load-42.lttng $LTTNG_HOME/.lttng/sessions/auto > + > + start_lttng_sessiond > + list_lttng_with_opts load-42 > + stop_lttng_sessiond > + > + rm -rf $LTTNG_HOME > +} > + > +TESTS=( > + test_auto_load_file > + test_auto_load_dir > + test_auto_load_lttng_home > +) > + > +# Need to be sure that no lttng-sessiond is running > +# - "stop_lttng_sessiond" is using the SESSIOND_PIDS created with > +# "start_lttng_sessiond" > +# - "sigstop_lttng_sessiond" keep lttng-runas dangling > +# - "stop_lttng_sessiond SIGKILL" will leave kernel modules loaded > +# The code below are killing all lttng-* programs and remove the > +# the lttng kernel modules > +SESSIOND_PIDS=$(pgrep $SESSIOND_MATCH) > +kill $SESSIOND_PIDS > +stop_lttng_sessiond > + > +for fct_test in ${TESTS[@]}; > +do > + TRACE_PATH=$(mktemp -d) > + > + ${fct_test} > + if [ $? -ne 0 ]; then > + break; > + fi > + # Only delete if successful > + rm -rf $TRACE_PATH > +done > -- > 2.17.0 > > ___ > lttng-dev mailing list > lttng-dev@lists.lttng.org > https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev ___ lttng-dev mailing list lttng-dev@lists.lttng.org https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
Re: [lttng-dev] [PATCH lttng-tools] Replace deprecated readdir_r() with readdir()
Merged in master, thanks! Jérémie On Tue, Jun 05, 2018 at 12:11:20PM -0400, Michael Jeanson wrote: > readdir_r() has been deprecated since glibc 2.24 [1]. > > We used readdir_r() in load_session_from_path() to be thread-safe > since this function is part of liblttng-ust-ctl. However, according > to readdir()'s man page, it's thread-safe as long as the directory > stream it operates on is not shared across threads : > > In the current POSIX.1 specification (POSIX.1-2008), readdir(3) is > not required to be thread-safe. However, in modern > implementations (including the glibc implementation), concurrent > calls to readdir(3) that specify different directory streams are > thread-safe. Therefore, the use of readdir_r() is generally > unnecessary in multithreaded programs. In cases where multiple > threads must read from the same directory stream, using readdir(3) > with external synchronization is still preferable to the use of > readdir_r(), for the reasons given in the points above. > > In our use-case where we open the directory stream in the same function, > we know it won't be shared across threads and thus it's safe to use > readdir(). Here is the relevevant bit from the POSIX.1 [2] spec : > > The returned pointer, and pointers within the structure, might be > invalidated or the structure or the storage areas might be overwritten > by a subsequent call to readdir() on the same directory stream. They shall > not be affected by a call to readdir() on a different directory stream. > > [1] https://sourceware.org/bugzilla/show_bug.cgi?id=19056 > [2] http://pubs.opengroup.org/onlinepubs/9699919799/functions/readdir.html > > Signed-off-by: Michael Jeanson > --- > src/common/config/session-config.c | 54 ++ > 1 file changed, 26 insertions(+), 28 deletions(-) > > diff --git a/src/common/config/session-config.c > b/src/common/config/session-config.c > index 624064a1..56db1195 100644 > --- a/src/common/config/session-config.c > +++ b/src/common/config/session-config.c > @@ -2953,23 +2953,6 @@ end: > return ret; > } > > -/* Allocate dirent as recommended by READDIR(3), NOTES on readdir_r */ > -static > -struct dirent *alloc_dirent(const char *path) > -{ > - size_t len; > - long name_max; > - struct dirent *entry; > - > - name_max = pathconf(path, _PC_NAME_MAX); > - if (name_max == -1) { > - name_max = PATH_MAX; > - } > - len = offsetof(struct dirent, d_name) + name_max + 1; > - entry = zmalloc(len); > - return entry; > -} > - > static > int load_session_from_path(const char *path, const char *session_name, > struct session_config_validation_ctx *validation_ctx, int overwrite, > @@ -3006,7 +2989,6 @@ int load_session_from_path(const char *path, const char > *session_name, > } > } > if (directory) { > - struct dirent *entry; > struct dirent *result; > size_t file_path_root_len; > > @@ -3017,16 +2999,9 @@ int load_session_from_path(const char *path, const > char *session_name, > goto end; > } > > - entry = alloc_dirent(path); > - if (!entry) { > - ret = -LTTNG_ERR_NOMEM; > - goto end; > - } > - > ret = lttng_dynamic_buffer_append(&file_path, path, path_len); > if (ret) { > ret = -LTTNG_ERR_NOMEM; > - free(entry); > goto end; > } > > @@ -3040,8 +3015,32 @@ int load_session_from_path(const char *path, const > char *session_name, > file_path_root_len = file_path.size; > > /* Search for *.lttng files */ > - while (!readdir_r(directory, entry, &result) && result) { > - size_t file_name_len = strlen(result->d_name); > + for (;;) { > + size_t file_name_len; > + > + /* > + * When the end of the directory stream is reached, > NULL is > + * returned and errno is kept unchanged. When an error > occurs, > + * NULL is returned and errno is set accordingly. To > + * distinguish between the two, set errno to zero before > + * calling readdir(). > + * > + * On success, readdir() returns a pointer to a dirent > + * structure. (This structure may be statically > allocated, do > + * not attempt to free(3) it.) > + */ > + errno = 0; > + result = readdir(directory); > + > + /* Reached end of dir stream or error out */ > + if (!result) { > + if (errno) { > + P
Re: [lttng-dev] [PATCH lttng-tools] Bash completion: ignore namespace for xmllint parsing
Merged in master, stable-2.10, and stable-2.9. Thanks! Jérémie On Mon, May 28, 2018 at 05:31:48PM -0400, Jonathan Rajotte wrote: > xmllint cli does not "easily" support namespace. > > One can use the local_name() xpath function and other "trick". > The simplest trick for bash completion is to ignore the namespace > altogether. > > Replacing "xmlns" by "ignore" does the job. > > Signed-off-by: Jonathan Rajotte > --- > extras/lttng-bash_completion | 8 > 1 file changed, 4 insertions(+), 4 deletions(-) > > diff --git a/extras/lttng-bash_completion b/extras/lttng-bash_completion > index ef1a71ab..c7482c54 100644 > --- a/extras/lttng-bash_completion > +++ b/extras/lttng-bash_completion > @@ -18,7 +18,7 @@ > # Generates COMPREPLY with the existing session names > _lttng_complete_sessions() { > local sessions > - sessions=$(lttng --mi xml list | xmllint --xpath > "//command/output/sessions/session/name" - 2>/dev/null | sed -e > 's///g' -e $'s/<\/name>/\\n/g') > + sessions=$(lttng --mi xml list | sed '2 s/xmlns/ignore/g' | xmllint > --xpath "//command/output/sessions/session/name" - 2>/dev/null | sed -e > 's///g' -e $'s/<\/name>/\\n/g') > COMPREPLY=( $(compgen -W "${sessions}" -- $cur) ) > return > } > @@ -27,7 +27,7 @@ _lttng_complete_sessions() { > # Generates COMPREPLY with the available kernel event > _lttng_complete_kernel_events() { > local kernel_event > - kernel_event=$(lttng --mi xml list -k | xmllint --xpath > "//command/output/domains/domain[./type = 'KERNEL']/events/event/name" - > 2>/dev/null | sed -e "s///g" -e $"s/<\/name>/\\n/g") > + kernel_event=$(lttng --mi xml list -k |sed '2 s/xmlns/ignore/g' | > xmllint --xpath "//command/output/domains/domain[./type = > 'KERNEL']/events/event/name" - 2>/dev/null | sed -e "s///g" -e > $"s/<\/name>/\\n/g") > COMPREPLY=( $(compgen -W "${kernel_event}" -- $cur) ) > return > } > @@ -35,7 +35,7 @@ _lttng_complete_kernel_events() { > # Generates COMPREPLY with the available ust event > _lttng_complete_ust_events() { > local ust_event > - ust_event=$(lttng --mi xml list -u | xmllint --xpath > "//command/output/domains/domain[./type = 'UST']/pids/pid/events/event/name" > - 2>/dev/null | sed -e "s///g" -e $"s/<\/name>/\\n/g") > + ust_event=$(lttng --mi xml list -u | sed '2 s/xmlns/ignore/g' | xmllint > --xpath "//command/output/domains/domain[./type = > 'UST']/pids/pid/events/event/name" - 2>/dev/null | sed -e "s///g" -e > $"s/<\/name>/\\n/g") > COMPREPLY=( $(compgen -W "${ust_event}" -- $cur) ) > return > } > @@ -43,7 +43,7 @@ _lttng_complete_ust_events() { > # Generates COMPREPLY with the available jul event > _lttng_complete_jul_events() { > local jul_event > - jul_event=$(lttng --mi xml list -j | xmllint --xpath > "//command/output/domains/domain[./type = 'JUL']/pids/pid/events/event/name" > - 2>/dev/null | sed -e "s///g" -e $"s/<\/name>/\\n/g") > + jul_event=$(lttng --mi xml list -j | sed '2 s/xmlns/ignore/g' | xmllint > --xpath "//command/output/domains/domain[./type = > 'JUL']/pids/pid/events/event/name" - 2>/dev/null | sed -e "s///g" -e > $"s/<\/name>/\\n/g") > COMPREPLY=( $(compgen -W "${jul_event}" -- $cur) ) > return > } > -- > 2.17.0 > ___ lttng-dev mailing list lttng-dev@lists.lttng.org https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
[lttng-dev] [PATCH lttng-tools] Replace deprecated readdir_r() with readdir()
readdir_r() has been deprecated since glibc 2.24 [1]. We used readdir_r() in load_session_from_path() to be thread-safe since this function is part of liblttng-ust-ctl. However, according to readdir()'s man page, it's thread-safe as long as the directory stream it operates on is not shared across threads : In the current POSIX.1 specification (POSIX.1-2008), readdir(3) is not required to be thread-safe. However, in modern implementations (including the glibc implementation), concurrent calls to readdir(3) that specify different directory streams are thread-safe. Therefore, the use of readdir_r() is generally unnecessary in multithreaded programs. In cases where multiple threads must read from the same directory stream, using readdir(3) with external synchronization is still preferable to the use of readdir_r(), for the reasons given in the points above. In our use-case where we open the directory stream in the same function, we know it won't be shared across threads and thus it's safe to use readdir(). Here is the relevevant bit from the POSIX.1 [2] spec : The returned pointer, and pointers within the structure, might be invalidated or the structure or the storage areas might be overwritten by a subsequent call to readdir() on the same directory stream. They shall not be affected by a call to readdir() on a different directory stream. [1] https://sourceware.org/bugzilla/show_bug.cgi?id=19056 [2] http://pubs.opengroup.org/onlinepubs/9699919799/functions/readdir.html Signed-off-by: Michael Jeanson --- src/common/config/session-config.c | 54 ++ 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/src/common/config/session-config.c b/src/common/config/session-config.c index 624064a1..56db1195 100644 --- a/src/common/config/session-config.c +++ b/src/common/config/session-config.c @@ -2953,23 +2953,6 @@ end: return ret; } -/* Allocate dirent as recommended by READDIR(3), NOTES on readdir_r */ -static -struct dirent *alloc_dirent(const char *path) -{ - size_t len; - long name_max; - struct dirent *entry; - - name_max = pathconf(path, _PC_NAME_MAX); - if (name_max == -1) { - name_max = PATH_MAX; - } - len = offsetof(struct dirent, d_name) + name_max + 1; - entry = zmalloc(len); - return entry; -} - static int load_session_from_path(const char *path, const char *session_name, struct session_config_validation_ctx *validation_ctx, int overwrite, @@ -3006,7 +2989,6 @@ int load_session_from_path(const char *path, const char *session_name, } } if (directory) { - struct dirent *entry; struct dirent *result; size_t file_path_root_len; @@ -3017,16 +2999,9 @@ int load_session_from_path(const char *path, const char *session_name, goto end; } - entry = alloc_dirent(path); - if (!entry) { - ret = -LTTNG_ERR_NOMEM; - goto end; - } - ret = lttng_dynamic_buffer_append(&file_path, path, path_len); if (ret) { ret = -LTTNG_ERR_NOMEM; - free(entry); goto end; } @@ -3040,8 +3015,32 @@ int load_session_from_path(const char *path, const char *session_name, file_path_root_len = file_path.size; /* Search for *.lttng files */ - while (!readdir_r(directory, entry, &result) && result) { - size_t file_name_len = strlen(result->d_name); + for (;;) { + size_t file_name_len; + + /* +* When the end of the directory stream is reached, NULL is +* returned and errno is kept unchanged. When an error occurs, +* NULL is returned and errno is set accordingly. To +* distinguish between the two, set errno to zero before +* calling readdir(). +* +* On success, readdir() returns a pointer to a dirent +* structure. (This structure may be statically allocated, do +* not attempt to free(3) it.) +*/ + errno = 0; + result = readdir(directory); + + /* Reached end of dir stream or error out */ + if (!result) { + if (errno) { + PERROR("readdir"); + } + break; + } + + file_name_len = strlen(result->d_name); if (file_name_len <=