Merge branch 'master' into benchmark
authorDavid Goulet <dgoulet@efficios.com>
Mon, 26 Mar 2012 20:55:06 +0000 (16:55 -0400)
committerDavid Goulet <dgoulet@efficios.com>
Mon, 26 Mar 2012 20:55:06 +0000 (16:55 -0400)
Signed-off-by: David Goulet <dgoulet@efficios.com>
110 files changed:
ChangeLog
LICENSE
configure.ac
doc/man/lttng-sessiond.8
doc/man/lttng.1
include/lttng/lttng.h
src/bin/lttng-consumerd/Makefile.am
src/bin/lttng-consumerd/lttng-consumerd.c
src/bin/lttng-consumerd/lttng-consumerd.h
src/bin/lttng-sessiond/Makefile.am
src/bin/lttng-sessiond/channel.c
src/bin/lttng-sessiond/channel.h
src/bin/lttng-sessiond/context.c
src/bin/lttng-sessiond/context.h
src/bin/lttng-sessiond/event.c
src/bin/lttng-sessiond/event.h
src/bin/lttng-sessiond/fd-limit.c [new file with mode: 0644]
src/bin/lttng-sessiond/fd-limit.h [new file with mode: 0644]
src/bin/lttng-sessiond/futex.c
src/bin/lttng-sessiond/futex.h
src/bin/lttng-sessiond/kern-modules.h
src/bin/lttng-sessiond/kernel.c
src/bin/lttng-sessiond/kernel.h
src/bin/lttng-sessiond/lttng-sessiond.h
src/bin/lttng-sessiond/lttng-ust-abi.h
src/bin/lttng-sessiond/lttng-ust-ctl.h
src/bin/lttng-sessiond/main.c
src/bin/lttng-sessiond/modprobe.c
src/bin/lttng-sessiond/modprobe.h
src/bin/lttng-sessiond/session.c
src/bin/lttng-sessiond/session.h
src/bin/lttng-sessiond/shm.c
src/bin/lttng-sessiond/shm.h
src/bin/lttng-sessiond/trace-kernel.c
src/bin/lttng-sessiond/trace-kernel.h
src/bin/lttng-sessiond/trace-ust.c
src/bin/lttng-sessiond/trace-ust.h
src/bin/lttng-sessiond/ust-app.c
src/bin/lttng-sessiond/ust-app.h
src/bin/lttng-sessiond/ust-consumer.c
src/bin/lttng-sessiond/ust-consumer.h
src/bin/lttng-sessiond/ust-ctl.h
src/bin/lttng-sessiond/utils.c
src/bin/lttng-sessiond/utils.h
src/bin/lttng/command.h
src/bin/lttng/commands/add_context.c
src/bin/lttng/commands/calibrate.c
src/bin/lttng/commands/create.c
src/bin/lttng/commands/destroy.c
src/bin/lttng/commands/disable_channels.c
src/bin/lttng/commands/disable_events.c
src/bin/lttng/commands/enable_channels.c
src/bin/lttng/commands/enable_events.c
src/bin/lttng/commands/list.c
src/bin/lttng/commands/set_session.c
src/bin/lttng/commands/start.c
src/bin/lttng/commands/stop.c
src/bin/lttng/commands/version.c
src/bin/lttng/commands/view.c
src/bin/lttng/conf.c
src/bin/lttng/conf.h
src/bin/lttng/lttng.c
src/bin/lttng/utils.c
src/bin/lttng/utils.h
src/common/Makefile.am
src/common/common.h
src/common/compat/Makefile.am [new file with mode: 0644]
src/common/compat/clone.h [new file with mode: 0644]
src/common/compat/compat-epoll.c
src/common/compat/compat-fcntl.c [new file with mode: 0644]
src/common/compat/compat-poll.c
src/common/compat/endian.h [new file with mode: 0644]
src/common/compat/fcntl.h [new file with mode: 0644]
src/common/compat/mman.h [new file with mode: 0644]
src/common/compat/poll.h
src/common/compat/socket.h [new file with mode: 0644]
src/common/consumer.c
src/common/consumer.h
src/common/defaults.h
src/common/error.h
src/common/hashtable/hashtable.c
src/common/hashtable/hashtable.h
src/common/hashtable/rculfhash-mm-mmap.c
src/common/hashtable/utils.c
src/common/hashtable/utils.h
src/common/kernel-consumer/kernel-consumer.c
src/common/kernel-consumer/kernel-consumer.h
src/common/kernel-ctl/kernel-ctl.c
src/common/kernel-ctl/kernel-ctl.h
src/common/kernel-ctl/kernel-ioctl.h
src/common/lttng-kernel.h
src/common/macros.h
src/common/runas.c
src/common/runas.h
src/common/sessiond-comm/sessiond-comm.c
src/common/sessiond-comm/sessiond-comm.h
src/common/ust-consumer/ust-consumer.c
src/common/ust-consumer/ust-consumer.h
src/lib/lttng-ctl/lttng-ctl.c
tests/Makefile.am
tests/lttng/kernel_all_events_basic.c
tests/lttng/kernel_event_basic.c
tests/lttng/ust_global_all_events_basic.c
tests/lttng/ust_global_event_basic.c
tests/test_kernel_data_trace.c
tests/test_sessions.c
tests/test_ust_data_trace.c
tests/ust-nevents/Makefile.am
tests/ust-nprocesses/Makefile.am
tests/ust-nprocesses/run

index 4f4705d2a966273e091d6f1f1db091f0f236b930..a459d3fd82c4e602b74cdee1ae69c3722fc275d7 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,84 @@
+2012-03-20 lttng-tools 2.0.0
+       * Fist STABLE version
+       * Add version name: Annedd'ale
+
+2012-03-20 lttng-tools 2.0.0-rc4
+       * Fix: add small detail to enable-channel man page
+       * Fix: warned of arbitrary time for ust-nprocesses test
+       * Fix. add limitation to man page
+       * Fix: minor changes to lttng.1
+       * Fix: add exit values to lttng.1 man page
+       * Fix: add delay before validating apps in test nproc
+       * Fix: error handling in lttng enable-event
+       * Fix: document structure init. to 0 in lttng.h
+       * Fix: uninitialized variable
+       * Keep track of FD used for UST applications (v2)
+       * Fix: lttng view, error message and exit code
+       * Small fixes to lttng man pages (v2)
+       * Fix: handle EINTR for sendmsg syscall
+       * Fix: lttng UI exit value and error message
+       * Fix: session lock use after free
+       * Fix kernel_list_events memleaks
+       * Fix debug message use uninitialized variable
+       * Fix: trace_ust_destroy_metadata should check for NULL pointer
+       * Fix: various memleaks
+       * Fix: hash table allocation out of order on error
+       * fix: lttng_ht_destroy memleak
+
+2012-03-16 lttng-tools 2.0.0-rc3
+       * Fix: missing headers for make dist
+       * Fix: install lttng-consumerd in lib/lttng/libexec/
+       * Fix: Redefine MAP_STACK to 0 if not defined by the architecture
+       * Fix: consumer CPU hotplug support
+       * Fix: double PID registration race
+       * Make libcompat independent not to confuse automake
+       * Clarify the license of lttng-ust-abi.h
+       * Fix: License header
+       * Fix: wrong return value on consumer socket creation
+       * Fix: test for UST invalid channel parameters at channel creation
+       * Fix: recvmsg should handle EINTR
+       * Fix: error.h non-static variables for liblttng-ctl
+       * Fix: missing _GNU_SOURCE define
+       * Fix: improve need root for kernel tracing error message
+       * Fix: start/stop lttng message error
+
+2012-03-02 lttng-tools 2.0.0-rc2
+       * Fix: meaningful error message
+       * Fix: UST consumer need to iterate on streams, just change their key
+       * Fix: add missing rcu read lock across RCU HT iteration
+       * Fix: kernel session closes fd 0 after create
+       * Fix: sendmsg EPIPE should be quiet by default (expected)
+       * Fix: thread_registration_apps should set its local sock to -1 when passing it
+       * Fix: clock -> sock typo
+       * Fix: consumer race: should allow reuse of FD key
+       * Fix: Use PERROR all across lttng-tools, never make it quiet
+       * Fix: test all close return values in sessiond
+       * Fix: All perror turned into PERROR to show file and line number
+       * Fix: large audit of close() use in sessiond main.c
+       * Fix: main.c client/apps sockets and kernel_trace_fd close(0)
+       * Fix: incorrect close of fd 0 for syscall kernel event destroy
+       * Fix: sessiond has incorrect missing 0 value in FD check
+       * Fix: sessiond app listening: use posix-compliant poll flags
+       * Fix: consumer printf type should match ssize_t (%zd)
+       * Fix: make ust consumer posix compliant for poll flags
+       * Fix security permission on lttng run directory
+       * Fix: Display right loglevel_type in error message
+       * Fix documentation in lttng.h
+       * Fix: lttng UST and kernel consumer: fix ret vs errno mixup
+       * Fix: restart consumerd and sessiond when interrupted in poll()
+       * Fix: handling bad channel when sending to consumer
+       * Fix useless variable
+       * Fix add-context returned error
+       * fix: add missing break in command handling
+       * fix: command handling: do not check domain for commands not requiring domain
+       * fix: if tracing group does not exist, do not report a client error
+       * Fix: run_as error handling
+       * Fix usage note on -a
+       * Revert FreeBSD compatibility layer
+       * Fix: documented number of subbuffers is incorrect
+       * Document that num-subbuf and subbuf-size need to be power of 2
+       * Merge branch 'master' of git://git.lttng.org/lttng-tools
+
 2012-02-20 lttng-tools 2.0.0-rc1
        * Fix lttcomm_close_unix_sock to actually close the socket
        * lttng-sessiond: Set group permissions explicitly
diff --git a/LICENSE b/LICENSE
index afc760369c13f29b9a38e0d89ad5db1b56392622..18d5896b8025b116258161b14535005abd977bea 100644 (file)
--- a/LICENSE
+++ b/LICENSE
@@ -7,8 +7,8 @@ July 18, 2011
 The library part is distributed under LGPLv2.1. See lgpl-2.1.txt for details.
 This applies to:
 
--) lttng.h
--) liblttngctl.c
+-) include/lttng/lttng.h
+-) src/lib/lttng-ctl/lttng-ctl.c
 
 LGPL-compatible source code can statically use the library header using:
 
index 322d9f21e17df45608054eda6ae04f4f9b244679..e765c15b965cac101f6b13787b7118e3a72a0879 100644 (file)
@@ -1,4 +1,4 @@
-AC_INIT([lttng-tools],[2.0.0-rc1],[dgoulet@efficios.com],[],[http://lttng.org])
+AC_INIT([lttng-tools],[2.0.0],[dgoulet@efficios.com],[],[http://lttng.org])
 AC_CONFIG_AUX_DIR([config])
 AC_CANONICAL_TARGET
 AC_CANONICAL_HOST
@@ -6,6 +6,12 @@ AC_CONFIG_MACRO_DIR([config])
 AM_INIT_AUTOMAKE([foreign dist-bzip2 no-dist-gzip])
 m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
 
+version_name="Annedd'ale"
+version_description="New type of beer, 100% from Quebec, flavored with sapin beaumier needles, with a touch of hops."
+
+AC_DEFINE_UNQUOTED([VERSION_NAME], ["$version_name"], "")
+AC_DEFINE_UNQUOTED([VERSION_DESCRIPTION], ["$version_description"], "")
+
 AC_CONFIG_HEADERS([include/config.h])
 
 AC_CHECK_HEADERS([ \
@@ -121,6 +127,24 @@ AM_CONDITIONAL([HAVE_LIBLTTNG_UST_CTL], [ test "x$ac_cv_lib_lttng_ust_ctl_ustctl
 
 AC_CHECK_FUNCS([sched_getcpu sysconf])
 
+# check for dlopen
+AC_CHECK_LIB([dl], [dlopen],
+[
+       have_libdl=yes
+],
+[
+       #libdl not found, check for dlopen in libc.
+       AC_CHECK_LIB([c], [dlopen],
+       [
+               have_libc_dl=yes
+       ],
+       [
+               AC_MSG_ERROR([Cannot find dlopen in libdl nor libc. Use [LDFLAGS]=-Ldir to specify their location.])
+       ])
+])
+AM_CONDITIONAL([LTTNG_TOOLS_BUILD_WITH_LIBDL], [test "x$have_libdl" = "xyes"])
+AM_CONDITIONAL([LTTNG_TOOLS_BUILD_WITH_LIBC_DL], [test "x$have_libc_dl" = "xyes"])
+
 # Option to only build the consumer daemon and its libraries
 AC_ARG_WITH([consumerd-only],
        AS_HELP_STRING([--with-consumerd-only],[Only build the consumer daemon [default=no]]),
@@ -152,6 +176,9 @@ lttngincludedir="${includedir}/lttng"
 AC_SUBST(lttngincludedir)
 AC_SUBST(DEFAULT_INCLUDES)
 
+lttnglibexecdir="${libdir}/lttng/libexec"
+AC_SUBST(lttnglibexecdir)
+
 AC_CONFIG_FILES([
        Makefile
        doc/Makefile
@@ -165,6 +192,7 @@ AC_CONFIG_FILES([
        src/common/ust-consumer/Makefile
        src/common/hashtable/Makefile
        src/common/sessiond-comm/Makefile
+       src/common/compat/Makefile
        src/lib/Makefile
        src/lib/lttng-ctl/Makefile
        src/bin/Makefile
@@ -183,6 +211,11 @@ AC_OUTPUT
 #
 AS_ECHO()
 
+AS_ECHO("Version name: $version_name")
+AS_ECHO("$version_description")
+
+AS_ECHO()
+
 # Target architecture we're building for
 target_arch=$host_cpu
 [
@@ -225,7 +258,7 @@ AS_IF([test "x$consumerd_only" = "xno"],[
        AS_ECHO("The sessiond daemon will look in the following directories: ")
        AS_ECHO_N("32-bit consumerd executable at: ")
        AS_IF([test "$CONSUMERD32_BIN" = ""],[
-               AS_ECHO_N("`eval eval echo $bindir`")
+               AS_ECHO_N("`eval eval echo $lttnglibexecdir`")
                AS_ECHO("/lttng-consumerd")
        ],[
                AS_ECHO("$CONSUMERD32_BIN")
@@ -240,7 +273,7 @@ AS_IF([test "x$consumerd_only" = "xno"],[
 
        AS_ECHO_N("64-bit consumerd executable at: ")
        AS_IF([test "$CONSUMERD64_BIN" = ""],[
-               AS_ECHO_N("`eval eval echo $bindir`")
+               AS_ECHO_N("`eval eval echo $lttnglibexecdir`")
                AS_ECHO("/lttng-consumerd")
        ],[
                AS_ECHO("$CONSUMERD64_BIN")
index 8a235f94130dcb2c5353807d374cd49719d4526a..b8b9906adcabc6dbb23b68b92dd1dad53b406d3e 100644 (file)
@@ -17,22 +17,22 @@ It's tracers help tracking down performance issues and debugging problems
 involving multiple concurrent processes and threads. Tracing across multiple
 systems is also possible.
 
-The session daemon,  acting as a tracing registry, allow you to interact with
+The session daemon, acting as a tracing registry, allow you to interact with
 multiple tracers (kernel and user-space) inside the same container, a tracing
 session. Trace can be gathered from the kernel and/or instrumented applications
-(lttng-ust(3)). Aggregating those traces is done using the babeltrace(1) text
-viewer.
+(lttng-ust(3)). Aggregating those traces is done using a viewer, like the
+babeltrace(1) text viewer.
 
 In order to trace the kernel, the session daemon needs to be running as root.
 LTTng provides the use of a \fBtracing group\fP (default: tracing). Whomever is
 in that group can interact with the root session daemon and thus trace the
 kernel. Session daemons can co-exist meaning that you can have a session daemon
-running as Alice that can be use to trace her applications along side with a
-root daemon or even a Bob daemon. We highly recommand to start the session
+running as Alice that can be used to trace her applications along side with a
+root daemon or even a Bob daemon. We highly recommend to start the session
 daemon at boot time for stable and long term tracing.
 
 The session daemon is in charge of managing trace data consumers by spawning
-one when the time as come. The user don't need to manage the lttng-consumerd.
+them when the time has come. The user don't need to manage the lttng-consumerd.
 .SH "OPTIONS"
 
 .PP
@@ -66,7 +66,7 @@ Show version number
 Send SIGCHLD to parent pid to notify readiness.
 
 This is used by \fBlttng(1)\fP to get notified when the session daemon is ready
-to accept command. By building a third part tool over liblttng-ctl, this option
+to accept command. When building a third party tool over liblttng-ctl, this option
 can be very handy to synchronize the control tool and the session daemon.
 .TP
 .BR "-q, --quiet"
@@ -113,31 +113,47 @@ Specify path for the 64-bit UST consumer daemon libraries
 .SH "ENVIRONMENT VARIABLES"
 
 .PP
-Note that all command line options will override environmenal variables.
+Note that all command line options will override environment variables.
 .PP
 
 .PP
 .IP "LTTNG_CONSUMERD32_BIN"
-Allow to specify the 32-bit consumer binary path. \fB--consumerd32-path\fP
+Specify the 32-bit consumer binary path. \fB--consumerd32-path\fP
 override this variable.
 .IP "LTTNG_CONSUMERD64_BIN"
-Allow to specify the 64-bit consumer binary path. \fB--consumerd64-path\fP
+Specify the 64-bit consumer binary path. \fB--consumerd64-path\fP
 override this variable.
 .IP "LTTNG_CONSUMERD32_LIBDIR"
-Allow to specifiy the 64-bit library path containing libconsumer.so.
+Specifiy the 64-bit library path containing libconsumer.so.
 \fB--consumerd32-libdir\fP override this variable.
 .IP "LTTNG_CONSUMERD64_LIBDIR"
-Allow to specifiy the 32-bit library path containing libconsumer.so.
+Specifiy the 32-bit library path containing libconsumer.so.
 \fB--consumerd64-libdir\fP override this variable.
+.IP "LTTNG_DEBUG_NOCLONE"
+Debug-mode disabling use of clone/fork. Insecure, but required to allow
+debuggers to work with sessiond on some operating systems.
 .SH "SEE ALSO"
 
 .PP
 babeltrace(1), lttng-ust(3), lttng(1)
 .PP
+
+.SH "LIMITATIONS"
+
+.PP
+For unprivileged user running lttng-sessiond, the maximum number of file
+descriptors per process is usually 1024. This limits the number of traceable
+applications since for each instrumented application there is two file
+descriptors per-CPU and one more socktet for bidirectional communication.
+
+For the root user, the limit is bumped to 65535. Future version will deal with
+this limitation.
+.PP
+
 .SH "BUGS"
 
 .PP
-No show stopper bugs known yet at this stable version.
+No show stopper bugs are known yet in this version.
 
 If you encounter any issues or usability problem, please report it on our
 mailing list <lttng-dev@lists.lttng.org> to help improve this project.
@@ -160,8 +176,8 @@ You can find us on IRC server irc.oftc.net (OFTC) in #lttng.
 
 .PP
 Thanks to Yannick Brosseau without whom this project would never have been so
-lean and mean! Also thanks to the Ericsson teams working on tracing which help
-us greatly with detailled bug reports and unsual use cases.
+lean and mean! Also thanks to the Ericsson teams working on tracing which helped
+us greatly with detailed bug reports and unusual test cases.
 
 Thanks to our beloved packager Alexandre Montplaisir-Goncalves (Ubuntu and PPA
 maintainer) and Jon Bernard for our Debian packages.
index 827c63c18132433028c7e165dcef400ed5736905..654be5ef5ee360ecd1879c96694bd37238b2e09f 100644 (file)
@@ -17,7 +17,7 @@ It's tracers help tracking down performance issues and debugging problems
 involving multiple concurrent processes and threads. Tracing across multiple
 systems is also possible.
 
-The \fBlttng\fP command line tool from lttng-tools package is used to control
+The \fBlttng\fP command line tool from the lttng-tools package is used to control
 both kernel and user-space tracing. Every interactions with the tracer should
 be done by this tool or by the liblttng-ctl provided with the lttng-tools
 package.
@@ -32,8 +32,8 @@ In order to trace the kernel, the session daemon needs to be running as root.
 LTTng provides the use of a \fBtracing group\fP (default: tracing). Whomever is
 in that group can interact with the root session daemon and thus trace the
 kernel. Session daemons can co-exist meaning that you can have a session daemon
-running as Alice that can be use to trace her applications along side with a
-root daemon or even a Bob daemon. We highly recommand to start the session
+running as Alice that can be used to trace her applications along side with a
+root daemon or even a Bob daemon. We highly recommend to start the session
 daemon at boot time for stable and long term tracing.
 
 Every user-space applications instrumented with lttng-ust(3), will
@@ -53,7 +53,8 @@ Show summary of possible options and commands.
 .TP
 .BR "\-v, \-\-verbose"
 Increase verbosity.
-FIXME : details (\-v : sessiond verbose, \-vv : consumerd verbose, etc) ?
+Three levels of verbosity are available which are triggered by putting additional v to
+the option (\-vv or \-vvv)
 .TP
 .BR "\-q, \-\-quiet"
 Suppress all messages (even errors).
@@ -205,7 +206,7 @@ aggregating multiple tracing sources.
 
 On creation, a \fB.lttngrc\fP file is created in your $HOME directory
 containing the current session name. If NAME is omitted, a session name is
-automatically created having this form: 'auto-yyyymmdd-hhmms'.
+automatically created having this form: 'auto-yyyymmdd-hhmmss'.
 
 If no \fB\-o, \-\-output\fP is specified, the traces will be written in
 $HOME/lttng-traces.
@@ -248,6 +249,8 @@ If NAME is omitted, the session name is taken from the .lttngrc file.
 .nf
 Enable tracing channel
 
+To enable event, you must first enable a channel which contains event(s).
+
 If \fB\-s, \-\-session\fP is omitted, the session name is taken from the .lttngrc
 file.
 .fi
@@ -273,7 +276,7 @@ file.
 \-\-subbuf-size
         Subbuffer size in bytes (default: 4096, kernel default: 262144)
 \-\-num-subbuf
-        Number of subbufers (default: 4)
+        Number of subbuffers (default: 4)
         Needs to be a power of 2 for kernel and ust tracers
 \-\-switch-timer
         Switch subbuffer timer interval in usec (default: 0)
@@ -395,6 +398,10 @@ List tracing session information.
 
 With no arguments, it will list available tracing session(s).
 
+With the session name, it will display the details of the session including
+the trace file path, the associated channels and their state (activated
+and deactivated), the activated events and more.
+
 With \-k alone, it will list all available kernel events (except the system
 calls events).
 With \-u alone, it will list all available user-space events from registered
@@ -416,7 +423,7 @@ You can now enable any event listed by using the name :
 \-\-list-options
         Simple listing of options
 \-k, \-\-kernel
-        Select kernel domain (FIXME : apparition de la notion de "domain" ici)
+        Select kernel domain
 \-u, \-\-userspace
         Select user-space domain.
 
@@ -507,8 +514,8 @@ View traces of a tracing session
 
 By default, the babeltrace viewer will be used for text viewing.
 
-The SESSION_NAME is an optional session name. If not specified, lttng will get
-it from the configuration file (.lttngrc).
+If SESSION_NAME is omitted, the session name is taken from the .lttngrc file.
+
 .fi
 
 .B OPTIONS:
@@ -528,6 +535,111 @@ it from the configuration file (.lttngrc).
         to the arguments
 .fi
 
+.SH "EXIT VALUES"
+
+.IP "0"
+Success
+
+.IP "1"
+Command error
+
+.IP "2"
+Undefined command
+
+.IP "3"
+Fatal error
+
+.IP "4"
+Command warning
+
+.IP "16"
+No session found by the name given
+
+.IP "18"
+Error in session creation
+
+.IP "21"
+Error in application(s) listing
+
+.IP "28"
+Session name already exists
+
+.IP "33"
+Kernel tracer unavailable
+
+.IP "35"
+Kernel event exists
+
+.IP "37"
+Kernel channel exists
+
+.IP "38"
+Kernel channel creation failed
+
+.IP "39"
+Kernel channel not found
+
+.IP "40"
+Kernel channel disable failed
+
+.IP "41"
+Kernel channel enable failed
+
+.IP "42"
+Kernel context failed
+
+.IP "43"
+Kernel enable event failed
+
+.IP "44"
+Kernel disable event failed
+
+.IP "53"
+Kernel listing events failed
+
+.IP "60"
+UST channel disable failed
+
+.IP "61"
+UST channel enable failed
+
+.IP "62"
+UST adding context failed
+
+.IP "63"
+UST event enable failed
+
+.IP "64"
+UST event disable failed
+
+.IP "66"
+UST start failed
+
+.IP "67"
+UST stop failed
+
+.IP "75"
+UST event exists
+
+.IP "76"
+UST event not found
+
+.IP "77"
+UST context exists
+
+.IP "78"
+UST invalid context
+
+.IP "79"
+Tracing the kernel requires a root lttng-sessiond daemon and "tracing" group
+user membership.
+
+.IP "80"
+Tracing already started
+
+.IP "81"
+Tracing already stopped
+.PP
 .SH "ENVIRONMENT VARIABLES"
 
 .PP
@@ -546,7 +658,7 @@ babeltrace(1), lttng-ust(3), lttng-sessiond(8)
 .SH "BUGS"
 
 .PP
-No show stopper bugs known yet at this stable version.
+No show stopper bugs are known yet in this version.
 
 If you encounter any issues or usability problem, please report it on our
 mailing list <lttng-dev@lists.lttng.org> to help improve this project.
@@ -570,7 +682,7 @@ You can find us on IRC server irc.oftc.net (OFTC) in #lttng.
 .PP
 Thanks to Yannick Brosseau without whom this project would never have been so
 lean and mean! Also thanks to the Ericsson teams working on tracing which
-helped us greatly with detailled bug reports and unusual test cases.
+helped us greatly with detailed bug reports and unusual test cases.
 
 Thanks to our beloved packager Alexandre Montplaisir-Goncalves (Ubuntu and PPA
 maintainer) and Jon Bernard for our Debian packages.
index 065caee9146a12d2bf9f63dfff3aa0511c611641..f621fa80dad58f2b299e5ffaf073598f4d016222 100644 (file)
@@ -6,8 +6,8 @@
  * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
  *
  * 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; only version 2.1 of the License.
+ * under the terms of the GNU Lesser General Public License, version 2.1 only,
+ * as published by the Free Software Foundation.
  *
  * This library is distributed in the hope that it will be useful, but WITHOUT
  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
@@ -124,6 +124,9 @@ enum lttng_calibrate_type {
        LTTNG_CALIBRATE_FUNCTION              = 0,
 };
 
+/*
+ * The structures should be initialized to zero before use.
+ */
 #define LTTNG_DOMAIN_PADDING1              16
 #define LTTNG_DOMAIN_PADDING2              LTTNG_SYMBOL_NAME_LEN + 32
 struct lttng_domain {
@@ -137,7 +140,11 @@ struct lttng_domain {
        } attr;
 };
 
-/* Perf counter attributes */
+/*
+ * Perf counter attributes
+ *
+ * The structures should be initialized to zero before use.
+ */
 #define LTTNG_PERF_EVENT_PADDING1          16
 struct lttng_event_perf_counter_ctx {
        uint32_t type;
@@ -147,7 +154,11 @@ struct lttng_event_perf_counter_ctx {
        char padding[LTTNG_PERF_EVENT_PADDING1];
 };
 
-/* Event/Channel context */
+/*
+ * Event/channel context
+ *
+ * The structures should be initialized to zero before use.
+ */
 #define LTTNG_EVENT_CONTEXT_PADDING1       16
 #define LTTNG_EVENT_CONTEXT_PADDING2       LTTNG_SYMBOL_NAME_LEN + 32
 struct lttng_event_context {
@@ -164,6 +175,8 @@ struct lttng_event_context {
  * Event probe.
  *
  * Either addr is used or symbol_name and offset.
+ *
+ * The structures should be initialized to zero before use.
  */
 #define LTTNG_EVENT_PROBE_PADDING1         16
 struct lttng_event_probe_attr {
@@ -177,6 +190,8 @@ struct lttng_event_probe_attr {
 
 /*
  * Function tracer
+ *
+ * The structures should be initialized to zero before use.
  */
 #define LTTNG_EVENT_FUNCTION_PADDING1      16
 struct lttng_event_function_attr {
@@ -187,6 +202,8 @@ struct lttng_event_function_attr {
 
 /*
  * Generic lttng event
+ *
+ * The structures should be initialized to zero before use.
  */
 #define LTTNG_EVENT_PADDING1               16
 #define LTTNG_EVENT_PADDING2               LTTNG_SYMBOL_NAME_LEN + 32
@@ -213,6 +230,8 @@ struct lttng_event {
 
 /*
  * Tracer channel attributes. For both kernel and user-space.
+ *
+ * The structures should be initialized to zero before use.
  */
 #define LTTNG_CHANNEL_ATTR_PADDING1        LTTNG_SYMBOL_NAME_LEN + 32
 struct lttng_channel_attr {
@@ -228,6 +247,8 @@ struct lttng_channel_attr {
 
 /*
  * Channel information structure. For both kernel and user-space.
+ *
+ * The structures should be initialized to zero before use.
  */
 #define LTTNG_CHANNEL_PADDING1             16
 struct lttng_channel {
@@ -251,6 +272,8 @@ struct lttng_calibrate {
  * This is an 'output data' meaning that it only comes *from* the session
  * daemon *to* the lttng client. It's basically a 'human' representation of
  * tracing entities (here a session).
+ *
+ * The structures should be initialized to zero before use.
  */
 #define LTTNG_SESSION_PADDING1             16
 struct lttng_session {
@@ -264,6 +287,8 @@ struct lttng_session {
 
 /*
  * Handle used as a context for commands.
+ *
+ * The structures should be initialized to zero before use.
  */
 #define LTTNG_HANDLE_PADDING1              16
 struct lttng_handle {
@@ -416,7 +441,7 @@ extern int lttng_add_context(struct lttng_handle *handle,
                const char *channel_name);
 
 /*
- * Create or enable a kernel event (or events) for a channel.
+ * Create or enable an event (or events) for a channel.
  *
  * If the event you are trying to enable does not exist, it will be created,
  * else it is enabled.
@@ -427,14 +452,14 @@ extern int lttng_enable_event(struct lttng_handle *handle,
                struct lttng_event *ev, const char *channel_name);
 
 /*
- * Create or enable a kernel channel.
+ * Create or enable a channel.
  * The channel name cannot be NULL.
  */
 extern int lttng_enable_channel(struct lttng_handle *handle,
                struct lttng_channel *chan);
 
 /*
- * Disable kernel event(s) of a channel and domain.
+ * Disable event(s) of a channel and domain.
  *
  * If event_name is NULL, all events are disabled.
  * If channel_name is NULL, the default channel is used (channel0).
@@ -443,7 +468,7 @@ extern int lttng_disable_event(struct lttng_handle *handle,
                const char *name, const char *channel_name);
 
 /*
- * Disable kernel channel.
+ * Disable channel.
  *
  * The channel name cannot be NULL.
  */
index 470c8c17a1ac597c0d40b83f26f200895ac2f9c3..acd58cdc398b4f4ae882aca010d37e78835131e9 100644 (file)
@@ -1,6 +1,6 @@
 AM_CPPFLAGS =
 
-bin_PROGRAMS = lttng-consumerd
+lttnglibexec_PROGRAMS = lttng-consumerd
 
 lttng_consumerd_SOURCES = lttng-consumerd.c lttng-consumerd.h
 
index 7e3bf3cfbad8c99976cd5b1e8813ad2adfa882a5..32571bddf36cfc94483eaf0f180694ac21a99fae 100644 (file)
@@ -2,19 +2,18 @@
  * Copyright (C) 2011 - Julien Desfossez <julien.desfossez@polymtl.ca>
  *                      Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; only version 2
- * of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
  * This program 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 General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #define _GNU_SOURCE
@@ -58,8 +57,8 @@ static pthread_t threads[2];
 static int sigintcount = 0;
 
 /* Argument variables */
-int opt_quiet;
-int opt_verbose;
+int lttng_opt_quiet;    /* not static in error.h */
+int lttng_opt_verbose;  /* not static in error.h */
 static int opt_daemon;
 static const char *progname;
 static char command_sock_path[PATH_MAX]; /* Global command socket path */
@@ -199,10 +198,10 @@ static void parse_args(int argc, char **argv)
                        usage(stdout);
                        exit(EXIT_SUCCESS);
                case 'q':
-                       opt_quiet = 1;
+                       lttng_opt_quiet = 1;
                        break;
                case 'v':
-                       opt_verbose = 1;
+                       lttng_opt_verbose = 1;
                        break;
                case 'V':
                        fprintf(stdout, "%s\n", VERSION);
index 872a3e9169dae546c35222951d94ce0ec051dfc4..9b34547c19f5718fc3a86c33361da2e897c1592e 100644 (file)
@@ -2,19 +2,18 @@
  * Copyright (C) 2011 - Julien Desfossez <julien.desfossez@polymtl.ca>
  *                      David Goulet <david.goulet@polymtl.ca>
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; only verion 2
- * of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
  * This program 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 General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #ifndef _LTTNG_CONSUMERD_H
index 1e449476c6323b1cddf31b11f1b5735d76373985..bc99f9b4a4e8d660fe9680e2543ee4dd12d32740 100644 (file)
@@ -1,5 +1,6 @@
+<<<<<<< HEAD
 AM_CPPFLAGS = -I$(top_srcdir)/benchmark \
-                         -DINSTALL_BIN_PATH=\""$(bindir)"\" \
+                         -DINSTALL_BIN_PATH=\""$(lttnglibexecdir)"\" \
                          -DINSTALL_LIB_PATH=\""$(libdir)"\"
 
 AM_CFLAGS = -fno-strict-aliasing
@@ -17,7 +18,8 @@ lttng_sessiond_SOURCES = utils.c utils.h \
                        shm.c shm.h \
                        session.c session.h \
                        modprobe.c modprobe.h kern-modules.h \
-                       lttng-ust-ctl.h lttng-ust-abi.h
+                       lttng-ust-ctl.h lttng-ust-abi.h \
+                       fd-limit.c fd-limit.h
 
 if HAVE_LIBLTTNG_UST_CTL
 lttng_sessiond_SOURCES += trace-ust.c ust-app.c ust-consumer.c ust-consumer.h
@@ -33,8 +35,8 @@ lttng_sessiond_LDADD = -lrt -lurcu-common -lurcu \
                $(top_builddir)/src/common/kernel-ctl/libkernel-ctl.la \
                $(top_builddir)/src/common/hashtable/libhashtable.la \
                $(top_builddir)/src/common/libcommon.la \
-               $(top_builddir)/benchmark/liblttng-benchmark.la \
-               $(top_builddir)/src/common/libcompat.la
+               $(top_builddir)/src/common/compat/libcompat.la \
+               $(top_builddir)/benchmark/liblttng-benchmark.la
 
 if HAVE_LIBLTTNG_UST_CTL
 lttng_sessiond_LDADD += -llttng-ust-ctl
index 54345d9c94bfa96a70ab9cd0ab6ffb925a9d4953..4ec12302b027e83ea3f63b5da862ce04737ecab0 100644 (file)
@@ -1,18 +1,18 @@
 /*
  * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
  *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; only version 2 of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
- * This program 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 General Public License for
- * more details.
+ * This program 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 General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place - Suite 330, Boston, MA  02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #define _GNU_SOURCE
@@ -121,6 +121,9 @@ int channel_kernel_enable(struct ltt_kernel_session *ksession,
                        ret = LTTCOMM_KERN_CHAN_ENABLE_FAIL;
                        goto error;
                }
+       } else {
+               ret = LTTCOMM_KERN_CHAN_EXIST;
+               goto error;
        }
 
        ret = LTTCOMM_OK;
@@ -179,6 +182,7 @@ int channel_ust_enable(struct ltt_ust_session *usess, int domain,
        /* If already enabled, everything is OK */
        if (uchan->enabled) {
                DBG3("Channel %s already enabled. Skipping", uchan->name);
+               ret = LTTCOMM_UST_CHAN_EXIST;
                goto end;
        }
 
@@ -235,6 +239,21 @@ int channel_ust_create(struct ltt_ust_session *usess, int domain,
                attr = defattr;
        }
 
+       /*
+        * Validate UST buffer size and number of buffers: must both be
+        * power of 2 and nonzero. We validate right here for UST,
+        * because applications will not report the error to the user
+        * (unlike kernel tracing).
+        */
+       if (!attr->attr.subbuf_size || (attr->attr.subbuf_size & (attr->attr.subbuf_size - 1))) {
+               ret = LTTCOMM_INVALID;
+               goto error;
+       }
+       if (!attr->attr.num_subbuf || (attr->attr.num_subbuf & (attr->attr.num_subbuf - 1))) {
+               ret = LTTCOMM_INVALID;
+               goto error;
+       }
+
        /* Create UST channel */
        uchan = trace_ust_create_channel(attr, usess->pathname);
        if (uchan == NULL) {
index 04052f6d728592e91ffedd91a48dc355b3073456..75953a88ce7f615dd83a84b8c11ee2fdba32ddfc 100644 (file)
@@ -1,18 +1,18 @@
 /*
  * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
  *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; only version 2 of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
- * This program 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 General Public License for
- * more details.
+ * This program 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 General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place - Suite 330, Boston, MA  02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #ifndef _LTT_CHANNEL_H
index 9727258bf130b0f8912a9edb67f0c6a77f3aa4f8..af1c32dea90b6f64078b08c36fcffa65d21441be 100644 (file)
@@ -1,18 +1,18 @@
 /*
  * Copyright (C)  2011 - David Goulet <david.goulet@polymtl.ca>
  *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; only version 2 of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
- * This program 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 General Public License for
- * more details.
+ * This program 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 General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place - Suite 330, Boston, MA  02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #define _GNU_SOURCE
@@ -337,7 +337,7 @@ int context_ust_add(struct ltt_ust_session *usess, int domain,
                struct lttng_event_context *ctx, char *event_name,
                char *channel_name)
 {
-       int ret = LTTCOMM_OK, have_event = 0, no_chan = 1;
+       int ret = LTTCOMM_OK, have_event = 0;
        struct lttng_ht_iter iter;
        struct lttng_ht *chan_ht;
        struct ltt_ust_channel *uchan = NULL;
@@ -409,7 +409,6 @@ int context_ust_add(struct ltt_ust_session *usess, int domain,
        } else if (!uchan && !have_event) {     /* Add ctx all events, all channels */
                /* For all channels */
                cds_lfht_for_each_entry(chan_ht->ht, &iter.iter, uchan, node.node) {
-                       no_chan = 0;
                        ret = add_uctx_to_channel(usess, domain, uchan, ctx);
                        if (ret < 0) {
                                ERR("Context failed for channel %s", uchan->name);
@@ -437,10 +436,6 @@ end:
                break;
        }
 
-       if (no_chan) {
-               ret = LTTCOMM_UST_CHAN_NOT_FOUND;
-       }
-
 error:
        return ret;
 }
index 4383f9abc0dd1cb490da15c52e4c0bcdc3f18e30..83c3c83100cbb2786c49fd226ff3c9b4ff53d01e 100644 (file)
@@ -1,18 +1,18 @@
 /*
  * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
  *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; only version 2 of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
- * This program 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 General Public License for
- * more details.
+ * This program 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 General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place - Suite 330, Boston, MA  02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #ifndef _LTT_CONTEXT_H
index 7cffe982096c8aee60cc3cb6f4274df88a5f4650..ac4b0b4a365f7f493973f7389cd58f241c8292ae 100644 (file)
@@ -1,18 +1,18 @@
 /*
  * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
  *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; only version 2 of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
- * This program 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 General Public License for
- * more details.
+ * This program 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 General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place - Suite 330, Boston, MA  02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #define _GNU_SOURCE
@@ -147,7 +147,12 @@ int event_kernel_enable_tracepoint(struct ltt_kernel_session *ksession,
                        ret = LTTCOMM_KERN_ENABLE_FAIL;
                        goto end;
                }
+       } else {
+               /* At this point, the event is considered enabled */
+               ret = LTTCOMM_KERN_EVENT_EXIST;
+               goto end;
        }
+
        ret = LTTCOMM_OK;
 end:
        return ret;
index 6103240b313d2f0a9d028a85cd503618d2cfd3b9..b606d76333430cd79821737624fc64dea1bfe56f 100644 (file)
@@ -1,18 +1,18 @@
 /*
  * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
  *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; only version 2 of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
- * This program 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 General Public License for
- * more details.
+ * This program 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 General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place - Suite 330, Boston, MA  02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #ifndef _LTT_EVENT_H
diff --git a/src/bin/lttng-sessiond/fd-limit.c b/src/bin/lttng-sessiond/fd-limit.c
new file mode 100644 (file)
index 0000000..a886d33
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2012 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#define _GNU_SOURCE
+#include <urcu/uatomic.h>
+#include <sys/time.h>
+#include <sys/resource.h>
+#include <errno.h>
+#include <stdio.h>
+#include "fd-limit.h"
+
+/* total count of fd. */
+static long fd_count;
+
+/*
+ * threshold in % of number of fd allowed.
+ */
+static long fd_threshold[LTTNG_FD_NR_TYPES] = {
+       [LTTNG_FD_APPS] = 75,
+};
+
+static rlim_t max_nr_fd;
+
+int lttng_fd_get(enum lttng_fd_type type, unsigned int nr)
+{
+       long newval;
+
+       if (type >= LTTNG_FD_NR_TYPES) {
+               return -EINVAL;
+       }
+
+       newval = uatomic_add_return(&fd_count, (long) nr);
+       if ((long) (newval * 100)
+                       - (long) (max_nr_fd * fd_threshold[type]) > 0) {
+               uatomic_sub(&fd_count, (long) nr);
+               return -EPERM;
+       }
+       return 0;
+}
+
+void lttng_fd_put(enum lttng_fd_type type, unsigned int nr)
+{
+       uatomic_sub(&fd_count, (long) nr);
+}
+
+void lttng_fd_init(void)
+{
+       struct rlimit rlim;
+       int ret;
+
+       ret = getrlimit(RLIMIT_NOFILE, &rlim);
+       if (ret < 0) {
+               perror("getrlimit");
+       }
+       max_nr_fd = rlim.rlim_cur;
+}
diff --git a/src/bin/lttng-sessiond/fd-limit.h b/src/bin/lttng-sessiond/fd-limit.h
new file mode 100644 (file)
index 0000000..a3dc1a7
--- /dev/null
@@ -0,0 +1,30 @@
+#ifndef _LTTNG_FD_LIMIT_H
+#define _LTTNG_FD_LIMIT_H
+
+/*
+ * Copyright (C) 2012 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+enum lttng_fd_type {
+       LTTNG_FD_APPS,
+       LTTNG_FD_NR_TYPES,
+};
+
+int lttng_fd_get(enum lttng_fd_type type, unsigned int nr);
+void lttng_fd_put(enum lttng_fd_type type, unsigned int nr);
+void lttng_fd_init(void);
+
+#endif /* _LTTNG_FD_LIMIT_H */
index 0a8a2bb24f09bf1e7c5849e4bd2dfefa54dafdee..adfe66b1c29feb3295949253f315819c8d110d92 100644 (file)
@@ -2,19 +2,18 @@
  * Copyright (C)  2011 - David Goulet <david.goulet@polymtl.ca>
  *                       Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; only version 2
- * of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
  * This program 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
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #define _GNU_SOURCE
index a056ec22b6e28d813c8deeb1c8a87af924c08673..9bdb2c140f92b8d8f20da1fd46429040cb371d2b 100644 (file)
@@ -2,18 +2,18 @@
  * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
  *                      Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; only version 2 of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
- * This program 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 General Public License for
- * more details.
+ * This program 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 General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place - Suite 330, Boston, MA  02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #ifndef _LTT_FUTEX_H
index 5c4d5dd586520e5f720c658d938c29f6616ca95b..7ce8b0b68d803cc5e8f1e43f8e719f5b069d00cf 100644 (file)
@@ -1,18 +1,18 @@
 /*
  * Copyright (C) 2011 - David Goulet <dgoulet@efficios.com>
  *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; only version 2 of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
- * This program 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 General Public License for
- * more details.
+ * This program 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 General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place - Suite 330, Boston, MA  02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #ifndef _KERN_MODULES_H
index 8e960dfed8fe59786a3de2436aae3155db9851d6..596af588c5800c4bd6754bd9ec00de93b3381649 100644 (file)
@@ -1,19 +1,18 @@
 /*
  * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; only version 2
- * of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
  * This program 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 General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #define _GNU_SOURCE
@@ -26,6 +25,7 @@
 
 #include <common/common.h>
 #include <common/kernel-ctl/kernel-ctl.h>
+#include <common/sessiond-comm/sessiond-comm.h>
 
 #include "kernel.h"
 #include "kern-modules.h"
@@ -42,7 +42,7 @@ int kernel_add_channel_context(struct ltt_kernel_channel *chan,
        ret = kernctl_add_context(chan->fd, ctx);
        if (ret < 0) {
                if (errno != EEXIST) {
-                       perror("add context ioctl");
+                       PERROR("add context ioctl");
                } else {
                        /* If EEXIST, we just ignore the error */
                        ret = 0;
@@ -52,7 +52,7 @@ int kernel_add_channel_context(struct ltt_kernel_channel *chan,
 
        chan->ctx = zmalloc(sizeof(struct lttng_kernel_context));
        if (chan->ctx == NULL) {
-               perror("zmalloc event context");
+               PERROR("zmalloc event context");
                goto error;
        }
 
@@ -75,13 +75,13 @@ int kernel_add_event_context(struct ltt_kernel_event *event,
        DBG("Adding context to event %s", event->event->name);
        ret = kernctl_add_context(event->fd, ctx);
        if (ret < 0) {
-               perror("add context ioctl");
+               PERROR("add context ioctl");
                goto error;
        }
 
        event->ctx = zmalloc(sizeof(struct lttng_kernel_context));
        if (event->ctx == NULL) {
-               perror("zmalloc event context");
+               PERROR("zmalloc event context");
                goto error;
        }
 
@@ -112,7 +112,7 @@ int kernel_create_session(struct ltt_session *session, int tracer_fd)
        /* Kernel tracer session creation */
        ret = kernctl_create_session(tracer_fd);
        if (ret < 0) {
-               perror("ioctl kernel create session");
+               PERROR("ioctl kernel create session");
                goto error;
        }
 
@@ -120,7 +120,7 @@ int kernel_create_session(struct ltt_session *session, int tracer_fd)
        /* Prevent fd duplication after execlp() */
        ret = fcntl(lks->fd, F_SETFD, FD_CLOEXEC);
        if (ret < 0) {
-               perror("fcntl session fd");
+               PERROR("fcntl session fd");
        }
 
        lks->consumer_fds_sent = 0;
@@ -153,7 +153,7 @@ int kernel_create_channel(struct ltt_kernel_session *session,
        /* Kernel tracer channel creation */
        ret = kernctl_create_channel(session->fd, &lkc->channel->attr);
        if (ret < 0) {
-               perror("ioctl kernel create channel");
+               PERROR("ioctl kernel create channel");
                goto error;
        }
 
@@ -162,7 +162,7 @@ int kernel_create_channel(struct ltt_kernel_session *session,
        /* Prevent fd duplication after execlp() */
        ret = fcntl(lkc->fd, F_SETFD, FD_CLOEXEC);
        if (ret < 0) {
-               perror("fcntl session fd");
+               PERROR("fcntl session fd");
        }
 
        /* Add channel to session */
@@ -208,6 +208,11 @@ int kernel_create_event(struct lttng_event *ev,
         */
        if (ret == 0 && event->event->instrumentation == LTTNG_KERNEL_SYSCALL) {
                DBG2("Kernel event syscall creation success");
+               /*
+                * We use fd == -1 to ensure that we never trigger a close of fd
+                * 0.
+                */
+               event->fd = -1;
                goto add_list;
        }
 
@@ -215,7 +220,7 @@ int kernel_create_event(struct lttng_event *ev,
        /* Prevent fd duplication after execlp() */
        ret = fcntl(event->fd, F_SETFD, FD_CLOEXEC);
        if (ret < 0) {
-               perror("fcntl session fd");
+               PERROR("fcntl session fd");
        }
 
 add_list:
@@ -242,7 +247,7 @@ int kernel_disable_channel(struct ltt_kernel_channel *chan)
 
        ret = kernctl_disable(chan->fd);
        if (ret < 0) {
-               perror("disable chan ioctl");
+               PERROR("disable chan ioctl");
                ret = errno;
                goto error;
        }
@@ -265,7 +270,7 @@ int kernel_enable_channel(struct ltt_kernel_channel *chan)
 
        ret = kernctl_enable(chan->fd);
        if (ret < 0 && errno != EEXIST) {
-               perror("Enable kernel chan");
+               PERROR("Enable kernel chan");
                goto error;
        }
 
@@ -286,8 +291,15 @@ int kernel_enable_event(struct ltt_kernel_event *event)
        int ret;
 
        ret = kernctl_enable(event->fd);
-       if (ret < 0 && errno != EEXIST) {
-               perror("enable kernel event");
+       if (ret < 0) {
+               switch (errno) {
+               case EEXIST:
+                       ret = LTTCOMM_KERN_EVENT_EXIST;
+                       break;
+               default:
+                       PERROR("enable kernel event");
+                       break;
+               }
                goto error;
        }
 
@@ -308,8 +320,15 @@ int kernel_disable_event(struct ltt_kernel_event *event)
        int ret;
 
        ret = kernctl_disable(event->fd);
-       if (ret < 0 && errno != EEXIST) {
-               perror("disable kernel event");
+       if (ret < 0) {
+               switch (errno) {
+               case EEXIST:
+                       ret = LTTCOMM_KERN_EVENT_EXIST;
+                       break;
+               default:
+                       PERROR("disable kernel event");
+                       break;
+               }
                goto error;
        }
 
@@ -347,7 +366,7 @@ int kernel_open_metadata(struct ltt_kernel_session *session, char *path)
        /* Prevent fd duplication after execlp() */
        ret = fcntl(lkm->fd, F_SETFD, FD_CLOEXEC);
        if (ret < 0) {
-               perror("fcntl session fd");
+               PERROR("fcntl session fd");
        }
 
        session->metadata = lkm;
@@ -369,7 +388,7 @@ int kernel_start_session(struct ltt_kernel_session *session)
 
        ret = kernctl_start_session(session->fd);
        if (ret < 0) {
-               perror("ioctl start session");
+               PERROR("ioctl start session");
                goto error;
        }
 
@@ -392,7 +411,7 @@ void kernel_wait_quiescent(int fd)
 
        ret = kernctl_wait_quiescent(fd);
        if (ret < 0) {
-               perror("wait quiescent ioctl");
+               PERROR("wait quiescent ioctl");
                ERR("Kernel quiescent wait failed");
        }
 }
@@ -406,7 +425,7 @@ int kernel_calibrate(int fd, struct lttng_kernel_calibrate *calibrate)
 
        ret = kernctl_calibrate(fd, calibrate);
        if (ret < 0) {
-               perror("calibrate ioctl");
+               PERROR("calibrate ioctl");
                return -1;
        }
 
@@ -443,7 +462,7 @@ int kernel_flush_buffer(struct ltt_kernel_channel *channel)
                DBG("Flushing channel stream %d", stream->fd);
                ret = kernctl_buffer_flush(stream->fd);
                if (ret < 0) {
-                       perror("ioctl");
+                       PERROR("ioctl");
                        ERR("Fail to flush buffer for stream %d (ret: %d)",
                                        stream->fd, ret);
                }
@@ -483,10 +502,13 @@ int kernel_open_channel_stream(struct ltt_kernel_channel *channel)
        int ret;
        struct ltt_kernel_stream *lks;
 
-       while ((ret = kernctl_create_stream(channel->fd)) > 0) {
+       while ((ret = kernctl_create_stream(channel->fd)) >= 0) {
                lks = trace_kernel_create_stream();
                if (lks == NULL) {
-                       close(ret);
+                       ret = close(ret);
+                       if (ret) {
+                               PERROR("close");
+                       }
                        goto error;
                }
 
@@ -494,13 +516,13 @@ int kernel_open_channel_stream(struct ltt_kernel_channel *channel)
                /* Prevent fd duplication after execlp() */
                ret = fcntl(lks->fd, F_SETFD, FD_CLOEXEC);
                if (ret < 0) {
-                       perror("fcntl session fd");
+                       PERROR("fcntl session fd");
                }
 
                ret = asprintf(&lks->pathname, "%s/%s_%d",
                                channel->pathname, channel->channel->name, channel->stream_count);
                if (ret < 0) {
-                       perror("asprintf kernel create stream");
+                       PERROR("asprintf kernel create stream");
                        goto error;
                }
 
@@ -527,7 +549,7 @@ int kernel_open_metadata_stream(struct ltt_kernel_session *session)
 
        ret = kernctl_create_stream(session->metadata->fd);
        if (ret < 0) {
-               perror("kernel create metadata stream");
+               PERROR("kernel create metadata stream");
                goto error;
        }
 
@@ -536,7 +558,7 @@ int kernel_open_metadata_stream(struct ltt_kernel_session *session)
        /* Prevent fd duplication after execlp() */
        ret = fcntl(session->metadata_stream_fd, F_SETFD, FD_CLOEXEC);
        if (ret < 0) {
-               perror("fcntl session fd");
+               PERROR("fcntl session fd");
        }
 
        return 0;
@@ -550,7 +572,7 @@ error:
  */
 ssize_t kernel_list_events(int tracer_fd, struct lttng_event **events)
 {
-       int fd, pos;
+       int fd, pos, ret;
        char *event;
        size_t nbmem, count = 0;
        ssize_t size;
@@ -559,13 +581,13 @@ ssize_t kernel_list_events(int tracer_fd, struct lttng_event **events)
 
        fd = kernctl_tracepoint_list(tracer_fd);
        if (fd < 0) {
-               perror("kernel tracepoint list");
+               PERROR("kernel tracepoint list");
                goto error;
        }
 
        fp = fdopen(fd, "r");
        if (fp == NULL) {
-               perror("kernel tracepoint list fdopen");
+               PERROR("kernel tracepoint list fdopen");
                goto error_fp;
        }
 
@@ -575,34 +597,51 @@ ssize_t kernel_list_events(int tracer_fd, struct lttng_event **events)
         */
        nbmem = KERNEL_EVENT_INIT_LIST_SIZE;
        elist = zmalloc(sizeof(struct lttng_event) * nbmem);
+       if (elist == NULL) {
+               PERROR("alloc list events");
+               count = -ENOMEM;
+               goto end;
+       }
 
        while ((size = fscanf(fp, "event { name = %m[^;]; };%n\n", &event, &pos)) == 1) {
                if (count >= nbmem) {
+                       struct lttng_event *new_elist;
+
                        DBG("Reallocating event list from %zu to %zu bytes", nbmem,
                                        nbmem * 2);
                        /* Double the size */
                        nbmem <<= 1;
-                       elist = realloc(elist, nbmem * sizeof(struct lttng_event));
-                       if (elist == NULL) {
-                               perror("realloc list events");
+                       new_elist = realloc(elist, nbmem * sizeof(struct lttng_event));
+                       if (new_elist == NULL) {
+                               PERROR("realloc list events");
+                               free(event);
+                               free(elist);
                                count = -ENOMEM;
                                goto end;
                        }
+                       elist = new_elist;
                }
                strncpy(elist[count].name, event, LTTNG_SYMBOL_NAME_LEN);
                elist[count].name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0';
                elist[count].enabled = -1;
                count++;
+               free(event);
        }
 
        *events = elist;
        DBG("Kernel list events done (%zu events)", count);
 end:
-       fclose(fp);     /* closes both fp and fd */
+       ret = fclose(fp);       /* closes both fp and fd */
+       if (ret) {
+               PERROR("fclose");
+       }
        return count;
 
 error_fp:
-       close(fd);
+       ret = close(fd);
+       if (ret) {
+               PERROR("close");
+       }
 error:
        return -1;
 }
@@ -664,8 +703,10 @@ int init_kernel_workarounds(void)
                        /* Ignore error, we don't really care */
                }
        }
-       fclose(fp);
+       ret = fclose(fp);
+       if (ret) {
+               PERROR("fclose");
+       }
 end_boot_id:
-
        return 0;
 }
index d663dbb1cebd6e6d2da57e9cf904445cd8884335..0ef083073f32cb7c2baec4e99b3e1074e3a984e9 100644 (file)
@@ -1,19 +1,18 @@
 /*
  * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; only version 2
- * of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
  * This program 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
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #ifndef _LTT_KERNEL_CTL_H
index 2ba2550c7a1bda4cdb6fa3d1ff2f1f9313ad35ae..32963044f1e88fcde508654ad542e14e5bb17728 100644 (file)
@@ -1,19 +1,18 @@
 /*
  * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; only version 2
- * of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
  * This program 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
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #ifndef _LTT_SESSIOND_H
@@ -24,6 +23,7 @@
 #include <urcu/wfqueue.h>
 
 #include <common/sessiond-comm/sessiond-comm.h>
+#include <common/compat/socket.h>
 
 #include "session.h"
 #include "ust-app.h"
@@ -42,10 +42,10 @@ extern const char default_home_dir[],
 struct command_ctx {
        int ust_sock;
        unsigned int lttng_msg_size;
-       struct ucred creds;
        struct ltt_session *session;
        struct lttcomm_lttng_msg *llm;
        struct lttcomm_session_msg *lsm;
+       lttng_sock_cred creds;
 };
 
 struct ust_command {
index f726c8b576e707a69a0cd3508f77c184d21706c4..1bf82ed4431ee8cc1267f8e6606012f05f7bad43 100644 (file)
  * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
  * OR IMPLIED.  ANY USE IS AT YOUR OWN RISK.
  *
- * Permission is hereby granted to use or copy this program
- * for any purpose,  provided the above notices are retained on all copies.
- * Permission to modify the code and to distribute modified code is granted,
- * provided the above notices are retained, and a notice that the code was
- * modified is included with the above copyright notice.
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  */
 
 #include <stdint.h>
index 280c64a9a005050e4e949fd25c5bcfd0beef1969..a4f9c3fb4c93ae1350b70f07880666b4c80bccf3 100644 (file)
@@ -2,19 +2,18 @@
  * Copyright (C) 2011 - Julien Desfossez <julien.desfossez@polymtl.ca>
  *                      Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; only version 2
- * of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
  * This program 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 General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #ifndef _LTTNG_UST_CTL_H
index cb4dd25e94f73159d7e9bb1e6f1660060450b30f..cb186bbbe31723e75764126ab596f1ac1a1111b8 100644 (file)
@@ -2,22 +2,21 @@
  * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
  *                      Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; only version 2 of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
- * This program 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 General Public License for
- * more details.
+ * This program 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 General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place - Suite 330, Boston, MA  02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #define _GNU_SOURCE
-#include <fcntl.h>
 #include <getopt.h>
 #include <grp.h>
 #include <limits.h>
@@ -40,6 +39,7 @@
 
 #include <common/common.h>
 #include <common/compat/poll.h>
+#include <common/compat/socket.h>
 #include <common/defaults.h>
 #include <common/kernel-consumer/kernel-consumer.h>
 #include <common/ust-consumer/ust-consumer.h>
@@ -54,6 +54,7 @@
 #include "shm.h"
 #include "ust-ctl.h"
 #include "utils.h"
+#include "fd-limit.h"
 
 #define CONSUMERD_FILE "lttng-consumerd"
 
@@ -83,14 +84,10 @@ const char default_tracing_group[] = DEFAULT_TRACING_GROUP;
 const char default_ust_sock_dir[] = DEFAULT_UST_SOCK_DIR;
 const char default_global_apps_pipe[] = DEFAULT_GLOBAL_APPS_PIPE;
 
-/* Variables */
-int opt_verbose;    /* Not static for lttngerr.h */
-int opt_verbose_consumer;    /* Not static for lttngerr.h */
-int opt_quiet;      /* Not static for lttngerr.h */
-
 const char *progname;
 const char *opt_tracing_group;
 static int opt_sig_parent;
+static int opt_verbose_consumer;
 static int opt_daemon;
 static int opt_no_kernel;
 static int is_root;                    /* Set to 1 if the daemon is running as root */
@@ -102,16 +99,22 @@ static struct consumer_data kconsumer_data = {
        .type = LTTNG_CONSUMER_KERNEL,
        .err_unix_sock_path = DEFAULT_KCONSUMERD_ERR_SOCK_PATH,
        .cmd_unix_sock_path = DEFAULT_KCONSUMERD_CMD_SOCK_PATH,
+       .err_sock = -1,
+       .cmd_sock = -1,
 };
 static struct consumer_data ustconsumer64_data = {
        .type = LTTNG_CONSUMER64_UST,
        .err_unix_sock_path = DEFAULT_USTCONSUMERD64_ERR_SOCK_PATH,
        .cmd_unix_sock_path = DEFAULT_USTCONSUMERD64_CMD_SOCK_PATH,
+       .err_sock = -1,
+       .cmd_sock = -1,
 };
 static struct consumer_data ustconsumer32_data = {
        .type = LTTNG_CONSUMER32_UST,
        .err_unix_sock_path = DEFAULT_USTCONSUMERD32_ERR_SOCK_PATH,
        .cmd_unix_sock_path = DEFAULT_USTCONSUMERD32_CMD_SOCK_PATH,
+       .err_sock = -1,
+       .cmd_sock = -1,
 };
 
 static int dispatch_thread_exit;
@@ -124,22 +127,22 @@ static char client_unix_sock_path[PATH_MAX];
 static char wait_shm_path[PATH_MAX];
 
 /* Sockets and FDs */
-static int client_sock;
-static int apps_sock;
-static int kernel_tracer_fd;
-static int kernel_poll_pipe[2];
+static int client_sock = -1;
+static int apps_sock = -1;
+static int kernel_tracer_fd = -1;
+static int kernel_poll_pipe[2] = { -1, -1 };
 
 /*
  * Quit pipe for all threads. This permits a single cancellation point
  * for all threads when receiving an event on the pipe.
  */
-static int thread_quit_pipe[2];
+static int thread_quit_pipe[2] = { -1, -1 };
 
 /*
  * This pipe is used to inform the thread managing application communication
  * that a command is queued and ready to be processed.
  */
-static int apps_cmd_pipe[2];
+static int apps_cmd_pipe[2] = { -1, -1 };
 
 /* Pthread, Mutexes and Semaphores */
 static pthread_t apps_thread;
@@ -297,14 +300,22 @@ static gid_t allowed_group(void)
  */
 static int init_thread_quit_pipe(void)
 {
-       int ret;
+       int ret, i;
 
-       ret = pipe2(thread_quit_pipe, O_CLOEXEC);
+       ret = pipe(thread_quit_pipe);
        if (ret < 0) {
-               perror("thread quit pipe");
+               PERROR("thread quit pipe");
                goto error;
        }
 
+       for (i = 0; i < 2; i++) {
+               ret = fcntl(thread_quit_pipe[i], F_SETFD, FD_CLOEXEC);
+               if (ret < 0) {
+                       PERROR("fcntl");
+                       goto error;
+               }
+       }
+
 error:
        return ret;
 }
@@ -326,7 +337,8 @@ static void teardown_kernel_session(struct ltt_session *session)
         * If a custom kernel consumer was registered, close the socket before
         * tearing down the complete kernel session structure
         */
-       if (session->kernel_session->consumer_fd != kconsumer_data.cmd_sock) {
+       if (kconsumer_data.cmd_sock >= 0 &&
+                       session->kernel_session->consumer_fd != kconsumer_data.cmd_sock) {
                lttcomm_close_unix_sock(session->kernel_session->consumer_fd);
        }
 
@@ -380,7 +392,7 @@ static void stop_threads(void)
  */
 static void cleanup(void)
 {
-       int ret;
+       int ret, i;
        char *cmd;
        struct ltt_session *sess, *stmp;
 
@@ -421,13 +433,44 @@ static void cleanup(void)
 
        if (is_root && !opt_no_kernel) {
                DBG2("Closing kernel fd");
-               close(kernel_tracer_fd);
+               if (kernel_tracer_fd >= 0) {
+                       ret = close(kernel_tracer_fd);
+                       if (ret) {
+                               PERROR("close");
+                       }
+               }
                DBG("Unloading kernel modules");
                modprobe_remove_lttng_all();
        }
 
-       close(thread_quit_pipe[0]);
-       close(thread_quit_pipe[1]);
+       /*
+        * Closing all pipes used for communication between threads.
+        */
+       for (i = 0; i < 2; i++) {
+               if (kernel_poll_pipe[i] >= 0) {
+                       ret = close(kernel_poll_pipe[i]);
+                       if (ret) {
+                               PERROR("close");
+                       }
+                       
+               }
+       }
+       for (i = 0; i < 2; i++) {
+               if (thread_quit_pipe[i] >= 0) {
+                       ret = close(thread_quit_pipe[i]);
+                       if (ret) {
+                               PERROR("close");
+                       }
+               }
+       }
+       for (i = 0; i < 2; i++) {
+               if (apps_cmd_pipe[i] >= 0) {
+                       ret = close(apps_cmd_pipe[i]);
+                       if (ret) {
+                               PERROR("close");
+                       }
+               }
+       }
 
        /* OUTPUT BENCHMARK RESULTS */
        bench_init();
@@ -510,7 +553,7 @@ static int send_kconsumer_channel_streams(struct consumer_data *consumer_data,
        DBG("Sending channel %d to consumer", lkm.u.channel.channel_key);
        ret = lttcomm_send_unix_sock(sock, &lkm, sizeof(lkm));
        if (ret < 0) {
-               perror("send consumer channel");
+               PERROR("send consumer channel");
                goto error;
        }
 
@@ -532,12 +575,12 @@ static int send_kconsumer_channel_streams(struct consumer_data *consumer_data,
                DBG("Sending stream %d to consumer", lkm.u.stream.stream_key);
                ret = lttcomm_send_unix_sock(sock, &lkm, sizeof(lkm));
                if (ret < 0) {
-                       perror("send consumer stream");
+                       PERROR("send consumer stream");
                        goto error;
                }
                ret = lttcomm_send_fds_unix_sock(sock, &stream->fd, 1);
                if (ret < 0) {
-                       perror("send consumer stream ancillary data");
+                       PERROR("send consumer stream ancillary data");
                        goto error;
                }
        }
@@ -563,21 +606,21 @@ static int send_kconsumer_session_streams(struct consumer_data *consumer_data,
 
        DBG("Sending metadata stream fd");
 
-       /* Extra protection. It's NOT supposed to be set to 0 at this point */
-       if (session->consumer_fd == 0) {
+       /* Extra protection. It's NOT supposed to be set to -1 at this point */
+       if (session->consumer_fd < 0) {
                session->consumer_fd = consumer_data->cmd_sock;
        }
 
-       if (session->metadata_stream_fd != 0) {
+       if (session->metadata_stream_fd >= 0) {
                /* Send metadata channel fd */
                lkm.cmd_type = LTTNG_CONSUMER_ADD_CHANNEL;
                lkm.u.channel.channel_key = session->metadata->fd;
                lkm.u.channel.max_sb_size = session->metadata->conf->attr.subbuf_size;
                lkm.u.channel.mmap_len = 0;     /* for kernel */
-               DBG("Sending metadata channel %d to consumer", lkm.u.stream.stream_key);
+               DBG("Sending metadata channel %d to consumer", lkm.u.channel.channel_key);
                ret = lttcomm_send_unix_sock(sock, &lkm, sizeof(lkm));
                if (ret < 0) {
-                       perror("send consumer channel");
+                       PERROR("send consumer channel");
                        goto error;
                }
 
@@ -595,12 +638,12 @@ static int send_kconsumer_session_streams(struct consumer_data *consumer_data,
                DBG("Sending metadata stream %d to consumer", lkm.u.stream.stream_key);
                ret = lttcomm_send_unix_sock(sock, &lkm, sizeof(lkm));
                if (ret < 0) {
-                       perror("send consumer stream");
+                       PERROR("send consumer stream");
                        goto error;
                }
                ret = lttcomm_send_fds_unix_sock(sock, &session->metadata_stream_fd, 1);
                if (ret < 0) {
-                       perror("send consumer stream");
+                       PERROR("send consumer stream");
                        goto error;
                }
        }
@@ -665,7 +708,7 @@ static int setup_lttng_msg(struct command_ctx *cmd_ctx, size_t size)
 
        cmd_ctx->llm = zmalloc(sizeof(struct lttcomm_lttng_msg) + buf_size);
        if (cmd_ctx->llm == NULL) {
-               perror("zmalloc");
+               PERROR("zmalloc");
                ret = -ENOMEM;
                goto error;
        }
@@ -746,8 +789,8 @@ static int update_kernel_stream(struct consumer_data *consumer_data, int fd)
                        continue;
                }
 
-               /* This is not suppose to be 0 but this is an extra security check */
-               if (session->kernel_session->consumer_fd == 0) {
+               /* This is not suppose to be -1 but this is an extra security check */
+               if (session->kernel_session->consumer_fd < 0) {
                        session->kernel_session->consumer_fd = consumer_data->cmd_sock;
                }
 
@@ -827,7 +870,7 @@ static void *thread_manage_kernel(void *data)
 
        ret = create_thread_poll_set(&events, 2);
        if (ret < 0) {
-               goto error;
+               goto error_poll_create;
        }
 
        ret = lttng_poll_add(&events, kernel_poll_pipe[0], LPOLLIN);
@@ -860,8 +903,15 @@ static void *thread_manage_kernel(void *data)
                tracepoint(sessiond_th_kern_poll);
 
                /* Poll infinite value of time */
+       restart:
                ret = lttng_poll_wait(&events, -1);
                if (ret < 0) {
+                       /*
+                        * Restart interrupted system call.
+                        */
+                       if (errno == EINTR) {
+                               goto restart;
+                       }
                        goto error;
                } else if (ret == 0) {
                        /* Should not happen since timeout is infinite */
@@ -907,12 +957,9 @@ static void *thread_manage_kernel(void *data)
        }
 
 error:
-       DBG("Kernel thread dying");
-       close(kernel_poll_pipe[0]);
-       close(kernel_poll_pipe[1]);
-
        lttng_poll_clean(&events);
-
+error_poll_create:
+       DBG("Kernel thread dying");
        return NULL;
 }
 
@@ -921,7 +968,7 @@ error:
  */
 static void *thread_manage_consumer(void *data)
 {
-       int sock = 0, i, ret, pollfd;
+       int sock = -1, i, ret, pollfd;
        uint32_t revents, nb_fd;
        enum lttcomm_return_code code;
        struct lttng_poll_event events;
@@ -933,7 +980,7 @@ static void *thread_manage_consumer(void *data)
 
        ret = lttcomm_listen_unix_sock(consumer_data->err_sock);
        if (ret < 0) {
-               goto error;
+               goto error_listen;
        }
 
        /*
@@ -942,7 +989,7 @@ static void *thread_manage_consumer(void *data)
         */
        ret = create_thread_poll_set(&events, 2);
        if (ret < 0) {
-               goto error;
+               goto error_poll;
        }
 
        ret = lttng_poll_add(&events, consumer_data->err_sock, LPOLLIN | LPOLLRDHUP);
@@ -955,8 +1002,15 @@ static void *thread_manage_consumer(void *data)
        tracepoint(sessiond_th_kcon_poll);
 
        /* Inifinite blocking call, waiting for transmission */
+restart:
        ret = lttng_poll_wait(&events, -1);
        if (ret < 0) {
+               /*
+                * Restart interrupted system call.
+                */
+               if (errno == EINTR) {
+                       goto restart;
+               }
                goto error;
        }
 
@@ -1026,8 +1080,15 @@ static void *thread_manage_consumer(void *data)
        nb_fd = LTTNG_POLL_GETNB(&events);
 
        /* Inifinite blocking call, waiting for transmission */
+restart_poll:
        ret = lttng_poll_wait(&events, -1);
        if (ret < 0) {
+               /*
+                * Restart interrupted system call.
+                */
+               if (errno == EINTR) {
+                       goto restart_poll;
+               }
                goto error;
        }
 
@@ -1062,16 +1123,33 @@ static void *thread_manage_consumer(void *data)
        ERR("consumer return code : %s", lttcomm_get_readable_code(-code));
 
 error:
-       DBG("consumer thread dying");
-       close(consumer_data->err_sock);
-       close(consumer_data->cmd_sock);
-       close(sock);
+       if (consumer_data->err_sock >= 0) {
+               ret = close(consumer_data->err_sock);
+               if (ret) {
+                       PERROR("close");
+               }
+       }
+       if (consumer_data->cmd_sock >= 0) {
+               ret = close(consumer_data->cmd_sock);
+               if (ret) {
+                       PERROR("close");
+               }
+       }
+       if (sock >= 0) {
+               ret = close(sock);
+               if (ret) {
+                       PERROR("close");
+               }
+       }
 
        unlink(consumer_data->err_unix_sock_path);
        unlink(consumer_data->cmd_unix_sock_path);
        consumer_data->pid = 0;
 
        lttng_poll_clean(&events);
+error_poll:
+error_listen:
+       DBG("consumer thread cleanup completed");
 
        return NULL;
 }
@@ -1095,7 +1173,7 @@ static void *thread_manage_apps(void *data)
 
        ret = create_thread_poll_set(&events, 2);
        if (ret < 0) {
-               goto error;
+               goto error_poll_create;
        }
 
        ret = lttng_poll_add(&events, apps_cmd_pipe[0], LPOLLIN | LPOLLRDHUP);
@@ -1114,8 +1192,15 @@ static void *thread_manage_apps(void *data)
                tracepoint(sessiond_th_apps_poll);
 
                /* Inifinite blocking call, waiting for transmission */
+       restart:
                ret = lttng_poll_wait(&events, -1);
                if (ret < 0) {
+                       /*
+                        * Restart interrupted system call.
+                        */
+                       if (errno == EINTR) {
+                               goto restart;
+                       }
                        goto error;
                }
 
@@ -1140,7 +1225,7 @@ static void *thread_manage_apps(void *data)
                                        /* Empty pipe */
                                        ret = read(apps_cmd_pipe[0], &ust_cmd, sizeof(ust_cmd));
                                        if (ret < 0 || ret < sizeof(ust_cmd)) {
-                                               perror("read apps cmd pipe");
+                                               PERROR("read apps cmd pipe");
                                                goto error;
                                        }
                                        tracepoint(ust_register_read_stop);
@@ -1180,8 +1265,10 @@ static void *thread_manage_apps(void *data)
                                                /*
                                                 * We just need here to monitor the close of the UST
                                                 * socket and poll set monitor those by default.
+                                                * Listen on POLLIN (even if we never expect any
+                                                * data) to ensure that hangup wakes us.
                                                 */
-                                               ret = lttng_poll_add(&events, ust_cmd.sock, 0);
+                                               ret = lttng_poll_add(&events, ust_cmd.sock, LPOLLIN);
                                                if (ret < 0) {
                                                        goto error;
                                                }
@@ -1217,12 +1304,9 @@ static void *thread_manage_apps(void *data)
        }
 
 error:
-       DBG("Application communication apps dying");
-       close(apps_cmd_pipe[0]);
-       close(apps_cmd_pipe[1]);
-
        lttng_poll_clean(&events);
-
+error_poll_create:
+       DBG("Application communication apps thread cleanup complete");
        rcu_thread_offline();
        rcu_unregister_thread();
        return NULL;
@@ -1275,7 +1359,7 @@ static void *thread_dispatch_ust_registration(void *data)
                        ret = write(apps_cmd_pipe[1], ust_cmd,
                                        sizeof(struct ust_command));
                        if (ret < 0) {
-                               perror("write apps cmd pipe");
+                               PERROR("write apps cmd pipe");
                                if (errno == EBADF) {
                                        /*
                                         * We can't inform the application thread to process
@@ -1305,7 +1389,7 @@ error:
  */
 static void *thread_registration_apps(void *data)
 {
-       int sock = 0, i, ret, pollfd;
+       int sock = -1, i, ret, pollfd;
        uint32_t revents, nb_fd;
        struct lttng_poll_event events;
        /*
@@ -1320,7 +1404,7 @@ static void *thread_registration_apps(void *data)
 
        ret = lttcomm_listen_unix_sock(apps_sock);
        if (ret < 0) {
-               goto error;
+               goto error_listen;
        }
 
        /*
@@ -1329,13 +1413,13 @@ static void *thread_registration_apps(void *data)
         */
        ret = create_thread_poll_set(&events, 2);
        if (ret < 0) {
-               goto error;
+               goto error_create_poll;
        }
 
        /* Add the application registration socket */
        ret = lttng_poll_add(&events, apps_sock, LPOLLIN | LPOLLRDHUP);
        if (ret < 0) {
-               goto error;
+               goto error_poll_add;
        }
 
        /* Notify all applications to register */
@@ -1354,8 +1438,15 @@ static void *thread_registration_apps(void *data)
                nb_fd = LTTNG_POLL_GETNB(&events);
 
                /* Inifinite blocking call, waiting for transmission */
+       restart:
                ret = lttng_poll_wait(&events, -1);
                if (ret < 0) {
+                       /*
+                        * Restart interrupted system call.
+                        */
+                       if (errno == EINTR) {
+                               goto restart;
+                       }
                        goto error;
                }
 
@@ -1387,7 +1478,7 @@ static void *thread_registration_apps(void *data)
                                        /* Create UST registration command for enqueuing */
                                        ust_cmd = zmalloc(sizeof(struct ust_command));
                                        if (ust_cmd == NULL) {
-                                               perror("ust command zmalloc");
+                                               PERROR("ust command zmalloc");
                                                goto error;
                                        }
 
@@ -1395,20 +1486,37 @@ static void *thread_registration_apps(void *data)
                                         * Using message-based transmissions to ensure we don't
                                         * have to deal with partially received messages.
                                         */
+                                       ret = lttng_fd_get(LTTNG_FD_APPS, 1);
+                                       if (ret < 0) {
+                                               ERR("Exhausted file descriptors allowed for applications.");
+                                               free(ust_cmd);
+                                               ret = close(sock);
+                                               if (ret) {
+                                                       PERROR("close");
+                                               }
+                                               sock = -1;
+                                               continue;
+                                       }
                                        ret = lttcomm_recv_unix_sock(sock, &ust_cmd->reg_msg,
                                                        sizeof(struct ust_register_msg));
                                        if (ret < 0 || ret < sizeof(struct ust_register_msg)) {
                                                if (ret < 0) {
-                                                       perror("lttcomm_recv_unix_sock register apps");
+                                                       PERROR("lttcomm_recv_unix_sock register apps");
                                                } else {
                                                        ERR("Wrong size received on apps register");
                                                }
                                                free(ust_cmd);
-                                               close(sock);
+                                               ret = close(sock);
+                                               if (ret) {
+                                                       PERROR("close");
+                                               }
+                                               lttng_fd_put(LTTNG_FD_APPS, 1);
+                                               sock = -1;
                                                continue;
                                        }
 
                                        ust_cmd->sock = sock;
+                                       sock = -1;
 
                                        DBG("UST registration received with pid:%d ppid:%d uid:%d"
                                                        " gid:%d sock:%d name:%s (version %d.%d)",
@@ -1436,16 +1544,29 @@ static void *thread_registration_apps(void *data)
        }
 
 error:
-       DBG("UST Registration thread dying");
-
        /* Notify that the registration thread is gone */
        notify_ust_apps(0);
 
-       close(apps_sock);
-       close(sock);
+       if (apps_sock >= 0) {
+               ret = close(apps_sock);
+               if (ret) {
+                       PERROR("close");
+               }
+       }
+       if (sock >= 0) {
+               ret = close(sock);
+               if (ret) {
+                       PERROR("close");
+               }
+               lttng_fd_put(LTTNG_FD_APPS, 1);
+       }
        unlink(apps_unix_sock_path);
 
+error_poll_add:
        lttng_poll_clean(&events);
+error_listen:
+error_create_poll:
+       DBG("UST Registration thread cleanup complete");
 
        return NULL;
 }
@@ -1685,17 +1806,17 @@ static pid_t spawn_consumerd(struct consumer_data *consumer_data)
                        break;
                }
                default:
-                       perror("unknown consumer type");
+                       PERROR("unknown consumer type");
                        exit(EXIT_FAILURE);
                }
                if (errno != 0) {
-                       perror("kernel start consumer exec");
+                       PERROR("kernel start consumer exec");
                }
                exit(EXIT_FAILURE);
        } else if (pid > 0) {
                ret = pid;
        } else {
-               perror("start consumer fork");
+               PERROR("start consumer fork");
                ret = -errno;
        }
 error:
@@ -1786,20 +1907,30 @@ static int init_kernel_tracer(void)
 
 error_version:
        modprobe_remove_lttng_control();
-       close(kernel_tracer_fd);
-       kernel_tracer_fd = 0;
+       ret = close(kernel_tracer_fd);
+       if (ret) {
+               PERROR("close");
+       }
+       kernel_tracer_fd = -1;
        return LTTCOMM_KERN_VERSION;
 
 error_modules:
-       close(kernel_tracer_fd);
+       ret = close(kernel_tracer_fd);
+       if (ret) {
+               PERROR("close");
+       }
 
 error_open:
        modprobe_remove_lttng_control();
 
 error:
        WARN("No kernel tracer available");
-       kernel_tracer_fd = 0;
-       return LTTCOMM_KERN_NA;
+       kernel_tracer_fd = -1;
+       if (!is_root) {
+               return LTTCOMM_NEED_ROOT_SESSIOND;
+       } else {
+               return LTTCOMM_KERN_NA;
+       }
 }
 
 /*
@@ -1812,10 +1943,10 @@ static int init_kernel_tracing(struct ltt_kernel_session *session)
        if (session->consumer_fds_sent == 0) {
                /*
                 * Assign default kernel consumer socket if no consumer assigned to the
-                * kernel session. At this point, it's NOT suppose to be 0 but this is
+                * kernel session. At this point, it's NOT supposed to be -1 but this is
                 * an extra security check.
                 */
-               if (session->consumer_fd == 0) {
+               if (session->consumer_fd < 0) {
                        session->consumer_fd = kconsumer_data.cmd_sock;
                }
 
@@ -1903,7 +2034,7 @@ static int create_kernel_session(struct ltt_session *session)
        }
 
        /* Set kernel consumer socket fd */
-       if (kconsumer_data.cmd_sock) {
+       if (kconsumer_data.cmd_sock >= 0) {
                session->kernel_session->consumer_fd = kconsumer_data.cmd_sock;
        }
 
@@ -2792,7 +2923,8 @@ static int cmd_start_trace(struct ltt_session *session)
        usess = session->ust_session;
 
        if (session->enabled) {
-               ret = LTTCOMM_UST_START_FAIL;
+               /* Already started. */
+               ret = LTTCOMM_TRACE_ALREADY_STARTED;
                goto error;
        }
 
@@ -2812,7 +2944,7 @@ static int cmd_start_trace(struct ltt_session *session)
                }
 
                /* Open kernel metadata stream */
-               if (ksession->metadata_stream_fd == 0) {
+               if (ksession->metadata_stream_fd < 0) {
                        ret = kernel_open_metadata_stream(ksession);
                        if (ret < 0) {
                                ERR("Kernel create metadata stream failed");
@@ -2884,7 +3016,7 @@ static int cmd_stop_trace(struct ltt_session *session)
        usess = session->ust_session;
 
        if (!session->enabled) {
-               ret = LTTCOMM_UST_STOP_FAIL;
+               ret = LTTCOMM_TRACE_ALREADY_STOPPED;
                goto error;
        }
 
@@ -2935,11 +3067,12 @@ error:
 /*
  * Command LTTNG_CREATE_SESSION processed by the client thread.
  */
-static int cmd_create_session(char *name, char *path, struct ucred *creds)
+static int cmd_create_session(char *name, char *path, lttng_sock_cred *creds)
 {
        int ret;
 
-       ret = session_create(name, path, creds->uid, creds->gid);
+       ret = session_create(name, path, LTTNG_SOCK_GET_UID_CRED(creds),
+                       LTTNG_SOCK_GET_GID_CRED(creds));
        if (ret != LTTCOMM_OK) {
                goto error;
        }
@@ -2968,7 +3101,7 @@ static int cmd_destroy_session(struct ltt_session *session, char *name)
         */
        ret = notify_thread_pipe(kernel_poll_pipe[1]);
        if (ret < 0) {
-               perror("write kernel poll pipe");
+               PERROR("write kernel poll pipe");
        }
 
        ret = session_destroy(session);
@@ -3189,11 +3322,30 @@ static int process_client_msg(struct command_ctx *cmd_ctx)
 {
        int ret = LTTCOMM_OK;
        int need_tracing_session = 1;
+       int need_domain;
 
        DBG("Processing client command %d", cmd_ctx->lsm->cmd_type);
 
-       if (opt_no_kernel && cmd_ctx->lsm->domain.type == LTTNG_DOMAIN_KERNEL) {
-               ret = LTTCOMM_KERN_NA;
+       switch (cmd_ctx->lsm->cmd_type) {
+       case LTTNG_CREATE_SESSION:
+       case LTTNG_DESTROY_SESSION:
+       case LTTNG_LIST_SESSIONS:
+       case LTTNG_LIST_DOMAINS:
+       case LTTNG_START_TRACE:
+       case LTTNG_STOP_TRACE:
+               need_domain = 0;
+               break;
+       default:
+               need_domain = 1;
+       }
+
+       if (opt_no_kernel && need_domain
+                       && cmd_ctx->lsm->domain.type == LTTNG_DOMAIN_KERNEL) {
+               if (!is_root) {
+                       ret = LTTCOMM_NEED_ROOT_SESSIOND;
+               } else {
+                       ret = LTTCOMM_KERN_NA;
+               }
                goto error;
        }
 
@@ -3220,17 +3372,21 @@ static int process_client_msg(struct command_ctx *cmd_ctx)
 
        /* Commands that DO NOT need a session. */
        switch (cmd_ctx->lsm->cmd_type) {
-       case LTTNG_CALIBRATE:
        case LTTNG_CREATE_SESSION:
+       case LTTNG_CALIBRATE:
        case LTTNG_LIST_SESSIONS:
        case LTTNG_LIST_TRACEPOINTS:
                need_tracing_session = 0;
                break;
        default:
                DBG("Getting session %s by name", cmd_ctx->lsm->session.name);
+               /*
+                * We keep the session list lock across _all_ commands
+                * for now, because the per-session lock does not
+                * handle teardown properly.
+                */
                session_lock_list();
                cmd_ctx->session = session_find_by_name(cmd_ctx->lsm->session.name);
-               session_unlock_list();
                if (cmd_ctx->session == NULL) {
                        if (cmd_ctx->lsm->session.name != NULL) {
                                ret = LTTCOMM_SESS_NOT_FOUND;
@@ -3246,18 +3402,21 @@ static int process_client_msg(struct command_ctx *cmd_ctx)
                break;
        }
 
+       if (!need_domain) {
+               goto skip_domain;
+       }
        /*
         * Check domain type for specific "pre-action".
         */
        switch (cmd_ctx->lsm->domain.type) {
        case LTTNG_DOMAIN_KERNEL:
                if (!is_root) {
-                       ret = LTTCOMM_KERN_NA;
+                       ret = LTTCOMM_NEED_ROOT_SESSIOND;
                        goto error;
                }
 
                /* Kernel tracer check */
-               if (kernel_tracer_fd == 0) {
+               if (kernel_tracer_fd == -1) {
                        /* Basically, load kernel tracer modules */
                        ret = init_kernel_tracer();
                        if (ret != 0) {
@@ -3339,6 +3498,7 @@ static int process_client_msg(struct command_ctx *cmd_ctx)
        default:
                break;
        }
+skip_domain:
 
        /*
         * Check that the UID or GID match that of the tracing session.
@@ -3346,7 +3506,8 @@ static int process_client_msg(struct command_ctx *cmd_ctx)
         */
        if (need_tracing_session) {
                if (!session_access_ok(cmd_ctx->session,
-                               cmd_ctx->creds.uid, cmd_ctx->creds.gid)) {
+                               LTTNG_SOCK_GET_UID_CRED(&cmd_ctx->creds),
+                               LTTNG_SOCK_GET_GID_CRED(&cmd_ctx->creds))) {
                        ret = LTTCOMM_EPERM;
                        goto error;
                }
@@ -3459,6 +3620,11 @@ static int process_client_msg(struct command_ctx *cmd_ctx)
                ret = cmd_destroy_session(cmd_ctx->session,
                                cmd_ctx->lsm->session.name);
                tracepoint(destroy_session_end);
+               /*
+                * Set session to NULL so we do not unlock it after
+                * free.
+                */
+               cmd_ctx->session = NULL;
                break;
        }
        case LTTNG_LIST_DOMAINS:
@@ -3543,7 +3709,9 @@ static int process_client_msg(struct command_ctx *cmd_ctx)
                unsigned int nr_sessions;
 
                session_lock_list();
-               nr_sessions = lttng_sessions_count(cmd_ctx->creds.uid, cmd_ctx->creds.gid);
+               nr_sessions = lttng_sessions_count(
+                               LTTNG_SOCK_GET_UID_CRED(&cmd_ctx->creds),
+                               LTTNG_SOCK_GET_GID_CRED(&cmd_ctx->creds));
 
                ret = setup_lttng_msg(cmd_ctx, sizeof(struct lttng_session) * nr_sessions);
                if (ret < 0) {
@@ -3553,7 +3721,8 @@ static int process_client_msg(struct command_ctx *cmd_ctx)
 
                /* Filled the session array */
                list_lttng_sessions((struct lttng_session *)(cmd_ctx->llm->payload),
-                       cmd_ctx->creds.uid, cmd_ctx->creds.gid);
+                       LTTNG_SOCK_GET_UID_CRED(&cmd_ctx->creds),
+                       LTTNG_SOCK_GET_GID_CRED(&cmd_ctx->creds));
 
                session_unlock_list();
 
@@ -3590,6 +3759,9 @@ setup_error:
        if (cmd_ctx->session) {
                session_unlock(cmd_ctx->session);
        }
+       if (need_tracing_session) {
+               session_unlock_list();
+       }
 init_setup_error:
        return ret;
 }
@@ -3600,7 +3772,7 @@ init_setup_error:
  */
 static void *thread_manage_clients(void *data)
 {
-       int sock = 0, ret, i, pollfd;
+       int sock = -1, ret, i, pollfd;
        uint32_t revents, nb_fd;
        struct command_ctx *cmd_ctx = NULL;
        struct lttng_poll_event events;
@@ -3646,8 +3818,15 @@ static void *thread_manage_clients(void *data)
                nb_fd = LTTNG_POLL_GETNB(&events);
 
                /* Inifinite blocking call, waiting for transmission */
+       restart:
                ret = lttng_poll_wait(&events, -1);
                if (ret < 0) {
+                       /*
+                        * Restart interrupted system call.
+                        */
+                       if (errno == EINTR) {
+                               goto restart;
+                       }
                        goto error;
                }
 
@@ -3687,14 +3866,14 @@ static void *thread_manage_clients(void *data)
                /* Allocate context command to process the client request */
                cmd_ctx = zmalloc(sizeof(struct command_ctx));
                if (cmd_ctx == NULL) {
-                       perror("zmalloc cmd_ctx");
+                       PERROR("zmalloc cmd_ctx");
                        goto error;
                }
 
                /* Allocate data buffer for reception */
                cmd_ctx->lsm = zmalloc(sizeof(struct lttcomm_session_msg));
                if (cmd_ctx->lsm == NULL) {
-                       perror("zmalloc cmd_ctx->lsm");
+                       PERROR("zmalloc cmd_ctx->lsm");
                        goto error;
                }
 
@@ -3711,8 +3890,12 @@ static void *thread_manage_clients(void *data)
                                sizeof(struct lttcomm_session_msg), &cmd_ctx->creds);
                if (ret <= 0) {
                        DBG("Nothing recv() from client... continuing");
-                       close(sock);
-                       free(cmd_ctx);
+                       ret = close(sock);
+                       if (ret) {
+                               PERROR("close");
+                       }
+                       sock = -1;
+                       clean_command_ctx(&cmd_ctx);
                        continue;
                }
 
@@ -3747,7 +3930,11 @@ static void *thread_manage_clients(void *data)
                }
 
                /* End of transmission */
-               close(sock);
+               ret = close(sock);
+               if (ret) {
+                       PERROR("close");
+               }
+               sock = -1;
 
                clean_command_ctx(&cmd_ctx);
        }
@@ -3755,8 +3942,18 @@ static void *thread_manage_clients(void *data)
 error:
        DBG("Client thread dying");
        unlink(client_unix_sock_path);
-       close(client_sock);
-       close(sock);
+       if (client_sock >= 0) {
+               ret = close(client_sock);
+               if (ret) {
+                       PERROR("close");
+               }
+       }
+       if (sock >= 0) {
+               ret = close(sock);
+               if (ret) {
+                       PERROR("close");
+               }
+       }
 
        lttng_poll_clean(&events);
        clean_command_ctx(&cmd_ctx);
@@ -3885,11 +4082,11 @@ static int parse_args(int argc, char **argv)
                        opt_no_kernel = 1;
                        break;
                case 'q':
-                       opt_quiet = 1;
+                       lttng_opt_quiet = 1;
                        break;
                case 'v':
                        /* Verbose level can increase using multiple -v */
-                       opt_verbose += 1;
+                       lttng_opt_verbose += 1;
                        break;
                case 'Z':
                        opt_verbose_consumer += 1;
@@ -3940,7 +4137,7 @@ static int init_daemon_socket(void)
        ret = chmod(client_unix_sock_path, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
        if (ret < 0) {
                ERR("Set file permissions failed: %s", client_unix_sock_path);
-               perror("chmod");
+               PERROR("chmod");
                goto end;
        }
 
@@ -3957,7 +4154,7 @@ static int init_daemon_socket(void)
                        S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
        if (ret < 0) {
                ERR("Set file permissions failed: %s", apps_unix_sock_path);
-               perror("chmod");
+               PERROR("chmod");
                goto end;
        }
 
@@ -4002,42 +4199,42 @@ static int set_permissions(char *rundir)
        ret = chown(rundir, 0, gid);
        if (ret < 0) {
                ERR("Unable to set group on %s", rundir);
-               perror("chown");
+               PERROR("chown");
        }
 
        /* Ensure tracing group can search the run dir */
-       ret = chmod(rundir, S_IRWXU | S_IXGRP);
+       ret = chmod(rundir, S_IRWXU | S_IXGRP | S_IXOTH);
        if (ret < 0) {
                ERR("Unable to set permissions on %s", rundir);
-               perror("chmod");
+               PERROR("chmod");
        }
 
        /* lttng client socket path */
        ret = chown(client_unix_sock_path, 0, gid);
        if (ret < 0) {
                ERR("Unable to set group on %s", client_unix_sock_path);
-               perror("chown");
+               PERROR("chown");
        }
 
        /* kconsumer error socket path */
        ret = chown(kconsumer_data.err_unix_sock_path, 0, gid);
        if (ret < 0) {
                ERR("Unable to set group on %s", kconsumer_data.err_unix_sock_path);
-               perror("chown");
+               PERROR("chown");
        }
 
        /* 64-bit ustconsumer error socket path */
        ret = chown(ustconsumer64_data.err_unix_sock_path, 0, gid);
        if (ret < 0) {
                ERR("Unable to set group on %s", ustconsumer64_data.err_unix_sock_path);
-               perror("chown");
+               PERROR("chown");
        }
 
        /* 32-bit ustconsumer compat32 error socket path */
        ret = chown(ustconsumer32_data.err_unix_sock_path, 0, gid);
        if (ret < 0) {
                ERR("Unable to set group on %s", ustconsumer32_data.err_unix_sock_path);
-               perror("chown");
+               PERROR("chown");
        }
 
        DBG("All permissions are set");
@@ -4048,18 +4245,54 @@ end:
 
 /*
  * Create the pipe used to wake up the kernel thread.
+ * Closed in cleanup().
  */
 static int create_kernel_poll_pipe(void)
 {
-       return pipe2(kernel_poll_pipe, O_CLOEXEC);
+       int ret, i;
+
+       ret = pipe(kernel_poll_pipe);
+       if (ret < 0) {
+               PERROR("kernel poll pipe");
+               goto error;
+       }
+
+       for (i = 0; i < 2; i++) {
+               ret = fcntl(kernel_poll_pipe[i], F_SETFD, FD_CLOEXEC);
+               if (ret < 0) {
+                       PERROR("fcntl kernel_poll_pipe");
+                       goto error;
+               }
+       }
+
+error:
+       return ret;
 }
 
 /*
  * Create the application command pipe to wake thread_manage_apps.
+ * Closed in cleanup().
  */
 static int create_apps_cmd_pipe(void)
 {
-       return pipe2(apps_cmd_pipe, O_CLOEXEC);
+       int ret, i;
+
+       ret = pipe(apps_cmd_pipe);
+       if (ret < 0) {
+               PERROR("apps cmd pipe");
+               goto error;
+       }
+
+       for (i = 0; i < 2; i++) {
+               ret = fcntl(apps_cmd_pipe[i], F_SETFD, FD_CLOEXEC);
+               if (ret < 0) {
+                       PERROR("fcntl apps_cmd_pipe");
+                       goto error;
+               }
+       }
+
+error:
+       return ret;
 }
 
 /*
@@ -4116,10 +4349,11 @@ static int set_consumer_sockets(struct consumer_data *consumer_data,
        ret = mkdir(path, S_IRWXU);
        if (ret < 0) {
                if (errno != EEXIST) {
+                       PERROR("mkdir");
                        ERR("Failed to create %s", path);
                        goto error;
                }
-               ret = 0;
+               ret = -1;
        }
 
        /* Create the kconsumerd error unix socket */
@@ -4180,7 +4414,7 @@ static int set_signal_handler(void)
        sigset_t sigset;
 
        if ((ret = sigemptyset(&sigset)) < 0) {
-               perror("sigemptyset");
+               PERROR("sigemptyset");
                return ret;
        }
 
@@ -4188,17 +4422,17 @@ static int set_signal_handler(void)
        sa.sa_mask = sigset;
        sa.sa_flags = 0;
        if ((ret = sigaction(SIGTERM, &sa, NULL)) < 0) {
-               perror("sigaction");
+               PERROR("sigaction");
                return ret;
        }
 
        if ((ret = sigaction(SIGINT, &sa, NULL)) < 0) {
-               perror("sigaction");
+               PERROR("sigaction");
                return ret;
        }
 
        if ((ret = sigaction(SIGPIPE, &sa, NULL)) < 0) {
-               perror("sigaction");
+               PERROR("sigaction");
                return ret;
        }
 
@@ -4222,7 +4456,7 @@ static void set_ulimit(void)
 
        ret = setrlimit(RLIMIT_NOFILE, &lim);
        if (ret < 0) {
-               perror("failed to set open files limit");
+               PERROR("failed to set open files limit");
        }
 }
 
@@ -4258,7 +4492,7 @@ int main(int argc, char **argv)
        if (opt_daemon) {
                ret = daemon(0, 0);
                if (ret < 0) {
-                       perror("daemon");
+                       PERROR("daemon");
                        goto error;
                }
        }
@@ -4381,6 +4615,12 @@ int main(int argc, char **argv)
                goto error;
        }
 
+       /*
+        * Init UST app hash table. Alloc hash table before this point since
+        * cleanup() can get called after that point.
+        */
+       ust_app_ht_alloc();
+
        /* After this point, we can safely call cleanup() with "goto exit" */
 
        /*
@@ -4403,6 +4643,8 @@ int main(int argc, char **argv)
                /* Set ulimit for open files */
                set_ulimit();
        }
+       /* init lttng_fd tracking must be done after set_ulimit. */
+       lttng_fd_init();
 
        ret = set_consumer_sockets(&ustconsumer64_data, rundir);
        if (ret < 0) {
@@ -4446,9 +4688,6 @@ int main(int argc, char **argv)
        /* Init UST command queue. */
        cds_wfq_init(&ust_cmd_queue.queue);
 
-       /* Init UST app hash table */
-       ust_app_ht_alloc();
-
        /*
         * Get session list pointer. This pointer MUST NOT be free(). This list is
         * statically declared in session.c
@@ -4462,7 +4701,7 @@ int main(int argc, char **argv)
        ret = pthread_create(&client_thread, NULL,
                        thread_manage_clients, (void *) NULL);
        if (ret != 0) {
-               perror("pthread_create clients");
+               PERROR("pthread_create clients");
                goto exit_client;
        }
 
@@ -4470,7 +4709,7 @@ int main(int argc, char **argv)
        ret = pthread_create(&dispatch_thread, NULL,
                        thread_dispatch_ust_registration, (void *) NULL);
        if (ret != 0) {
-               perror("pthread_create dispatch");
+               PERROR("pthread_create dispatch");
                goto exit_dispatch;
        }
 
@@ -4478,7 +4717,7 @@ int main(int argc, char **argv)
        ret = pthread_create(&reg_apps_thread, NULL,
                        thread_registration_apps, (void *) NULL);
        if (ret != 0) {
-               perror("pthread_create registration");
+               PERROR("pthread_create registration");
                goto exit_reg_apps;
        }
 
@@ -4486,7 +4725,7 @@ int main(int argc, char **argv)
        ret = pthread_create(&apps_thread, NULL,
                        thread_manage_apps, (void *) NULL);
        if (ret != 0) {
-               perror("pthread_create apps");
+               PERROR("pthread_create apps");
                goto exit_apps;
        }
 
@@ -4494,7 +4733,7 @@ int main(int argc, char **argv)
        ret = pthread_create(&kernel_thread, NULL,
                        thread_manage_kernel, (void *) NULL);
        if (ret != 0) {
-               perror("pthread_create kernel");
+               PERROR("pthread_create kernel");
                goto exit_kernel;
        }
 
@@ -4502,41 +4741,41 @@ int main(int argc, char **argv)
 
        ret = pthread_join(kernel_thread, &status);
        if (ret != 0) {
-               perror("pthread_join");
+               PERROR("pthread_join");
                goto error;     /* join error, exit without cleanup */
        }
 
 exit_kernel:
        ret = pthread_join(apps_thread, &status);
        if (ret != 0) {
-               perror("pthread_join");
+               PERROR("pthread_join");
                goto error;     /* join error, exit without cleanup */
        }
 
 exit_apps:
        ret = pthread_join(reg_apps_thread, &status);
        if (ret != 0) {
-               perror("pthread_join");
+               PERROR("pthread_join");
                goto error;     /* join error, exit without cleanup */
        }
 
 exit_reg_apps:
        ret = pthread_join(dispatch_thread, &status);
        if (ret != 0) {
-               perror("pthread_join");
+               PERROR("pthread_join");
                goto error;     /* join error, exit without cleanup */
        }
 
 exit_dispatch:
        ret = pthread_join(client_thread, &status);
        if (ret != 0) {
-               perror("pthread_join");
+               PERROR("pthread_join");
                goto error;     /* join error, exit without cleanup */
        }
 
        ret = join_consumer_thread(&kconsumer_data);
        if (ret != 0) {
-               perror("join_consumer");
+               PERROR("join_consumer");
                goto error;     /* join error, exit without cleanup */
        }
 
index a87d7075489d1cd640a5b91e23872abecb8f64fe..b3f2e57018ece61ce85bafa9f86f16b5712c776b 100644 (file)
@@ -1,18 +1,18 @@
 /*
  * Copyright (C) 2011 - David Goulet <dgoulet@efficios.com>
  *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; only version 2 of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
- * This program 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 General Public License for
- * more details.
+ * This program 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 General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place - Suite 330, Boston, MA  02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #define _GNU_SOURCE
@@ -101,7 +101,7 @@ void modprobe_remove_lttng_data(void)
                                "/sbin/modprobe -r -q %s",
                                kern_modules_list[i].name);
                if (ret < 0) {
-                       perror("snprintf modprobe -r");
+                       PERROR("snprintf modprobe -r");
                        goto error;
                }
                modprobe[sizeof(modprobe) - 1] = '\0';
@@ -182,7 +182,7 @@ int modprobe_lttng_data(void)
                                kern_modules_list[i].required ? "" : "-q ",
                                kern_modules_list[i].name);
                if (ret < 0) {
-                       perror("snprintf modprobe");
+                       PERROR("snprintf modprobe");
                        goto error;
                }
                modprobe[sizeof(modprobe) - 1] = '\0';
index acd3e8ac97c48b10a171f78adcecbb4233a8f927..8f329fad19a422505b7dd1a82168b737a3ffb77e 100644 (file)
@@ -1,18 +1,18 @@
 /*
  * Copyright (C) 2011 - David Goulet <dgoulet@efficios.com>
  *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; only version 2 of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
- * This program 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 General Public License for
- * more details.
+ * This program 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 General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place - Suite 330, Boston, MA  02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #ifndef _MODPROBE_H
index e890d07bac3b4d359c788152ea244ca96582bb31..cf2ef463e8ce20404746ae7dda5a28e44f538b84 100644 (file)
@@ -1,19 +1,18 @@
 /*
  * Copyright (C)  2011 - David Goulet <david.goulet@polymtl.ca>
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; only version 2
- * of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
  * This program 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
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #define _GNU_SOURCE
@@ -177,7 +176,7 @@ int session_create(char *name, char *path, uid_t uid, gid_t gid)
        /* Allocate session data structure */
        new_session = zmalloc(sizeof(struct ltt_session));
        if (new_session == NULL) {
-               perror("zmalloc");
+               PERROR("zmalloc");
                ret = LTTCOMM_FATAL;
                goto error_malloc;
        }
index 6264e14ac4f0b6430fd06f9960e0c9915e539fa2..fd8f9116d21585d46fb1ac541272b397759cb293 100644 (file)
@@ -1,19 +1,18 @@
 /*
  * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; only version 2
- * of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
  * This program 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 General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #ifndef _LTT_SESSION_H
index 0bf3ff58f0dd138e553f9c1dafaa38d418b1d09c..e785aaa8b05c584a248b49ecd764ef9e02ac72b0 100644 (file)
@@ -2,18 +2,18 @@
  * Copyright (C)  2011 - David Goulet <david.goulet@polymtl.ca>
  *                       Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; only version 2 of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
- * This program 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 General Public License for
- * more details.
+ * This program 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 General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place - Suite 330, Boston, MA  02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #define _GNU_SOURCE
@@ -55,7 +55,7 @@ static int get_wait_shm(char *shm_path, size_t mmap_size, int global)
                ret = chown(shm_path, 0, 0);
                if (ret < 0) {
                        if (errno != ENOENT) {
-                               perror("chown wait shm");
+                               PERROR("chown wait shm");
                                goto error;
                        }
                }
@@ -69,7 +69,7 @@ static int get_wait_shm(char *shm_path, size_t mmap_size, int global)
                ret = chown(shm_path, getuid(), getgid());
                if (ret < 0) {
                        if (errno != ENOENT) {
-                               perror("chown wait shm");
+                               PERROR("chown wait shm");
                                goto error;
                        }
                }
@@ -81,7 +81,7 @@ static int get_wait_shm(char *shm_path, size_t mmap_size, int global)
        ret = chmod(shm_path, mode);
        if (ret < 0) {
                if (errno != ENOENT) {
-                       perror("chmod wait shm");
+                       PERROR("chmod wait shm");
                        goto error;
                }
        }
@@ -101,21 +101,25 @@ static int get_wait_shm(char *shm_path, size_t mmap_size, int global)
         */
        wait_shm_fd = shm_open(shm_path, O_RDWR | O_CREAT, mode);
        if (wait_shm_fd < 0) {
-               perror("shm_open wait shm");
+               PERROR("shm_open wait shm");
                goto error;
        }
 
        ret = ftruncate(wait_shm_fd, mmap_size);
        if (ret < 0) {
-               perror("ftruncate wait shm");
+               PERROR("ftruncate wait shm");
                exit(EXIT_FAILURE);
        }
 
+#ifndef __FreeBSD__
        ret = fchmod(wait_shm_fd, mode);
        if (ret < 0) {
-               perror("fchmod");
+               PERROR("fchmod");
                exit(EXIT_FAILURE);
        }
+#else
+#warning "FreeBSD does not support setting file mode on shm FD. Remember that for secure use, lttng-sessiond should be started before applications linked on lttng-ust."
+#endif
 
        tracepoint(ust_notify_shm_stop);
 
@@ -157,7 +161,7 @@ char *shm_ust_get_mmap(char *shm_path, int global)
        /* close shm fd immediately after taking the mmap reference */
        ret = close(wait_shm_fd);
        if (ret) {
-               perror("Error closing fd");
+               PERROR("Error closing fd");
        }
 
        if (wait_shm_mmap == MAP_FAILED) {
index 2d301bbac09bb5675fb3a655ac722ce422931002..bcce28bcde57b69fa6c7e0381a1b0fa8c630b140 100644 (file)
@@ -2,18 +2,18 @@
  * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
  *                      Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; only version 2 of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
- * This program 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 General Public License for
- * more details.
+ * This program 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 General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place - Suite 330, Boston, MA  02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #ifndef _LTT_SHM_H
index 36f7c9708a8f47e0fa33d9ce579a33c0bf607e08..293ca381b6bf3a24f88907acf6cb9f32f60fd698 100644 (file)
@@ -1,19 +1,18 @@
 /*
  * Copyright (C)  2011 - David Goulet <david.goulet@polymtl.ca>
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; only version 2
- * of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
  * This program 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 General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #define _GNU_SOURCE
@@ -91,23 +90,23 @@ struct ltt_kernel_session *trace_kernel_create_session(char *path)
        /* Allocate a new ltt kernel session */
        lks = zmalloc(sizeof(struct ltt_kernel_session));
        if (lks == NULL) {
-               perror("create kernel session zmalloc");
+               PERROR("create kernel session zmalloc");
                goto error;
        }
 
        /* Init data structure */
-       lks->fd = 0;
-       lks->metadata_stream_fd = 0;
+       lks->fd = -1;
+       lks->metadata_stream_fd = -1;
        lks->channel_count = 0;
        lks->stream_count_global = 0;
        lks->metadata = NULL;
-       lks->consumer_fd = 0;
+       lks->consumer_fd = -1;
        CDS_INIT_LIST_HEAD(&lks->channel_list.head);
 
        /* Set session path */
        ret = asprintf(&lks->trace_path, "%s/kernel", path);
        if (ret < 0) {
-               perror("asprintf kernel traces path");
+               PERROR("asprintf kernel traces path");
                goto error;
        }
 
@@ -129,18 +128,18 @@ struct ltt_kernel_channel *trace_kernel_create_channel(struct lttng_channel *cha
 
        lkc = zmalloc(sizeof(struct ltt_kernel_channel));
        if (lkc == NULL) {
-               perror("ltt_kernel_channel zmalloc");
+               PERROR("ltt_kernel_channel zmalloc");
                goto error;
        }
 
        lkc->channel = zmalloc(sizeof(struct lttng_channel));
        if (lkc->channel == NULL) {
-               perror("lttng_channel zmalloc");
+               PERROR("lttng_channel zmalloc");
                goto error;
        }
        memcpy(lkc->channel, chan, sizeof(struct lttng_channel));
 
-       lkc->fd = 0;
+       lkc->fd = -1;
        lkc->stream_count = 0;
        lkc->event_count = 0;
        lkc->enabled = 1;
@@ -151,7 +150,7 @@ struct ltt_kernel_channel *trace_kernel_create_channel(struct lttng_channel *cha
        /* Set default trace output path */
        ret = asprintf(&lkc->pathname, "%s", path);
        if (ret < 0) {
-               perror("asprintf kernel create channel");
+               PERROR("asprintf kernel create channel");
                goto error;
        }
 
@@ -174,7 +173,7 @@ struct ltt_kernel_event *trace_kernel_create_event(struct lttng_event *ev)
        lke = zmalloc(sizeof(struct ltt_kernel_event));
        attr = zmalloc(sizeof(struct lttng_kernel_event));
        if (lke == NULL || attr == NULL) {
-               perror("kernel event zmalloc");
+               PERROR("kernel event zmalloc");
                goto error;
        }
 
@@ -221,7 +220,7 @@ struct ltt_kernel_event *trace_kernel_create_event(struct lttng_event *ev)
        attr->name[LTTNG_KERNEL_SYM_NAME_LEN - 1] = '\0';
 
        /* Setting up a kernel event */
-       lke->fd = 0;
+       lke->fd = -1;
        lke->event = attr;
        lke->enabled = 1;
        lke->ctx = NULL;
@@ -229,6 +228,8 @@ struct ltt_kernel_event *trace_kernel_create_event(struct lttng_event *ev)
        return lke;
 
 error:
+       free(lke);
+       free(attr);
        return NULL;
 }
 
@@ -246,7 +247,7 @@ struct ltt_kernel_metadata *trace_kernel_create_metadata(char *path)
        lkm = zmalloc(sizeof(struct ltt_kernel_metadata));
        chan = zmalloc(sizeof(struct lttng_channel));
        if (lkm == NULL || chan == NULL) {
-               perror("kernel metadata zmalloc");
+               PERROR("kernel metadata zmalloc");
                goto error;
        }
 
@@ -259,18 +260,20 @@ struct ltt_kernel_metadata *trace_kernel_create_metadata(char *path)
        chan->attr.output = DEFAULT_KERNEL_CHANNEL_OUTPUT;
 
        /* Init metadata */
-       lkm->fd = 0;
+       lkm->fd = -1;
        lkm->conf = chan;
        /* Set default metadata path */
        ret = asprintf(&lkm->pathname, "%s/metadata", path);
        if (ret < 0) {
-               perror("asprintf kernel metadata");
+               PERROR("asprintf kernel metadata");
                goto error;
        }
 
        return lkm;
 
 error:
+       free(lkm);
+       free(chan);
        return NULL;
 }
 
@@ -286,12 +289,12 @@ struct ltt_kernel_stream *trace_kernel_create_stream(void)
 
        lks = zmalloc(sizeof(struct ltt_kernel_stream));
        if (lks == NULL) {
-               perror("kernel stream zmalloc");
+               PERROR("kernel stream zmalloc");
                goto error;
        }
 
        /* Init stream */
-       lks->fd = 0;
+       lks->fd = -1;
        lks->pathname = NULL;
        lks->state = 0;
 
@@ -306,9 +309,16 @@ error:
  */
 void trace_kernel_destroy_stream(struct ltt_kernel_stream *stream)
 {
+       int ret;
+
        DBG("[trace] Closing stream fd %d", stream->fd);
        /* Close kernel fd */
-       close(stream->fd);
+       if (stream->fd >= 0) {
+               ret = close(stream->fd);
+               if (ret) {
+                       PERROR("close");
+               }
+       }
        /* Remove from stream list */
        cds_list_del(&stream->list);
 
@@ -321,9 +331,18 @@ void trace_kernel_destroy_stream(struct ltt_kernel_stream *stream)
  */
 void trace_kernel_destroy_event(struct ltt_kernel_event *event)
 {
-       DBG("[trace] Closing event fd %d", event->fd);
-       /* Close kernel fd */
-       close(event->fd);
+       int ret;
+
+       if (event->fd >= 0) {
+               DBG("[trace] Closing event fd %d", event->fd);
+               /* Close kernel fd */
+               ret = close(event->fd);
+               if (ret) {
+                       PERROR("close");
+               }
+       } else {
+               DBG("[trace] Tearing down event (no associated fd)");
+       }
 
        /* Remove from event list */
        cds_list_del(&event->list);
@@ -340,10 +359,16 @@ void trace_kernel_destroy_channel(struct ltt_kernel_channel *channel)
 {
        struct ltt_kernel_stream *stream, *stmp;
        struct ltt_kernel_event *event, *etmp;
+       int ret;
 
        DBG("[trace] Closing channel fd %d", channel->fd);
        /* Close kernel fd */
-       close(channel->fd);
+       if (channel->fd >= 0) {
+               ret = close(channel->fd);
+               if (ret) {
+                       PERROR("close");
+               }
+       }
 
        /* For each stream in the channel list */
        cds_list_for_each_entry_safe(stream, stmp, &channel->stream_list.head, list) {
@@ -369,9 +394,16 @@ void trace_kernel_destroy_channel(struct ltt_kernel_channel *channel)
  */
 void trace_kernel_destroy_metadata(struct ltt_kernel_metadata *metadata)
 {
+       int ret;
+
        DBG("[trace] Closing metadata fd %d", metadata->fd);
        /* Close kernel fd */
-       close(metadata->fd);
+       if (metadata->fd >= 0) {
+               ret = close(metadata->fd);
+               if (ret) {
+                       PERROR("close");
+               }
+       }
 
        free(metadata->conf);
        free(metadata->pathname);
@@ -384,14 +416,23 @@ void trace_kernel_destroy_metadata(struct ltt_kernel_metadata *metadata)
 void trace_kernel_destroy_session(struct ltt_kernel_session *session)
 {
        struct ltt_kernel_channel *channel, *ctmp;
+       int ret;
 
        DBG("[trace] Closing session fd %d", session->fd);
        /* Close kernel fds */
-       close(session->fd);
+       if (session->fd >= 0) {
+               ret = close(session->fd);
+               if (ret) {
+                       PERROR("close");
+               }
+       }
 
-       if (session->metadata_stream_fd != 0) {
+       if (session->metadata_stream_fd >= 0) {
                DBG("[trace] Closing metadata stream fd %d", session->metadata_stream_fd);
-               close(session->metadata_stream_fd);
+               ret = close(session->metadata_stream_fd);
+               if (ret) {
+                       PERROR("close");
+               }
        }
 
        if (session->metadata != NULL) {
index ae993c8d98df22a49c8d74d079c9f756e3ae2957..5a8bcdbd4418c496ab3aa72fcb931c179814d71f 100644 (file)
@@ -1,19 +1,18 @@
 /*
  * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; only version 2
- * of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
  * This program 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 General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #ifndef _LTT_TRACE_KERNEL_H
index ce6332d931618178948c64095abe1264cbc35315..7b5c3c788e4ff622a18d74f7fc2ce01555483359 100644 (file)
@@ -1,18 +1,18 @@
 /*
  * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
  *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; only version 2 of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
- * This program 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 General Public License for
- * more details.
+ * This program 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 General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place - Suite 330, Boston, MA  02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #define _GNU_SOURCE
@@ -121,6 +121,9 @@ struct ltt_ust_session *trace_ust_create_session(char *path, int session_id,
        return lus;
 
 error_free_session:
+       lttng_ht_destroy(lus->domain_global.channels);
+       lttng_ht_destroy(lus->domain_exec);
+       lttng_ht_destroy(lus->domain_pid);
        free(lus);
 error:
        return NULL;
@@ -139,7 +142,7 @@ struct ltt_ust_channel *trace_ust_create_channel(struct lttng_channel *chan,
 
        luc = zmalloc(sizeof(struct ltt_ust_channel));
        if (luc == NULL) {
-               perror("ltt_ust_channel zmalloc");
+               PERROR("ltt_ust_channel zmalloc");
                goto error;
        }
 
@@ -171,7 +174,7 @@ struct ltt_ust_channel *trace_ust_create_channel(struct lttng_channel *chan,
        /* Set trace output path */
        ret = snprintf(luc->pathname, PATH_MAX, "%s", path);
        if (ret < 0) {
-               perror("asprintf ust create channel");
+               PERROR("asprintf ust create channel");
                goto error_free_channel;
        }
 
@@ -180,6 +183,8 @@ struct ltt_ust_channel *trace_ust_create_channel(struct lttng_channel *chan,
        return luc;
 
 error_free_channel:
+       lttng_ht_destroy(luc->ctx);
+       lttng_ht_destroy(luc->events);
        free(luc);
 error:
        return NULL;
@@ -236,7 +241,7 @@ struct ltt_ust_event *trace_ust_create_event(struct lttng_event *ev)
                lue->attr.loglevel = ev->loglevel;
                break;
        default:
-               ERR("Unknown ust loglevel type (%d)", ev->type);
+               ERR("Unknown ust loglevel type (%d)", ev->loglevel_type);
                goto error_free_event;
        }
 
@@ -253,6 +258,7 @@ struct ltt_ust_event *trace_ust_create_event(struct lttng_event *ev)
        return lue;
 
 error_free_event:
+       lttng_ht_destroy(lue->ctx);
        free(lue);
 error:
        return NULL;
@@ -270,7 +276,7 @@ struct ltt_ust_metadata *trace_ust_create_metadata(char *path)
 
        lum = zmalloc(sizeof(struct ltt_ust_metadata));
        if (lum == NULL) {
-               perror("ust metadata zmalloc");
+               PERROR("ust metadata zmalloc");
                goto error;
        }
 
@@ -286,7 +292,7 @@ struct ltt_ust_metadata *trace_ust_create_metadata(char *path)
        /* Set metadata trace path */
        ret = snprintf(lum->pathname, PATH_MAX, "%s/metadata", path);
        if (ret < 0) {
-               perror("asprintf ust metadata");
+               PERROR("asprintf ust metadata");
                goto error_free_metadata;
        }
 
@@ -453,8 +459,10 @@ static void destroy_channel_rcu(struct rcu_head *head)
  */
 void trace_ust_destroy_metadata(struct ltt_ust_metadata *metadata)
 {
+       if (!metadata->handle) {
+               return;
+       }
        DBG2("Trace UST destroy metadata %d", metadata->handle);
-
        free(metadata);
 }
 
index 7459218d3bb9eb9d8b2e0913d13cd7b1aaf64702..4513bafee6847581aa0f401a52cd17f880028b85 100644 (file)
@@ -1,19 +1,18 @@
 /*
  * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; only version 2
- * of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
  * This program 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 General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #ifndef _LTT_TRACE_UST_H
index 030358241f663548265493bd2459c00977be0013..7dbea5c182ca4c6e1a54a89c74a3f0f2c737fe23 100644 (file)
@@ -1,19 +1,18 @@
 /*
  * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; only version 2
- * of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
  * This program 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 General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #define _GNU_SOURCE
@@ -32,6 +31,7 @@
 #include "ust-app.h"
 #include "ust-consumer.h"
 #include "ust-ctl.h"
+#include "fd-limit.h"
 
 /*
  * Delete ust context safely. RCU read lock must be held before calling
@@ -83,6 +83,7 @@ void delete_ust_app_stream(int sock, struct ltt_ust_stream *stream)
 {
        if (stream->obj) {
                ustctl_release_object(sock, stream->obj);
+               lttng_fd_put(LTTNG_FD_APPS, 2);
                free(stream->obj);
        }
        free(stream);
@@ -126,6 +127,7 @@ void delete_ust_app_channel(int sock, struct ust_app_channel *ua_chan)
 
        if (ua_chan->obj != NULL) {
                ustctl_release_object(sock, ua_chan->obj);
+               lttng_fd_put(LTTNG_FD_APPS, 2);
                free(ua_chan->obj);
        }
        free(ua_chan);
@@ -145,12 +147,15 @@ void delete_ust_app_session(int sock, struct ust_app_session *ua_sess)
        if (ua_sess->metadata) {
                if (ua_sess->metadata->stream_obj) {
                        ustctl_release_object(sock, ua_sess->metadata->stream_obj);
+                       lttng_fd_put(LTTNG_FD_APPS, 2);
                        free(ua_sess->metadata->stream_obj);
                }
                if (ua_sess->metadata->obj) {
                        ustctl_release_object(sock, ua_sess->metadata->obj);
+                       lttng_fd_put(LTTNG_FD_APPS, 2);
                        free(ua_sess->metadata->obj);
                }
+               trace_ust_destroy_metadata(ua_sess->metadata);
        }
 
        cds_lfht_for_each_entry(ua_sess->channels->ht, &iter.iter, ua_chan,
@@ -181,26 +186,38 @@ void delete_ust_app(struct ust_app *app)
        rcu_read_lock();
 
        /* Delete ust app sessions info */
-       sock = app->key.sock;
-       app->key.sock = -1;
+       sock = app->sock;
+       app->sock = -1;
 
        /* Wipe sessions */
        cds_lfht_for_each_entry(app->sessions->ht, &iter.iter, ua_sess,
                        node.node) {
                ret = lttng_ht_del(app->sessions, &iter);
                assert(!ret);
-               delete_ust_app_session(app->key.sock, ua_sess);
+               delete_ust_app_session(app->sock, ua_sess);
        }
        lttng_ht_destroy(app->sessions);
 
        /*
-        * Wait until we have removed the key from the sock hash table before
-        * closing this socket, otherwise an application could re-use the socket ID
-        * and race with the teardown, using the same hash table entry.
+        * Wait until we have deleted the application from the sock hash table
+        * before closing this socket, otherwise an application could re-use the
+        * socket ID and race with the teardown, using the same hash table entry.
+        *
+        * It's OK to leave the close in call_rcu. We want it to stay unique for
+        * all RCU readers that could run concurrently with unregister app,
+        * therefore we _need_ to only close that socket after a grace period. So
+        * it should stay in this RCU callback.
+        *
+        * This close() is a very important step of the synchronization model so
+        * every modification to this function must be carefully reviewed.
         */
-       close(sock);
+       ret = close(sock);
+       if (ret) {
+               PERROR("close");
+       }
+       lttng_fd_put(LTTNG_FD_APPS, 1);
 
-       DBG2("UST app pid %d deleted", app->key.pid);
+       DBG2("UST app pid %d deleted", app->pid);
        free(app);
 
        rcu_read_unlock();
@@ -215,9 +232,9 @@ void delete_ust_app_rcu(struct rcu_head *head)
        struct lttng_ht_node_ulong *node =
                caa_container_of(head, struct lttng_ht_node_ulong, head);
        struct ust_app *app =
-               caa_container_of(node, struct ust_app, node);
+               caa_container_of(node, struct ust_app, pid_n);
 
-       DBG3("Call RCU deleting app PID %d", app->key.pid);
+       DBG3("Call RCU deleting app PID %d", app->pid);
        delete_ust_app(app);
 }
 
@@ -352,25 +369,16 @@ static
 struct ust_app *find_app_by_sock(int sock)
 {
        struct lttng_ht_node_ulong *node;
-       struct ust_app_key *key;
        struct lttng_ht_iter iter;
 
-       lttng_ht_lookup(ust_app_sock_key_map, (void *)((unsigned long) sock),
-                       &iter);
-       node = lttng_ht_iter_get_node_ulong(&iter);
-       if (node == NULL) {
-               DBG2("UST app find by sock %d key not found", sock);
-               goto error;
-       }
-       key = caa_container_of(node, struct ust_app_key, node);
-
-       lttng_ht_lookup(ust_app_ht, (void *)((unsigned long) key->pid), &iter);
+       lttng_ht_lookup(ust_app_ht_by_sock, (void *)((unsigned long) sock), &iter);
        node = lttng_ht_iter_get_node_ulong(&iter);
        if (node == NULL) {
                DBG2("UST app find by sock %d not found", sock);
                goto error;
        }
-       return caa_container_of(node, struct ust_app, node);
+
+       return caa_container_of(node, struct ust_app, sock_n);
 
 error:
        return NULL;
@@ -385,7 +393,7 @@ int create_ust_channel_context(struct ust_app_channel *ua_chan,
 {
        int ret;
 
-       ret = ustctl_add_context(app->key.sock, &ua_ctx->ctx,
+       ret = ustctl_add_context(app->sock, &ua_ctx->ctx,
                        ua_chan->obj, &ua_ctx->obj);
        if (ret < 0) {
                goto error;
@@ -408,7 +416,7 @@ int create_ust_event_context(struct ust_app_event *ua_event,
 {
        int ret;
 
-       ret = ustctl_add_context(app->key.sock, &ua_ctx->ctx,
+       ret = ustctl_add_context(app->sock, &ua_ctx->ctx,
                        ua_event->obj, &ua_ctx->obj);
        if (ret < 0) {
                goto error;
@@ -430,16 +438,16 @@ static int disable_ust_event(struct ust_app *app,
 {
        int ret;
 
-       ret = ustctl_disable(app->key.sock, ua_event->obj);
+       ret = ustctl_disable(app->sock, ua_event->obj);
        if (ret < 0) {
                ERR("UST app event %s disable failed for app (pid: %d) "
                                "and session handle %d with ret %d",
-                               ua_event->attr.name, app->key.pid, ua_sess->handle, ret);
+                               ua_event->attr.name, app->pid, ua_sess->handle, ret);
                goto error;
        }
 
        DBG2("UST app event %s disabled successfully for app (pid: %d)",
-                       ua_event->attr.name, app->key.pid);
+                       ua_event->attr.name, app->pid);
 
 error:
        return ret;
@@ -453,16 +461,16 @@ static int disable_ust_channel(struct ust_app *app,
 {
        int ret;
 
-       ret = ustctl_disable(app->key.sock, ua_chan->obj);
+       ret = ustctl_disable(app->sock, ua_chan->obj);
        if (ret < 0) {
                ERR("UST app channel %s disable failed for app (pid: %d) "
                                "and session handle %d with ret %d",
-                               ua_chan->name, app->key.pid, ua_sess->handle, ret);
+                               ua_chan->name, app->pid, ua_sess->handle, ret);
                goto error;
        }
 
        DBG2("UST app channel %s disabled successfully for app (pid: %d)",
-                       ua_chan->name, app->key.pid);
+                       ua_chan->name, app->pid);
 
 error:
        return ret;
@@ -476,18 +484,18 @@ static int enable_ust_channel(struct ust_app *app,
 {
        int ret;
 
-       ret = ustctl_enable(app->key.sock, ua_chan->obj);
+       ret = ustctl_enable(app->sock, ua_chan->obj);
        if (ret < 0) {
                ERR("UST app channel %s enable failed for app (pid: %d) "
                                "and session handle %d with ret %d",
-                               ua_chan->name, app->key.pid, ua_sess->handle, ret);
+                               ua_chan->name, app->pid, ua_sess->handle, ret);
                goto error;
        }
 
        ua_chan->enabled = 1;
 
        DBG2("UST app channel %s enabled successfully for app (pid: %d)",
-                       ua_chan->name, app->key.pid);
+                       ua_chan->name, app->pid);
 
 error:
        return ret;
@@ -501,16 +509,16 @@ static int enable_ust_event(struct ust_app *app,
 {
        int ret;
 
-       ret = ustctl_enable(app->key.sock, ua_event->obj);
+       ret = ustctl_enable(app->sock, ua_event->obj);
        if (ret < 0) {
                ERR("UST app event %s enable failed for app (pid: %d) "
                                "and session handle %d with ret %d",
-                               ua_event->attr.name, app->key.pid, ua_sess->handle, ret);
+                               ua_event->attr.name, app->pid, ua_sess->handle, ret);
                goto error;
        }
 
        DBG2("UST app event %s enabled successfully for app (pid: %d)",
-                       ua_event->attr.name, app->key.pid);
+                       ua_event->attr.name, app->pid);
 
 error:
        return ret;
@@ -534,12 +542,18 @@ static int open_ust_metadata(struct ust_app *app,
                ua_sess->metadata->attr.read_timer_interval;
        uattr.output = ua_sess->metadata->attr.output;
 
+       /* We are going to receive 2 fds, we need to reserve them. */
+       ret = lttng_fd_get(LTTNG_FD_APPS, 2);
+       if (ret < 0) {
+               ERR("Exhausted number of available FD upon metadata open");
+               goto error;
+       }
        /* UST tracer metadata creation */
-       ret = ustctl_open_metadata(app->key.sock, ua_sess->handle, &uattr,
+       ret = ustctl_open_metadata(app->sock, ua_sess->handle, &uattr,
                        &ua_sess->metadata->obj);
        if (ret < 0) {
                ERR("UST app open metadata failed for app pid:%d with ret %d",
-                               app->key.pid, ret);
+                               app->pid, ret);
                goto error;
        }
 
@@ -557,7 +571,13 @@ static int create_ust_stream(struct ust_app *app,
 {
        int ret;
 
-       ret = ustctl_create_stream(app->key.sock, ua_sess->metadata->obj,
+       /* We are going to receive 2 fds, we need to reserve them. */
+       ret = lttng_fd_get(LTTNG_FD_APPS, 2);
+       if (ret < 0) {
+               ERR("Exhausted number of available FD upon metadata stream create");
+               goto error;
+       }
+       ret = ustctl_create_stream(app->sock, ua_sess->metadata->obj,
                        &ua_sess->metadata->stream_obj);
        if (ret < 0) {
                ERR("UST create metadata stream failed");
@@ -577,20 +597,28 @@ static int create_ust_channel(struct ust_app *app,
        int ret;
 
        /* TODO: remove cast and use lttng-ust-abi.h */
-       ret = ustctl_create_channel(app->key.sock, ua_sess->handle,
+
+       /* We are going to receive 2 fds, we need to reserve them. */
+       ret = lttng_fd_get(LTTNG_FD_APPS, 2);
+       if (ret < 0) {
+               ERR("Exhausted number of available FD upon create channel");
+               goto error;
+       }
+       ret = ustctl_create_channel(app->sock, ua_sess->handle,
                        (struct lttng_ust_channel_attr *)&ua_chan->attr, &ua_chan->obj);
        if (ret < 0) {
                ERR("Creating channel %s for app (pid: %d, sock: %d) "
                                "and session handle %d with ret %d",
-                               ua_chan->name, app->key.pid, app->key.sock,
+                               ua_chan->name, app->pid, app->sock,
                                ua_sess->handle, ret);
+               lttng_fd_put(LTTNG_FD_APPS, 2);
                goto error;
        }
 
        ua_chan->handle = ua_chan->obj->handle;
 
        DBG2("UST app channel %s created successfully for pid:%d and sock:%d",
-                       ua_chan->name, app->key.pid, app->key.sock);
+                       ua_chan->name, app->pid, app->sock);
 
        /* If channel is not enabled, disable it on the tracer */
        if (!ua_chan->enabled) {
@@ -614,7 +642,7 @@ int create_ust_event(struct ust_app *app, struct ust_app_session *ua_sess,
        int ret = 0;
 
        /* Create UST event on tracer */
-       ret = ustctl_create_event(app->key.sock, &ua_event->attr, ua_chan->obj,
+       ret = ustctl_create_event(app->sock, &ua_event->attr, ua_chan->obj,
                        &ua_event->obj);
        if (ret < 0) {
                if (ret == -EEXIST) {
@@ -622,14 +650,14 @@ int create_ust_event(struct ust_app *app, struct ust_app_session *ua_sess,
                        goto error;
                }
                ERR("Error ustctl create event %s for app pid: %d with ret %d",
-                               ua_event->attr.name, app->key.pid, ret);
+                               ua_event->attr.name, app->pid, ret);
                goto error;
        }
 
        ua_event->handle = ua_event->obj->handle;
 
        DBG2("UST app event %s created successfully for pid:%d",
-                       ua_event->attr.name, app->key.pid);
+                       ua_event->attr.name, app->pid);
 
        /* If event not enabled, disable it on the tracer */
        if (ua_event->enabled == 0) {
@@ -770,7 +798,7 @@ static void shadow_copy_session(struct ust_app_session *ua_sess,
        ua_sess->gid = usess->gid;
 
        ret = snprintf(ua_sess->path, PATH_MAX, "%s/%s-%d-%s", usess->pathname,
-                       app->name, app->key.pid, datetime);
+                       app->name, app->pid, datetime);
        if (ret < 0) {
                PERROR("asprintf UST shadow copy session");
                /* TODO: We cannot return an error from here.. */
@@ -852,7 +880,7 @@ static struct ust_app_session *create_ust_app_session(
        ua_sess = lookup_session_by_app(usess, app);
        if (ua_sess == NULL) {
                DBG2("UST app pid: %d session id %d not found, creating it",
-                               app->key.pid, usess->id);
+                               app->pid, usess->id);
                ua_sess = alloc_ust_app_session();
                if (ua_sess == NULL) {
                        /* Only malloc can failed so something is really wrong */
@@ -862,9 +890,9 @@ static struct ust_app_session *create_ust_app_session(
        }
 
        if (ua_sess->handle == -1) {
-               ret = ustctl_create_session(app->key.sock);
+               ret = ustctl_create_session(app->sock);
                if (ret < 0) {
-                       ERR("Creating session for app pid %d", app->key.pid);
+                       ERR("Creating session for app pid %d", app->pid);
                        /* This means that the tracer is gone... */
                        ua_sess = (void*) -1UL;
                        goto error;
@@ -1095,7 +1123,7 @@ static struct ust_app_channel *create_ust_app_channel(
        lttng_ht_add_unique_str(ua_sess->channels, &ua_chan->node);
 
        DBG2("UST app create channel %s for PID %d completed", ua_chan->name,
-                       app->key.pid);
+                       app->pid);
 
 end:
        return ua_chan;
@@ -1146,7 +1174,7 @@ int create_ust_app_event(struct ust_app_session *ua_sess,
        lttng_ht_add_unique_str(ua_chan->events, &ua_event->node);
 
        DBG2("UST app create event %s for PID %d completed", ua_event->name,
-                       app->key.pid);
+                       app->pid);
 
 end:
        return ret;
@@ -1187,7 +1215,7 @@ static int create_ust_app_metadata(struct ust_app_session *ua_sess,
                        goto error;
                }
 
-               DBG2("UST metadata opened for app pid %d", app->key.pid);
+               DBG2("UST metadata opened for app pid %d", app->pid);
        }
 
        /* Open UST metadata stream */
@@ -1212,7 +1240,7 @@ static int create_ust_app_metadata(struct ust_app_session *ua_sess,
                }
 
                DBG2("UST metadata stream object created for app pid %d",
-                               app->key.pid);
+                               app->pid);
        } else {
                ERR("Attempting to create stream without metadata opened");
                goto error;
@@ -1251,7 +1279,7 @@ struct ust_app *ust_app_find_by_pid(pid_t pid)
 
        DBG2("Found UST app by pid %d", pid);
 
-       return caa_container_of(node, struct ust_app, node);
+       return caa_container_of(node, struct ust_app, pid_n);
 
 error:
        rcu_read_unlock();
@@ -1268,20 +1296,29 @@ error:
 int ust_app_register(struct ust_register_msg *msg, int sock)
 {
        struct ust_app *lta;
+       int ret;
 
        if ((msg->bits_per_long == 64 && ust_consumerd64_fd == -EINVAL)
                        || (msg->bits_per_long == 32 && ust_consumerd32_fd == -EINVAL)) {
                ERR("Registration failed: application \"%s\" (pid: %d) has "
                        "%d-bit long, but no consumerd for this long size is available.\n",
                        msg->name, msg->pid, msg->bits_per_long);
-               close(sock);
+               ret = close(sock);
+               if (ret) {
+                       PERROR("close");
+               }
+               lttng_fd_put(LTTNG_FD_APPS, 1);
                return -EINVAL;
        }
        if (msg->major != LTTNG_UST_COMM_MAJOR) {
                ERR("Registration failed: application \"%s\" (pid: %d) has "
                        "communication protocol version %u.%u, but sessiond supports 2.x.\n",
                        msg->name, msg->pid, msg->major, msg->minor);
-               close(sock);
+               ret = close(sock);
+               if (ret) {
+                       PERROR("close");
+               }
+               lttng_fd_put(LTTNG_FD_APPS, 1);
                return -EINVAL;
        }
        lta = zmalloc(sizeof(struct ust_app));
@@ -1301,20 +1338,31 @@ int ust_app_register(struct ust_register_msg *msg, int sock)
        lta->name[16] = '\0';
        lta->sessions = lttng_ht_new(0, LTTNG_HT_TYPE_ULONG);
 
-       /* Set key map */
-       lta->key.pid = msg->pid;
-       lttng_ht_node_init_ulong(&lta->node, (unsigned long)lta->key.pid);
-       lta->key.sock = sock;
-       lttng_ht_node_init_ulong(&lta->key.node, (unsigned long)lta->key.sock);
+       lta->pid = msg->pid;
+       lttng_ht_node_init_ulong(&lta->pid_n, (unsigned long)lta->pid);
+       lta->sock = sock;
+       lttng_ht_node_init_ulong(&lta->sock_n, (unsigned long)lta->sock);
 
        rcu_read_lock();
-       lttng_ht_add_unique_ulong(ust_app_sock_key_map, &lta->key.node);
-       lttng_ht_add_unique_ulong(ust_app_ht, &lta->node);
+
+       /*
+        * On a re-registration, we want to kick out the previous registration of
+        * that pid
+        */
+       lttng_ht_add_replace_ulong(ust_app_ht, &lta->pid_n);
+
+       /*
+        * The socket _should_ be unique until _we_ call close. So, a add_unique
+        * for the ust_app_ht_by_sock is used which asserts fail if the entry was
+        * already in the table.
+        */
+       lttng_ht_add_unique_ulong(ust_app_ht_by_sock, &lta->sock_n);
+
        rcu_read_unlock();
 
        DBG("App registered with pid:%d ppid:%d uid:%d gid:%d sock:%d name:%s"
-                       " (version %d.%d)", lta->key.pid, lta->ppid, lta->uid, lta->gid,
-                       lta->key.sock, lta->name, lta->v_major, lta->v_minor);
+                       " (version %d.%d)", lta->pid, lta->ppid, lta->uid, lta->gid,
+                       lta->sock, lta->name, lta->v_major, lta->v_minor);
 
        return 0;
 }
@@ -1333,31 +1381,32 @@ void ust_app_unregister(int sock)
        int ret;
 
        rcu_read_lock();
-       lta = find_app_by_sock(sock);
-       if (lta == NULL) {
-               ERR("Unregister app sock %d not found!", sock);
-               goto error;
-       }
-
-       DBG("PID %d unregistering with sock %d", lta->key.pid, sock);
-
-       /* Remove application from socket hash table */
-       lttng_ht_lookup(ust_app_sock_key_map, (void *)((unsigned long) sock), &iter);
-       ret = lttng_ht_del(ust_app_sock_key_map, &iter);
-       assert(!ret);
 
        /* Get the node reference for a call_rcu */
-       lttng_ht_lookup(ust_app_ht, (void *)((unsigned long) lta->key.pid), &iter);
+       lttng_ht_lookup(ust_app_ht_by_sock, (void *)((unsigned long) sock), &iter);
        node = lttng_ht_iter_get_node_ulong(&iter);
        if (node == NULL) {
-               ERR("Unable to find app sock %d by pid %d", sock, lta->key.pid);
+               ERR("Unable to find app by sock %d", sock);
                goto error;
        }
 
+       lta = caa_container_of(node, struct ust_app, sock_n);
+
+       DBG("PID %d unregistering with sock %d", lta->pid, sock);
+
        /* Remove application from PID hash table */
+       ret = lttng_ht_del(ust_app_ht_by_sock, &iter);
+       assert(!ret);
+
+       /* Assign second node for deletion */
+       iter.iter.node = &lta->pid_n.node;
+
        ret = lttng_ht_del(ust_app_ht, &iter);
        assert(!ret);
-       call_rcu(&node->head, delete_ust_app_rcu);
+
+       /* Free memory */
+       call_rcu(&lta->pid_n.head, delete_ust_app_rcu);
+
 error:
        rcu_read_unlock();
        return;
@@ -1398,7 +1447,7 @@ int ust_app_list_events(struct lttng_event **events)
 
        rcu_read_lock();
 
-       cds_lfht_for_each_entry(ust_app_ht->ht, &iter.iter, app, node.node) {
+       cds_lfht_for_each_entry(ust_app_ht->ht, &iter.iter, app, pid_n.node) {
                struct lttng_ust_tracepoint_iter uiter;
 
                if (!app->compatible) {
@@ -1408,14 +1457,14 @@ int ust_app_list_events(struct lttng_event **events)
                         */
                        continue;
                }
-               handle = ustctl_tracepoint_list(app->key.sock);
+               handle = ustctl_tracepoint_list(app->sock);
                if (handle < 0) {
                        ERR("UST app list events getting handle failed for app pid %d",
-                                       app->key.pid);
+                                       app->pid);
                        continue;
                }
 
-               while ((ret = ustctl_tracepoint_list_get(app->key.sock, handle,
+               while ((ret = ustctl_tracepoint_list_get(app->sock, handle,
                                                &uiter)) != -ENOENT) {
                        if (count >= nbmem) {
                                DBG2("Reallocating event list from %zu to %zu entries", nbmem,
@@ -1431,7 +1480,7 @@ int ust_app_list_events(struct lttng_event **events)
                        memcpy(tmp[count].name, uiter.name, LTTNG_UST_SYM_NAME_LEN);
                        tmp[count].loglevel = uiter.loglevel;
                        tmp[count].type = LTTNG_UST_TRACEPOINT;
-                       tmp[count].pid = app->key.pid;
+                       tmp[count].pid = app->pid;
                        tmp[count].enabled = -1;
                        count++;
                }
@@ -1466,15 +1515,16 @@ void ust_app_clean_list(void)
                assert(!ret);
                call_rcu(&node->head, delete_ust_app_rcu);
        }
-       /* Destroy is done only when the ht is empty */
-       lttng_ht_destroy(ust_app_ht);
 
-       cds_lfht_for_each_entry(ust_app_sock_key_map->ht, &iter.iter, node, node) {
-               ret = lttng_ht_del(ust_app_sock_key_map, &iter);
+       /* Cleanup socket hash table */
+       cds_lfht_for_each_entry(ust_app_ht_by_sock->ht, &iter.iter, node, node) {
+               ret = lttng_ht_del(ust_app_ht_by_sock, &iter);
                assert(!ret);
        }
+
        /* Destroy is done only when the ht is empty */
-       lttng_ht_destroy(ust_app_sock_key_map);
+       lttng_ht_destroy(ust_app_ht);
+       lttng_ht_destroy(ust_app_ht_by_sock);
 
        rcu_read_unlock();
 }
@@ -1485,7 +1535,7 @@ void ust_app_clean_list(void)
 void ust_app_ht_alloc(void)
 {
        ust_app_ht = lttng_ht_new(0, LTTNG_HT_TYPE_ULONG);
-       ust_app_sock_key_map = lttng_ht_new(0, LTTNG_HT_TYPE_ULONG);
+       ust_app_ht_by_sock = lttng_ht_new(0, LTTNG_HT_TYPE_ULONG);
 }
 
 /*
@@ -1513,7 +1563,7 @@ int ust_app_disable_channel_glb(struct ltt_ust_session *usess,
        rcu_read_lock();
 
        /* For every registered applications */
-       cds_lfht_for_each_entry(ust_app_ht->ht, &iter.iter, app, node.node) {
+       cds_lfht_for_each_entry(ust_app_ht->ht, &iter.iter, app, pid_n.node) {
                struct lttng_ht_iter uiter;
                if (!app->compatible) {
                        /*
@@ -1574,7 +1624,7 @@ int ust_app_enable_channel_glb(struct ltt_ust_session *usess,
        rcu_read_lock();
 
        /* For every registered applications */
-       cds_lfht_for_each_entry(ust_app_ht->ht, &iter.iter, app, node.node) {
+       cds_lfht_for_each_entry(ust_app_ht->ht, &iter.iter, app, pid_n.node) {
                if (!app->compatible) {
                        /*
                         * TODO: In time, we should notice the caller of this error by
@@ -1621,7 +1671,7 @@ int ust_app_disable_event_glb(struct ltt_ust_session *usess,
        rcu_read_lock();
 
        /* For all registered applications */
-       cds_lfht_for_each_entry(ust_app_ht->ht, &iter.iter, app, node.node) {
+       cds_lfht_for_each_entry(ust_app_ht->ht, &iter.iter, app, pid_n.node) {
                if (!app->compatible) {
                        /*
                         * TODO: In time, we should notice the caller of this error by
@@ -1640,7 +1690,7 @@ int ust_app_disable_event_glb(struct ltt_ust_session *usess,
                ua_chan_node = lttng_ht_iter_get_node_str(&uiter);
                if (ua_chan_node == NULL) {
                        DBG2("Channel %s not found in session id %d for app pid %d."
-                                       "Skipping", uchan->name, usess->id, app->key.pid);
+                                       "Skipping", uchan->name, usess->id, app->pid);
                        continue;
                }
                ua_chan = caa_container_of(ua_chan_node, struct ust_app_channel, node);
@@ -1649,7 +1699,7 @@ int ust_app_disable_event_glb(struct ltt_ust_session *usess,
                ua_event_node = lttng_ht_iter_get_node_str(&uiter);
                if (ua_event_node == NULL) {
                        DBG2("Event %s not found in channel %s for app pid %d."
-                                       "Skipping", uevent->attr.name, uchan->name, app->key.pid);
+                                       "Skipping", uevent->attr.name, uchan->name, app->pid);
                        continue;
                }
                ua_event = caa_container_of(ua_event_node, struct ust_app_event, node);
@@ -1687,7 +1737,7 @@ int ust_app_disable_all_event_glb(struct ltt_ust_session *usess,
        rcu_read_lock();
 
        /* For all registered applications */
-       cds_lfht_for_each_entry(ust_app_ht->ht, &iter.iter, app, node.node) {
+       cds_lfht_for_each_entry(ust_app_ht->ht, &iter.iter, app, pid_n.node) {
                if (!app->compatible) {
                        /*
                         * TODO: In time, we should notice the caller of this error by
@@ -1744,7 +1794,7 @@ int ust_app_create_channel_glb(struct ltt_ust_session *usess,
        rcu_read_lock();
 
        /* For every registered applications */
-       cds_lfht_for_each_entry(ust_app_ht->ht, &iter.iter, app, node.node) {
+       cds_lfht_for_each_entry(ust_app_ht->ht, &iter.iter, app, pid_n.node) {
                if (!app->compatible) {
                        /*
                         * TODO: In time, we should notice the caller of this error by
@@ -1808,7 +1858,7 @@ int ust_app_enable_event_glb(struct ltt_ust_session *usess,
        rcu_read_lock();
 
        /* For all registered applications */
-       cds_lfht_for_each_entry(ust_app_ht->ht, &iter.iter, app, node.node) {
+       cds_lfht_for_each_entry(ust_app_ht->ht, &iter.iter, app, pid_n.node) {
                if (!app->compatible) {
                        /*
                         * TODO: In time, we should notice the caller of this error by
@@ -1832,7 +1882,7 @@ int ust_app_enable_event_glb(struct ltt_ust_session *usess,
                ua_event_node = lttng_ht_iter_get_node_str(&uiter);
                if (ua_event_node == NULL) {
                        DBG3("UST app enable event %s not found for app PID %d."
-                                       "Skipping app", uevent->attr.name, app->key.pid);
+                                       "Skipping app", uevent->attr.name, app->pid);
                        continue;
                }
                ua_event = caa_container_of(ua_event_node, struct ust_app_event, node);
@@ -1868,7 +1918,7 @@ int ust_app_create_event_glb(struct ltt_ust_session *usess,
        rcu_read_lock();
 
        /* For all registered applications */
-       cds_lfht_for_each_entry(ust_app_ht->ht, &iter.iter, app, node.node) {
+       cds_lfht_for_each_entry(ust_app_ht->ht, &iter.iter, app, pid_n.node) {
                if (!app->compatible) {
                        /*
                         * TODO: In time, we should notice the caller of this error by
@@ -1895,7 +1945,7 @@ int ust_app_create_event_glb(struct ltt_ust_session *usess,
                                break;
                        }
                        DBG2("UST app event %s already exist on app PID %d",
-                                       uevent->attr.name, app->key.pid);
+                                       uevent->attr.name, app->pid);
                        continue;
                }
        }
@@ -1917,7 +1967,7 @@ int ust_app_start_trace(struct ltt_ust_session *usess, struct ust_app *app)
        struct ltt_ust_stream *ustream;
        int consumerd_fd;
 
-       DBG("Starting tracing for ust app pid %d", app->key.pid);
+       DBG("Starting tracing for ust app pid %d", app->pid);
 
        rcu_read_lock();
 
@@ -1955,10 +2005,19 @@ int ust_app_start_trace(struct ltt_ust_session *usess, struct ust_app *app)
                                goto error_rcu_unlock;
                        }
 
-                       ret = ustctl_create_stream(app->key.sock, ua_chan->obj,
+                       /* We are going to receive 2 fds, we need to reserve them. */
+                       ret = lttng_fd_get(LTTNG_FD_APPS, 2);
+                       if (ret < 0) {
+                               ERR("Exhausted number of available FD upon stream create");
+                               free(ustream);
+                               goto error_rcu_unlock;
+                       }
+                       ret = ustctl_create_stream(app->sock, ua_chan->obj,
                                        &ustream->obj);
                        if (ret < 0) {
                                /* Got all streams */
+                               lttng_fd_put(LTTNG_FD_APPS, 2);
+                               free(ustream);
                                break;
                        }
                        ustream->handle = ustream->obj->handle;
@@ -1970,6 +2029,10 @@ int ust_app_start_trace(struct ltt_ust_session *usess, struct ust_app *app)
                                        ua_chan->streams.count++);
                        if (ret < 0) {
                                PERROR("asprintf UST create stream");
+                               /*
+                                * XXX what should we do here with the
+                                * stream ?
+                                */
                                continue;
                        }
                        DBG2("UST stream %d ready at %s", ua_chan->streams.count,
@@ -1997,14 +2060,14 @@ int ust_app_start_trace(struct ltt_ust_session *usess, struct ust_app *app)
 
 skip_setup:
        /* This start the UST tracing */
-       ret = ustctl_start_session(app->key.sock, ua_sess->handle);
+       ret = ustctl_start_session(app->sock, ua_sess->handle);
        if (ret < 0) {
-               ERR("Error starting tracing for app pid: %d", app->key.pid);
+               ERR("Error starting tracing for app pid: %d", app->pid);
                goto error_rcu_unlock;
        }
 
        /* Quiescent wait after starting trace */
-       ustctl_wait_quiescent(app->key.sock);
+       ustctl_wait_quiescent(app->sock);
 
 end:
        rcu_read_unlock();
@@ -2025,7 +2088,7 @@ int ust_app_stop_trace(struct ltt_ust_session *usess, struct ust_app *app)
        struct ust_app_session *ua_sess;
        struct ust_app_channel *ua_chan;
 
-       DBG("Stopping tracing for ust app pid %d", app->key.pid);
+       DBG("Stopping tracing for ust app pid %d", app->pid);
 
        rcu_read_lock();
 
@@ -2047,31 +2110,31 @@ int ust_app_stop_trace(struct ltt_ust_session *usess, struct ust_app *app)
        assert(ua_sess->started == 1);
 
        /* This inhibits UST tracing */
-       ret = ustctl_stop_session(app->key.sock, ua_sess->handle);
+       ret = ustctl_stop_session(app->sock, ua_sess->handle);
        if (ret < 0) {
-               ERR("Error stopping tracing for app pid: %d", app->key.pid);
+               ERR("Error stopping tracing for app pid: %d", app->pid);
                goto error_rcu_unlock;
        }
 
        /* Quiescent wait after stopping trace */
-       ustctl_wait_quiescent(app->key.sock);
+       ustctl_wait_quiescent(app->sock);
 
        /* Flushing buffers */
        cds_lfht_for_each_entry(ua_sess->channels->ht, &iter.iter, ua_chan,
                        node.node) {
-               ret = ustctl_sock_flush_buffer(app->key.sock, ua_chan->obj);
+               ret = ustctl_sock_flush_buffer(app->sock, ua_chan->obj);
                if (ret < 0) {
                        ERR("UST app PID %d channel %s flush failed with ret %d",
-                                       app->key.pid, ua_chan->name, ret);
+                                       app->pid, ua_chan->name, ret);
                        /* Continuing flushing all buffers */
                        continue;
                }
        }
 
        /* Flush all buffers before stopping */
-       ret = ustctl_sock_flush_buffer(app->key.sock, ua_sess->metadata->obj);
+       ret = ustctl_sock_flush_buffer(app->sock, ua_sess->metadata->obj);
        if (ret < 0) {
-               ERR("UST app PID %d metadata flush failed with ret %d", app->key.pid,
+               ERR("UST app PID %d metadata flush failed with ret %d", app->pid,
                                ret);
        }
 
@@ -2095,7 +2158,7 @@ int ust_app_destroy_trace(struct ltt_ust_session *usess, struct ust_app *app)
        struct lttng_ht_node_ulong *node;
        int ret;
 
-       DBG("Destroy tracing for ust app pid %d", app->key.pid);
+       DBG("Destroy tracing for ust app pid %d", app->pid);
 
        rcu_read_lock();
 
@@ -2116,12 +2179,12 @@ int ust_app_destroy_trace(struct ltt_ust_session *usess, struct ust_app *app)
        obj.shm_fd = -1;
        obj.wait_fd = -1;
        obj.memory_map_size = 0;
-       ustctl_release_object(app->key.sock, &obj);
+       ustctl_release_object(app->sock, &obj);
 
-       delete_ust_app_session(app->key.sock, ua_sess);
+       delete_ust_app_session(app->sock, ua_sess);
 
        /* Quiescent wait after stopping trace */
-       ustctl_wait_quiescent(app->key.sock);
+       ustctl_wait_quiescent(app->sock);
 
 end:
        rcu_read_unlock();
@@ -2145,7 +2208,7 @@ int ust_app_start_trace_all(struct ltt_ust_session *usess)
 
        rcu_read_lock();
 
-       cds_lfht_for_each_entry(ust_app_ht->ht, &iter.iter, app, node.node) {
+       cds_lfht_for_each_entry(ust_app_ht->ht, &iter.iter, app, pid_n.node) {
                ret = ust_app_start_trace(usess, app);
                if (ret < 0) {
                        /* Continue to next apps even on error */
@@ -2171,7 +2234,7 @@ int ust_app_stop_trace_all(struct ltt_ust_session *usess)
 
        rcu_read_lock();
 
-       cds_lfht_for_each_entry(ust_app_ht->ht, &iter.iter, app, node.node) {
+       cds_lfht_for_each_entry(ust_app_ht->ht, &iter.iter, app, pid_n.node) {
                ret = ust_app_stop_trace(usess, app);
                if (ret < 0) {
                        /* Continue to next apps even on error */
@@ -2197,7 +2260,7 @@ int ust_app_destroy_trace_all(struct ltt_ust_session *usess)
 
        rcu_read_lock();
 
-       cds_lfht_for_each_entry(ust_app_ht->ht, &iter.iter, app, node.node) {
+       cds_lfht_for_each_entry(ust_app_ht->ht, &iter.iter, app, pid_n.node) {
                ret = ust_app_destroy_trace(usess, app);
                if (ret < 0) {
                        /* Continue to next apps even on error */
@@ -2298,7 +2361,7 @@ void ust_app_global_update(struct ltt_ust_session *usess, int sock)
                        goto error;
                }
 
-               DBG2("UST trace started for app pid %d", app->key.pid);
+               DBG2("UST trace started for app pid %d", app->pid);
        }
 
 error:
@@ -2321,7 +2384,7 @@ int ust_app_add_ctx_channel_glb(struct ltt_ust_session *usess,
 
        rcu_read_lock();
 
-       cds_lfht_for_each_entry(ust_app_ht->ht, &iter.iter, app, node.node) {
+       cds_lfht_for_each_entry(ust_app_ht->ht, &iter.iter, app, pid_n.node) {
                if (!app->compatible) {
                        /*
                         * TODO: In time, we should notice the caller of this error by
@@ -2370,7 +2433,7 @@ int ust_app_add_ctx_event_glb(struct ltt_ust_session *usess,
 
        rcu_read_lock();
 
-       cds_lfht_for_each_entry(ust_app_ht->ht, &iter.iter, app, node.node) {
+       cds_lfht_for_each_entry(ust_app_ht->ht, &iter.iter, app, pid_n.node) {
                if (!app->compatible) {
                        /*
                         * TODO: In time, we should notice the caller of this error by
@@ -2558,7 +2621,7 @@ int ust_app_validate_version(int sock)
        }
 
        DBG2("UST app PID %d is compatible with major version %d "
-                       "(supporting <= %d)", app->key.pid, app->version.major,
+                       "(supporting <= %d)", app->pid, app->version.major,
                        UST_APP_MAJOR_VERSION);
        app->compatible = 1;
        rcu_read_unlock();
@@ -2566,7 +2629,7 @@ int ust_app_validate_version(int sock)
 
 error:
        DBG2("UST app PID %d is not compatible with major version %d "
-                       "(supporting <= %d)", app->key.pid, app->version.major,
+                       "(supporting <= %d)", app->pid, app->version.major,
                        UST_APP_MAJOR_VERSION);
        app->compatible = 0;
        rcu_read_unlock();
@@ -2584,7 +2647,7 @@ int ust_app_calibrate_glb(struct lttng_ust_calibrate *calibrate)
 
        rcu_read_lock();
 
-       cds_lfht_for_each_entry(ust_app_ht->ht, &iter.iter, app, node.node) {
+       cds_lfht_for_each_entry(ust_app_ht->ht, &iter.iter, app, pid_n.node) {
                if (!app->compatible) {
                        /*
                         * TODO: In time, we should notice the caller of this error by
@@ -2593,7 +2656,7 @@ int ust_app_calibrate_glb(struct lttng_ust_calibrate *calibrate)
                        continue;
                }
 
-               ret = ustctl_calibrate(app->key.sock, calibrate);
+               ret = ustctl_calibrate(app->sock, calibrate);
                if (ret < 0) {
                        switch (ret) {
                        case -ENOSYS:
@@ -2603,7 +2666,7 @@ int ust_app_calibrate_glb(struct lttng_ust_calibrate *calibrate)
                        default:
                                /* TODO: Report error to user */
                                DBG2("Calibrate app PID %d returned with error %d",
-                                               app->key.pid, ret);
+                                               app->pid, ret);
                                break;
                        }
                }
index 5bfecdb47deb0a8e2b2be9d872a5072f286cba3b..8e98082207a59f9f398a551aa5a7ad7041d45eba 100644 (file)
@@ -1,19 +1,18 @@
 /*
  * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; only version 2
- * of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
  * This program 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 General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #ifndef _LTT_UST_APP_H 
@@ -46,17 +45,16 @@ struct ust_register_msg {
 };
 
 /*
- * Global applications HT used by the session daemon.
+ * Global applications HT used by the session daemon. This table is indexed by
+ * PID using the pid_n node and pid value of an ust_app.
  */
 struct lttng_ht *ust_app_ht;
 
-struct lttng_ht *ust_app_sock_key_map;
-
-struct ust_app_key {
-       pid_t pid;
-       int sock;
-       struct lttng_ht_node_ulong node;
-};
+/*
+ * Global applications HT used by the session daemon. This table is indexed by
+ * socket using the sock_n node and sock value of an ust_app.
+ */
+struct lttng_ht *ust_app_ht_by_sock;
 
 struct ust_app_ctx {
        int handle;
@@ -107,6 +105,8 @@ struct ust_app_session {
  * and a linked list is kept of all running traceable app.
  */
 struct ust_app {
+       int sock;
+       pid_t pid;
        pid_t ppid;
        uid_t uid;           /* User ID that owns the apps */
        gid_t gid;           /* Group ID that owns the apps */
@@ -119,8 +119,8 @@ struct ust_app {
        uint32_t v_minor;    /* Verion minor number */
        char name[17];       /* Process name (short) */
        struct lttng_ht *sessions;
-       struct lttng_ht_node_ulong node;
-       struct ust_app_key key;
+       struct lttng_ht_node_ulong pid_n;
+       struct lttng_ht_node_ulong sock_n;
 };
 
 #ifdef HAVE_LIBLTTNG_UST_CTL
index 26ebfac496c30ed9aa33d53028f36f8cd0495a92..03b0c7d03ecee91f63dff4317dc956c10130f7fc 100644 (file)
@@ -1,18 +1,18 @@
 /*
  * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
  *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; only version 2 of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
- * This program 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 General Public License for
- * more details.
+ * This program 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 General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place - Suite 330, Boston, MA  02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #define _GNU_SOURCE
@@ -58,13 +58,13 @@ static int send_channel_streams(int sock,
        DBG("Sending channel %d to consumer", lum.u.channel.channel_key);
        ret = lttcomm_send_unix_sock(sock, &lum, sizeof(lum));
        if (ret < 0) {
-               perror("send consumer channel");
+               PERROR("send consumer channel");
                goto error;
        }
        fd = uchan->obj->shm_fd;
        ret = lttcomm_send_fds_unix_sock(sock, &fd, 1);
        if (ret < 0) {
-               perror("send consumer channel ancillary data");
+               PERROR("send consumer channel ancillary data");
                goto error;
        }
 
@@ -91,7 +91,7 @@ static int send_channel_streams(int sock,
                DBG("Sending stream %d to consumer", lum.u.stream.stream_key);
                ret = lttcomm_send_unix_sock(sock, &lum, sizeof(lum));
                if (ret < 0) {
-                       perror("send consumer stream");
+                       PERROR("send consumer stream");
                        goto error;
                }
 
@@ -99,7 +99,7 @@ static int send_channel_streams(int sock,
                fds[1] = stream->obj->wait_fd;
                ret = lttcomm_send_fds_unix_sock(sock, fds, 2);
                if (ret < 0) {
-                       perror("send consumer stream ancillary data");
+                       PERROR("send consumer stream ancillary data");
                        goto error;
                }
        }
@@ -142,13 +142,13 @@ int ust_consumer_send_session(int consumer_fd, struct ust_app_session *usess)
                DBG("Sending metadata channel %d to consumer", lum.u.channel.channel_key);
                ret = lttcomm_send_unix_sock(sock, &lum, sizeof(lum));
                if (ret < 0) {
-                       perror("send consumer channel");
+                       PERROR("send consumer channel");
                        goto error;
                }
                fd = usess->metadata->obj->shm_fd;
                ret = lttcomm_send_fds_unix_sock(sock, &fd, 1);
                if (ret < 0) {
-                       perror("send consumer metadata channel");
+                       PERROR("send consumer metadata channel");
                        goto error;
                }
 
@@ -166,14 +166,14 @@ int ust_consumer_send_session(int consumer_fd, struct ust_app_session *usess)
                DBG("Sending metadata stream %d to consumer", lum.u.stream.stream_key);
                ret = lttcomm_send_unix_sock(sock, &lum, sizeof(lum));
                if (ret < 0) {
-                       perror("send consumer metadata stream");
+                       PERROR("send consumer metadata stream");
                        goto error;
                }
                fds[0] = usess->metadata->stream_obj->shm_fd;
                fds[1] = usess->metadata->stream_obj->wait_fd;
                ret = lttcomm_send_fds_unix_sock(sock, fds, 2);
                if (ret < 0) {
-                       perror("send consumer stream");
+                       PERROR("send consumer stream");
                        goto error;
                }
        }
@@ -182,6 +182,14 @@ int ust_consumer_send_session(int consumer_fd, struct ust_app_session *usess)
        rcu_read_lock();
        cds_lfht_for_each_entry(usess->channels->ht, &iter.iter, ua_chan,
                        node.node) {
+               /*
+                * Indicate that the channel was not created on the tracer side so skip
+                * sending unexisting streams.
+                */
+               if (ua_chan->obj == NULL) {
+                       continue;
+               }
+
                ret = send_channel_streams(sock, ua_chan, usess->uid, usess->gid);
                if (ret < 0) {
                        rcu_read_unlock();
index 85169e6b81919d43879e2a459b7ae338050010f6..0afb08f3d34d243b1305f4c779358f4cd4df421a 100644 (file)
@@ -1,18 +1,18 @@
 /*
  * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
  *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; only version 2 of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
- * This program 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 General Public License for
- * more details.
+ * This program 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 General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place - Suite 330, Boston, MA  02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #ifndef _UST_CONSUMER_H
index f4f34ee2f00bc32eecc3ad434c0f9737409e7a63..fd0fc7ad0a006fb22e3428025b6fe012c25dff50 100644 (file)
@@ -5,18 +5,18 @@
  *
  * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
  *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; only version 2 of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
- * This program 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 General Public License for
- * more details.
+ * This program 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 General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place - Suite 330, Boston, MA  02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #ifndef _LTT_UST_CTL_H
index 6c4ef0636927a346485e54685c98623704531c05..ce2e97561f0170c3dbdb072370e79b1e5ec502ae 100644 (file)
@@ -2,18 +2,18 @@
  * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
  *                      Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; only version 2 of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
- * This program 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 General Public License for
- * more details.
+ * This program 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 General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place - Suite 330, Boston, MA  02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #define _GNU_SOURCE
index e20ec4e9e2b5af5ed88be9d64235aeeee26f2a81..d4bd8c286f9df4b0f577029677d2a92d150a5f13 100644 (file)
@@ -1,18 +1,18 @@
 /*
  * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
  *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; only version 2 of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
- * This program 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 General Public License for
- * more details.
+ * This program 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 General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place - Suite 330, Boston, MA  02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #ifndef _LTT_UTILS_H
index fa3e217468abba881c4a8f806547a7ef9a9ca0b3..27de0d5a0f1c61b9218c98b2a5e3d356b1612a50 100644 (file)
@@ -1,19 +1,18 @@
 /*
  * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; only version 2
- * of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
  * This program 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 General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #ifndef _LTTNG_CMD_H
@@ -27,7 +26,7 @@
 #include "utils.h"
 
 enum cmd_error_code {
-       CMD_SUCCESS,
+       CMD_SUCCESS = 0,
        CMD_ERROR,
        CMD_UNDEFINED,
        CMD_FATAL,
index 4aeeff24e86d805fff5a40c679b80fa798da56f6..afeaa0628c130f53e2596a35f80d1aa57f210a93 100644 (file)
@@ -1,19 +1,18 @@
 /*
  * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; only version 2
- * of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
  * This program 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 General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #define _GNU_SOURCE
index 61b588e1294eead110e14bb5e043f0d74318b065..a14570eea5e3341b173595ff91c07323e66d2cbb 100644 (file)
@@ -2,19 +2,18 @@
  * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
  * Copyright (C) 2011 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; only version 2
- * of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
  * This program 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 General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #define _GNU_SOURCE
index 8052826a245296b0d2d9c310165385a11c5f6ad9..b1f3e8a777a0420ca4f5de66c7c9032118780015 100644 (file)
@@ -1,19 +1,18 @@
 /*
  * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; only version 2
- * of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
  * This program 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 General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #define _GNU_SOURCE
@@ -29,6 +28,8 @@
 #include "../command.h"
 #include "../utils.h"
 
+#include <common/sessiond-comm/sessiond-comm.h>
+
 static char *opt_output_path;
 static char *opt_session_name;
 
@@ -120,6 +121,11 @@ static int create_session()
        ret = lttng_create_session(session_name, traces_path);
        if (ret < 0) {
                /* Don't set ret so lttng can interpret the sessiond error. */
+               switch (-ret) {
+               case LTTCOMM_EXIST_SESS:
+                       WARN("Session %s already exists", session_name);
+                       break;
+               }
                goto error;
        }
 
index e1833c89ccd8183609f0b18065764691ac6117ae..a179da83f576ce3700ba3d2148df6235d3b2f2fb 100644 (file)
@@ -1,19 +1,18 @@
 /*
  * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; only version 2
- * of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
  * This program 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 General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #define _GNU_SOURCE
@@ -27,6 +26,8 @@
 
 #include "../command.h"
 
+#include <common/sessiond-comm/sessiond-comm.h>
+
 static char *opt_session_name;
 
 enum {
@@ -77,7 +78,13 @@ static int destroy_session()
 
        ret = lttng_destroy_session(session_name);
        if (ret < 0) {
-               /* Don't set ret so lttng can interpret the sessiond error. */
+               switch (-ret) {
+               case LTTCOMM_SESS_NOT_FOUND:
+                       WARN("Session name %s not found", session_name);
+                       break;
+               default:
+                       break;
+               }
                goto free_name;
        }
 
index cfc8561d9ef0339a660ced29dec9677b00670f62..7378ee7a0fd59309bb9ba0b382ec527e63321df9 100644 (file)
@@ -1,19 +1,18 @@
 /*
  * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; only version 2
- * of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
  * This program 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 General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #define _GNU_SOURCE
index 0a9c833bbb6559fdd3327fff81a65d4290a2cee1..c0b8bf9d012d53ed908a8bea019d7ba64955a851 100644 (file)
@@ -1,19 +1,18 @@
 /*
  * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; only version 2
- * of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
  * This program 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 General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #define _GNU_SOURCE
index 4a737d28d9ae07a4cb2731d74f3c1bffbffa1e5e..9b5f8d64d302b276f3faee598c30e43dfcde28a2 100644 (file)
@@ -1,19 +1,18 @@
 /*
  * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; only version 2
- * of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
  * This program 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 General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #define _GNU_SOURCE
@@ -28,6 +27,8 @@
 
 #include "../command.h"
 
+#include <src/common/sessiond-comm/sessiond-comm.h>
+
 static char *opt_channels;
 static int opt_kernel;
 static char *opt_session_name;
@@ -190,8 +191,17 @@ static int enable_channel(char *session_name)
 
                ret = lttng_enable_channel(handle, &chan);
                if (ret < 0) {
-                       ERR("Channel %s: %s (session %s)", channel_name,
-                                       lttng_strerror(ret), session_name);
+                       switch (-ret) {
+                       case LTTCOMM_KERN_CHAN_EXIST:
+                       case LTTCOMM_UST_CHAN_EXIST:
+                               WARN("Channel %s: %s (session %s", channel_name,
+                                               lttng_strerror(ret), session_name);
+                               goto error;
+                       default:
+                               ERR("Channel %s: %s (session %s)", channel_name,
+                                               lttng_strerror(ret), session_name);
+                               break;
+                       }
                        warn = 1;
                } else {
                        MSG("%s channel %s enabled for session %s",
index b5b46fb36f373fdbd3b8bcc611d0583e68522c4d..5dda8bf8c64ceaa3895c48b7dbbe3dd323d0e876 100644 (file)
@@ -1,19 +1,18 @@
 /*
  * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; only version 2
- * of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
  * This program 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 General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #define _GNU_SOURCE
@@ -28,6 +27,7 @@
 #include <ctype.h>
 
 #include "../command.h"
+#include <src/common/sessiond-comm/sessiond-comm.h>
 
 static char *opt_event_list;
 static int opt_event_type;
@@ -346,7 +346,17 @@ static int enable_events(char *session_name)
 
                ret = lttng_enable_event(handle, &ev, channel_name);
                if (ret < 0) {
-                       goto error;
+                       switch (-ret) {
+                       case LTTCOMM_KERN_EVENT_EXIST:
+                               WARN("Kernel events already enabled (channel %s, session %s)",
+                                               channel_name, session_name);
+                               break;
+                       default:
+                               ERR("Events: %s (channel %s, session %s)",
+                                               lttng_strerror(ret), channel_name, session_name);
+                               break;
+                       }
+                       goto end;
                }
 
                switch (opt_event_type) {
@@ -493,8 +503,17 @@ static int enable_events(char *session_name)
 
                ret = lttng_enable_event(handle, &ev, channel_name);
                if (ret < 0) {
-                       ERR("Event %s: %s (channel %s, session %s)", event_name,
-                                       lttng_strerror(ret), channel_name, session_name);
+                       /* Turn ret to positive value to handle the positive error code */
+                       switch (-ret) {
+                       case LTTCOMM_KERN_EVENT_EXIST:
+                               WARN("Kernel event %s already enabled (channel %s, session %s)",
+                                               event_name, channel_name, session_name);
+                               break;
+                       default:
+                               ERR("Event %s: %s (channel %s, session %s)", event_name,
+                                               lttng_strerror(ret), channel_name, session_name);
+                               break;
+                       }
                        warn = 1;
                } else {
                        MSG("%s event %s created in channel %s",
index f1707fc76844d76d68d43c85e5da0df645c627ec..50d6114c3d166be10483b71974b6418cf6152494 100644 (file)
@@ -1,19 +1,18 @@
 /*
  * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; only version 2
- * of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
  * This program 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 General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #define _GNU_SOURCE
index fdeeaafb5ded5ab535c131046af90f179d19e684..a428aed16ce239257253ae2f1fd7178fc4ff69e8 100644 (file)
@@ -1,19 +1,18 @@
 /*
  * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; only version 2
- * of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
  * This program 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 General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #define _GNU_SOURCE
index af93665d0ae16f74aec32044d0f27668696e86eb..44554fb37e223d11f62cb0d0f7bce33e096f79f2 100644 (file)
@@ -1,19 +1,18 @@
 /*
  * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; only version 2
- * of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
  * This program 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 General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #define _GNU_SOURCE
@@ -27,6 +26,8 @@
 
 #include "../command.h"
 
+#include <common/sessiond-comm/sessiond-comm.h>
+
 static char *opt_session_name;
 
 enum {
@@ -80,7 +81,14 @@ static int start_tracing(void)
 
        ret = lttng_start_tracing(session_name);
        if (ret < 0) {
-               /* Don't set ret so lttng can interpret the sessiond error. */
+               switch (-ret) {
+               case LTTCOMM_TRACE_ALREADY_STARTED:
+                       WARN("Tracing already started for session %s", session_name);
+                       break;
+               default:
+                       ERR("%s", lttng_strerror(ret));
+                       break;
+               }
                goto free_name;
        }
 
index f2ab453084f489cd38fe3cf2812a92278a05e296..6ed67fdabcaaf0194cbbe911c3853609aa3720de 100644 (file)
@@ -1,19 +1,18 @@
 /*
  * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; only version 2
- * of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
  * This program 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 General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #define _GNU_SOURCE
@@ -27,6 +26,8 @@
 
 #include "../command.h"
 
+#include <common/sessiond-comm/sessiond-comm.h>
+
 static char *opt_session_name;
 
 enum {
@@ -76,7 +77,14 @@ static int stop_tracing(void)
 
        ret = lttng_stop_tracing(session_name);
        if (ret < 0) {
-               /* Don't set ret so lttng can interpret the sessiond error. */
+               switch (-ret) {
+               case LTTCOMM_TRACE_ALREADY_STOPPED:
+                       WARN("Tracing already stopped for session %s", session_name);
+                       break;
+               default:
+                       ERR("%s", lttng_strerror(ret));
+                       break;
+               }
                goto free_name;
        }
 
index 030ccaae2937d89f071563f78ee4f6dfc78f306d..a6bbd6aece3c7a9e674705ddda560dd4bcd0e39b 100644 (file)
@@ -1,19 +1,18 @@
 /*
  * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; only version 2
- * of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
  * This program 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 General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #define _GNU_SOURCE
@@ -78,9 +77,9 @@ int cmd_version(int argc, const char **argv)
                }
        }
 
-       MSG("lttng version " VERSION);
+       MSG("lttng version " VERSION " - " VERSION_NAME);
        MSG("Web site: http://lttng.org/");
-       MSG("\nlttng is free software and under the GPL license.");
+       MSG("\nlttng is free software and under the GPL license and part LGPL");
 
 end:
        poptFreeContext(pc);
index c4724415c31bca500e8054a8dc9411f9d140c7e5..9508743e62878ade2428905ba0bfdc9e831537f5 100644 (file)
@@ -1,18 +1,18 @@
 /*
  * Copyright (C) 2011 - David Goulet <dgoulet@efficios.com>
  *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; only version 2 of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
- * This program 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 General Public License for
- * more details.
+ * This program 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 General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place - Suite 330, Boston, MA  02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #define _GNU_SOURCE
@@ -258,7 +258,11 @@ static int spawn_viewer(const char *trace_path)
 
        ret = execvp(viewer_bin, argv);
        if (ret) {
-               PERROR("exec: %s", viewer_bin);
+               if (errno == ENOENT) {
+                       ERR("%s not found on the system", viewer_bin);
+               } else {
+                       PERROR("exec: %s", viewer_bin);
+               }
                free(argv);
                ret = CMD_FATAL;
                goto error;
@@ -346,8 +350,6 @@ static int view_trace(void)
                goto free_sessions;
        }
 
-       ret = CMD_SUCCESS;
-
 free_sessions:
        if (sessions) {
                free(sessions);
index 00991b08195319f58f3d5489ff10ed679204f8aa..6f290b7e5f1df78b34f4d88cf87d500a1c72b1fa 100644 (file)
@@ -2,9 +2,8 @@
  * Copyright (c)  2011 David Goulet <david.goulet@polymtl.ca>
  *
  * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * as published by the Free Software Foundation; only version 2
- * of the License.
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
index a7672e413a4bb6f918effca6bb51f390f1d8ca07..1c471dae3c0990eff7cc2ececbbb81a474cb830c 100644 (file)
@@ -1,19 +1,18 @@
 /*
  * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; only version 2
- * of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
  * This program 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 General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #ifndef _LTTNG_CONFIG_H
index 1349c20a726f0cb2b51a88d25c113928522f147c..8d6c8e621e83eadd3d18a08e385ad0b474e98940 100644 (file)
@@ -2,9 +2,8 @@
  * Copyright (c)  2011 David Goulet <david.goulet@polymtl.ca>
  *
  * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * as published by the Free Software Foundation; only version 2
- * of the License.
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -26,6 +25,7 @@
 #include <sys/wait.h>
 #include <unistd.h>
 #include <config.h>
+#include <ctype.h>
 
 #include <lttng/lttng.h>
 #include <common/error.h>
@@ -34,9 +34,6 @@
 
 /* Variables */
 static char *progname;
-
-int opt_quiet;
-int opt_verbose;
 static int opt_no_sessiond;
 static char *opt_sessiond_path;
 static pid_t sessiond_pid;
@@ -82,7 +79,7 @@ static struct cmd_struct commands[] =  {
 
 static void usage(FILE *ofp)
 {
-       fprintf(ofp, "LTTng Trace Control " VERSION"\n\n");
+       fprintf(ofp, "LTTng Trace Control " VERSION" - " VERSION_NAME"\n\n");
        fprintf(ofp, "usage: lttng [OPTIONS] <COMMAND>\n");
        fprintf(ofp, "\n");
        fprintf(ofp, "Options:\n");
@@ -431,10 +428,10 @@ static int parse_args(int argc, char **argv)
                        ret = 0;
                        goto end;
                case 'v':
-                       opt_verbose += 1;
+                       lttng_opt_verbose += 1;
                        break;
                case 'q':
-                       opt_quiet = 1;
+                       lttng_opt_quiet = 1;
                        break;
                case 'g':
                        lttng_set_tracing_group(optarg);
@@ -461,8 +458,8 @@ static int parse_args(int argc, char **argv)
        }
 
        /* If both options are specified, quiet wins */
-       if (opt_verbose && opt_quiet) {
-               opt_verbose = 0;
+       if (lttng_opt_verbose && lttng_opt_quiet) {
+               lttng_opt_verbose = 0;
        }
 
        /* Spawn session daemon if needed */
@@ -504,7 +501,9 @@ static int parse_args(int argc, char **argv)
        case 0:
                break;
        default:
-               ERR("%s", lttng_strerror(ret));
+               if (ret < 0) {
+                       ret = -ret;
+               }
                break;
        }
 
index 1f491db1b89e0095d33ce7ee603338f4f7f400c2..b982bd5936149ab7667e64176a9f0c499dfd0207 100644 (file)
@@ -1,10 +1,9 @@
 /*
  * Copyright (c)  2011 David Goulet <david.goulet@polymtl.ca>
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; only version 2
- * of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -16,6 +15,7 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
+#define _GNU_SOURCE
 #include <stdlib.h>
 #include <ctype.h>
 
index e609b7086926df453b7ce98a8f81942f30914842..9c51b67e341a73b461e698e9ca52d57677a35270 100644 (file)
@@ -1,19 +1,18 @@
 /*
  * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; only version 2
- * of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
  * This program 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 General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #ifndef _LTTNG_UTILS_H
index 37f9acb9ab144b9a7ce711b4062d62a82bc78a4a..5d79210b802819cd07e14e5b11338c16acfdca09 100644 (file)
@@ -1,6 +1,6 @@
 AM_CPPFLAGS =
 
-SUBDIRS = hashtable kernel-ctl sessiond-comm kernel-consumer ust-consumer
+SUBDIRS = compat hashtable kernel-ctl sessiond-comm kernel-consumer ust-consumer
 
 AM_CFLAGS = -fno-strict-aliasing
 
@@ -18,19 +18,10 @@ libconsumer_la_SOURCES = consumer.c consumer.h
 libconsumer_la_LIBADD = \
                $(top_builddir)/src/common/sessiond-comm/libsessiond-comm.la \
                $(top_builddir)/src/common/kernel-consumer/libkernel-consumer.la \
-               $(top_builddir)/src/common/hashtable/libhashtable.la
+               $(top_builddir)/src/common/hashtable/libhashtable.la \
+               $(top_builddir)/src/common/compat/libcompat.la
 
 if HAVE_LIBLTTNG_UST_CTL
 libconsumer_la_LIBADD += \
                $(top_builddir)/src/common/ust-consumer/libust-consumer.la
 endif
-
-if COMPAT_EPOLL
-COMPAT=compat/compat-epoll.c
-else
-COMPAT=compat/compat-poll.c
-endif
-
-noinst_LTLIBRARIES += libcompat.la
-
-libcompat_la_SOURCES = compat/poll.h $(COMPAT)
index cc4a4c7a9b063553e37fe921a20ac9114d84682f..2b2081c48cc15161ee89b1e76868362646c7dfb8 100644 (file)
@@ -2,18 +2,18 @@
  * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
  *                      Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; only version 2 of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
  * This program 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 General Public License for
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  * more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place - Suite 330, Boston, MA  02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #ifndef _COMMON_H
diff --git a/src/common/compat/Makefile.am b/src/common/compat/Makefile.am
new file mode 100644 (file)
index 0000000..91cd3bd
--- /dev/null
@@ -0,0 +1,12 @@
+AM_CPPFLAGS = -I$(top_srcdir)/include
+
+noinst_LTLIBRARIES = libcompat.la
+
+if COMPAT_EPOLL
+COMPAT=compat-epoll.c
+else
+COMPAT=compat-poll.c
+endif
+
+libcompat_la_SOURCES = poll.h fcntl.h endian.h mman.h clone.h \
+                       socket.h compat-fcntl.c $(COMPAT)
diff --git a/src/common/compat/clone.h b/src/common/compat/clone.h
new file mode 100644 (file)
index 0000000..581595b
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2011 - David Goulet <dgoulet@efficios.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
+ *
+ * This program 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 General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef _COMPAT_CLONE_H
+#define _COMPAT_CLONE_H
+
+#ifdef __linux__
+
+#include <sched.h>
+
+static inline
+pid_t lttng_clone_files(int (*fn)(void *), void *child_stack, void *arg)
+{
+       return clone(fn, child_stack, CLONE_FILES | SIGCHLD, arg);
+}
+
+#elif defined(__FreeBSD__)
+
+#include <unistd.h>
+
+static inline
+pid_t lttng_clone_files(int (*fn)(void *), void *child_stack, void *arg)
+{
+       pid_t pid;
+
+       pid = rfork(RFPROC | RFTHREAD);
+       if (pid == 0) {
+               /* child */
+               int ret;
+
+               ret = fn(arg);
+               exit(ret);
+       } else if (pid > 0) {
+               /* parent */
+               /*
+                * Just return, the caller will wait for the child.
+                */
+               return pid;
+       } else {
+               /* Error */
+               return pid;
+       }
+}
+
+#else
+#error "Please add support for your OS."
+#endif /* __linux__ , __FreeBSD__ */
+
+#endif /* _COMPAT_CLONE_H */
index 77f5b922abcb7bc03c90ce8f574f5f4c94a9e6ed..e58497232a130c002940cd1ffeb5b879129d47b7 100644 (file)
@@ -1,20 +1,21 @@
 /*
  * Copyright (C)  2011 - David Goulet <david.goulet@polymtl.ca>
  *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; only version 2 of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
  * This program 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 General Public License for
  * more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place - Suite 330, Boston, MA  02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
+#define _GNU_SOURCE
 #include <fcntl.h>
 #include <limits.h>
 #include <stdlib.h>
@@ -49,7 +50,7 @@ int compat_epoll_create(struct lttng_poll_event *events, int size, int flags)
        ret = epoll_create1(flags);
        if (ret < 0) {
                /* At this point, every error is fatal */
-               perror("epoll_create1");
+               PERROR("epoll_create1");
                goto error;
        }
 
@@ -58,7 +59,7 @@ int compat_epoll_create(struct lttng_poll_event *events, int size, int flags)
        /* This *must* be freed by using lttng_poll_free() */
        events->events = zmalloc(size * sizeof(struct epoll_event));
        if (events->events == NULL) {
-               perror("zmalloc epoll set");
+               PERROR("zmalloc epoll set");
                goto error_close;
        }
 
@@ -68,7 +69,10 @@ int compat_epoll_create(struct lttng_poll_event *events, int size, int flags)
        return 0;
 
 error_close:
-       close(events->epfd);
+       ret = close(events->epfd);
+       if (ret) {
+               PERROR("close");
+       }
 error:
        return -1;
 }
@@ -97,11 +101,11 @@ int compat_epoll_add(struct lttng_poll_event *events, int fd, uint32_t req_event
                        goto end;
                case ENOSPC:
                case EPERM:
-                       /* Print perror and goto end not failing. Show must go on. */
-                       perror("epoll_ctl ADD");
+                       /* Print PERROR and goto end not failing. Show must go on. */
+                       PERROR("epoll_ctl ADD");
                        goto end;
                default:
-                       perror("epoll_ctl ADD fatal");
+                       PERROR("epoll_ctl ADD fatal");
                        goto error;
                }
        }
@@ -112,7 +116,7 @@ int compat_epoll_add(struct lttng_poll_event *events, int fd, uint32_t req_event
                new_size = 2 * events->events_size;
                ptr = realloc(events->events, new_size * sizeof(struct epoll_event));
                if (ptr == NULL) {
-                       perror("realloc epoll add");
+                       PERROR("realloc epoll add");
                        goto error;
                }
                events->events = ptr;
@@ -142,14 +146,14 @@ int compat_epoll_del(struct lttng_poll_event *events, int fd)
                switch (errno) {
                case ENOENT:
                case EPERM:
-                       /* Print perror and goto end not failing. Show must go on. */
-                       perror("epoll_ctl DEL");
+                       /* Print PERROR and goto end not failing. Show must go on. */
+                       PERROR("epoll_ctl DEL");
                        goto end;
                default:
-                       perror("epoll_ctl DEL fatal");
+                       PERROR("epoll_ctl DEL fatal");
                        goto error;
                }
-               perror("epoll_ctl del");
+               PERROR("epoll_ctl del");
                goto error;
        }
 
@@ -180,7 +184,7 @@ int compat_epoll_wait(struct lttng_poll_event *events, int timeout)
        } while (ret == -1 && errno == EINTR);
        if (ret < 0) {
                /* At this point, every error is fatal */
-               perror("epoll_wait");
+               PERROR("epoll_wait");
                goto error;
        }
 
@@ -207,7 +211,7 @@ void compat_epoll_set_max_size(void)
 
        ret = read(fd, buf, sizeof(buf));
        if (ret < 0) {
-               perror("read set max size");
+               PERROR("read set max size");
                goto error;
        }
 
@@ -220,5 +224,8 @@ void compat_epoll_set_max_size(void)
        DBG("epoll set max size is %d", poll_max_size);
 
 error:
-       close(fd);
+       ret = close(fd);
+       if (ret) {
+               PERROR("close");
+       }
 }
diff --git a/src/common/compat/compat-fcntl.c b/src/common/compat/compat-fcntl.c
new file mode 100644 (file)
index 0000000..5a1c757
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2011 - David Goulet <dgoulet@efficios.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
+ *
+ * This program 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 General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#define _GNU_SOURCE
+#include <common/compat/fcntl.h>
+
+#ifdef __linux__
+
+int compat_sync_file_range(int fd, off64_t offset, off64_t nbytes,
+               unsigned int flags)
+{
+       return sync_file_range(fd, offset, nbytes, flags);
+}
+
+#endif /* __linux__ */
index 51bf22c865ddd6dff74359e39e54e5a8adf22e94..157a2d79de950a25e051df3875071586344f32b3 100644 (file)
@@ -1,20 +1,21 @@
 /*
  * Copyright (C)  2011 - David Goulet <david.goulet@polymtl.ca>
  *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; only version 2 of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
  * This program 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 General Public License for
  * more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place - Suite 330, Boston, MA  02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
+#define _GNU_SOURCE
 #include <stdlib.h>
 #include <sys/resource.h>
 #include <sys/time.h>
diff --git a/src/common/compat/endian.h b/src/common/compat/endian.h
new file mode 100644 (file)
index 0000000..2850866
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2011 - David Goulet <dgoulet@efficios.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
+ *
+ * This program 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 General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifdef _COMPAT_ENDIAN_H
+#define _COMPAT_ENDIAN_H
+
+#ifdef __linux__
+#include <endian.h>
+#elif defined(__FreeBSD__)
+#include <machine/endian.h>
+#else
+#error "Please add support for your OS."
+#endif
+
+#endif /* _COMPAT_ENDIAN_H */
diff --git a/src/common/compat/fcntl.h b/src/common/compat/fcntl.h
new file mode 100644 (file)
index 0000000..58c1579
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2011 - David Goulet <dgoulet@efficios.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
+ *
+ * This program 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 General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef _COMPAT_FCNTL_H
+#define _COMPAT_FCNTL_H
+
+#include <fcntl.h>
+#include <sys/types.h>
+
+#ifdef __linux__
+
+extern int compat_sync_file_range(int fd, off64_t offset, off64_t nbytes,
+               unsigned int flags);
+#define lttng_sync_file_range(fd, offset, nbytes, flags) \
+       compat_sync_file_range(fd, offset, nbytes, flags)
+
+#elif defined(__FreeBSD__)
+
+typedef long int off64_t;
+typedef off64_t loff_t;
+
+#include <sys/errno.h>
+
+/*
+ * Possible flags under Linux. Simply nullify them and avoid wrapper.
+ */
+#define SYNC_FILE_RANGE_WAIT_AFTER    0
+#define SYNC_FILE_RANGE_WAIT_BEFORE   0
+#define SYNC_FILE_RANGE_WRITE         0
+
+/*
+ * Possible flags under Linux. Simply nullify them and avoid wrappers.
+ */
+#define SPLICE_F_MOVE       0
+#define SPLICE_F_NONBLOCK   0
+#define SPLICE_F_MORE       0
+#define SPLICE_F_GIFT       0
+
+#define POSIX_FADV_DONTNEED 0
+
+static inline int lttng_sync_file_range(int fd, off64_t offset,
+               off64_t nbytes, unsigned int flags)
+{
+       return -ENOSYS;
+}
+
+static inline ssize_t splice(int fd_in, loff_t *off_in, int fd_out, loff_t *off_out,
+               size_t len, unsigned int flags)
+{
+       return -ENOSYS;
+}
+
+static inline int posix_fadvise(int fd, off_t offset, off_t len, int advice)
+{
+       return -ENOSYS;
+}
+
+#else
+#error "Please add support for your OS."
+#endif /* __linux__ , __FreeBSD__ */
+
+#endif /* _COMPAT_FCNTL_H */
diff --git a/src/common/compat/mman.h b/src/common/compat/mman.h
new file mode 100644 (file)
index 0000000..1c65eb4
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2011 - David Goulet <dgoulet@efficios.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
+ *
+ * This program 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 General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef _COMPAT_MMAN_H
+#define _COMPAT_MMAN_H
+
+#include <sys/mman.h>
+
+#ifdef __linux__
+
+#elif defined(__FreeBSD__)
+
+#define MAP_GROWSDOWN 0
+#define MAP_ANONYMOUS MAP_ANON
+
+#else
+#error "Please add support for your OS."
+#endif /* __linux__ , __FreeBSD__ */
+
+#endif /* _COMPAT_MMAN_H */
index 1580a4fb211a24def1146d7ec5c721431c34e3b4..46200ac3e313effea9c198ef0dd061008341133e 100644 (file)
@@ -1,18 +1,18 @@
 /*
  * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
  *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; only version 2 of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
  * This program 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 General Public License for
  * more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place - Suite 330, Boston, MA  02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #ifndef _LTT_POLL_H
@@ -50,6 +50,7 @@ static inline void __lttng_poll_free(void *events)
  */
 #ifdef HAVE_EPOLL
 #include <sys/epoll.h>
+#include <stdio.h>
 
 /* See man epoll(7) for this define path */
 #define COMPAT_EPOLL_PROC_PATH "/proc/sys/fs/epoll/max_user_watches"
@@ -146,8 +147,13 @@ static inline void lttng_poll_reset(struct lttng_poll_event *events)
  */
 static inline void lttng_poll_clean(struct lttng_poll_event *events)
 {
+       int ret;
+
        if (events) {
-               close(events->epfd);
+               ret = close(events->epfd);
+               if (ret) {
+                       perror("close");
+               }
                __lttng_poll_free((void *) events->events);
        }
 }
@@ -179,10 +185,17 @@ enum {
        LPOLLRDBAND = POLLRDBAND,
        LPOLLWRNORM = POLLWRNORM,
        LPOLLWRBAND = POLLWRBAND,
+#if __linux__
        LPOLLMSG = POLLMSG,
+       LPOLLRDHUP = POLLRDHUP,
+#elif defined(__FreeBSD__)
+       LPOLLMSG = 0,
+       LPOLLRDHUP = 0,
+#else
+#error "Please add support for your OS."
+#endif /* __linux__ */
        LPOLLERR = POLLERR,
        LPOLLHUP = POLLHUP | POLLNVAL,
-       LPOLLRDHUP = POLLRDHUP,
        /* Close on exec feature does not exist for poll(2) */
        LTTNG_CLOEXEC = 0xdead,
 };
diff --git a/src/common/compat/socket.h b/src/common/compat/socket.h
new file mode 100644 (file)
index 0000000..69a9188
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2011 - David Goulet <dgoulet@efficios.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
+ *
+ * This program 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 General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef _COMPAT_SOCKET_H
+#define _COMPAT_SOCKET_H
+
+#include <sys/socket.h>
+#include <sys/un.h>
+
+#include <common/macros.h>
+
+#ifdef __linux__
+
+#define LTTNG_SOCK_CREDS SCM_CREDENTIALS
+
+typedef struct ucred lttng_sock_cred;
+
+#define LTTNG_SOCK_SET_UID_CRED(c, u) LTTNG_REF(c)->uid = u
+#define LTTNG_SOCK_SET_GID_CRED(c, g) LTTNG_REF(c)->gid = g
+#define LTTNG_SOCK_SET_PID_CRED(c, p) LTTNG_REF(c)->pid = p
+
+#define LTTNG_SOCK_GET_UID_CRED(c) LTTNG_REF(c)->uid
+#define LTTNG_SOCK_GET_GID_CRED(c) LTTNG_REF(c)->gid
+#define LTTNG_SOCK_GET_PID_CRED(c) LTTNG_REF(c)->pid
+
+#elif defined(__FreeBSD__)
+
+struct lttng_sock_cred {
+       uid_t uid;
+       gid_t gid;
+};
+
+typedef struct lttng_sock_cred lttng_sock_cred;
+
+#define LTTNG_SOCK_GET_UID_CRED(c) LTTNG_REF(c)->uid
+#define LTTNG_SOCK_GET_GID_CRED(c) LTTNG_REF(c)->gid
+#define LTTNG_SOCK_GET_PID_CRED(c) -1
+
+#else
+#error "Please add support for your OS."
+#endif /* __linux__ , __FreeBSD__ */
+
+#endif /* _COMPAT_SOCKET_H */
index b605591e478a1c2a40dd13a25228bd2ad80bc684..f81de8d556a66149c75e59193c50a7d2c96741bd 100644 (file)
@@ -2,24 +2,22 @@
  * Copyright (C) 2011 - Julien Desfossez <julien.desfossez@polymtl.ca>
  *                      Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; only version 2
- * of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
- * This program 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 General Public License for more details.
+ * This program 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 General Public License for
+ * more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #define _GNU_SOURCE
 #include <assert.h>
-#include <fcntl.h>
 #include <poll.h>
 #include <pthread.h>
 #include <stdlib.h>
@@ -86,9 +84,18 @@ static void consumer_steal_stream_key(int key)
 {
        struct lttng_consumer_stream *stream;
 
+       rcu_read_lock();
        stream = consumer_find_stream(key);
-       if (stream)
+       if (stream) {
                stream->key = -1;
+               /*
+                * We don't want the lookup to match, but we still need
+                * to iterate on this stream when iterating over the hash table. Just
+                * change the node key.
+                */
+               stream->node.key = -1;
+       }
+       rcu_read_unlock();
 }
 
 static struct lttng_consumer_channel *consumer_find_channel(int key)
@@ -119,9 +126,29 @@ static void consumer_steal_channel_key(int key)
 {
        struct lttng_consumer_channel *channel;
 
+       rcu_read_lock();
        channel = consumer_find_channel(key);
-       if (channel)
+       if (channel) {
                channel->key = -1;
+               /*
+                * We don't want the lookup to match, but we still need
+                * to iterate on this channel when iterating over the hash table. Just
+                * change the node key.
+                */
+               channel->node.key = -1;
+       }
+       rcu_read_unlock();
+}
+
+static
+void consumer_free_stream(struct rcu_head *head)
+{
+       struct lttng_ht_node_ulong *node =
+               caa_container_of(head, struct lttng_ht_node_ulong, head);
+       struct lttng_consumer_stream *stream =
+               caa_container_of(node, struct lttng_consumer_stream, node);
+
+       free(stream);
 }
 
 /*
@@ -156,11 +183,7 @@ void consumer_del_stream(struct lttng_consumer_stream *stream)
        }
 
        rcu_read_lock();
-
-       /* Get stream node from hash table */
-       lttng_ht_lookup(consumer_data.stream_ht,
-                       (void *)((unsigned long) stream->key), &iter);
-       /* Remove stream node from hash table */
+       iter.iter.node = &stream->node.node;
        ret = lttng_ht_del(consumer_data.stream_ht, &iter);
        assert(!ret);
 
@@ -174,17 +197,27 @@ void consumer_del_stream(struct lttng_consumer_stream *stream)
                goto end;
        }
        if (stream->out_fd >= 0) {
-               close(stream->out_fd);
+               ret = close(stream->out_fd);
+               if (ret) {
+                       PERROR("close");
+               }
        }
        if (stream->wait_fd >= 0 && !stream->wait_fd_is_copy) {
-               close(stream->wait_fd);
+               ret = close(stream->wait_fd);
+               if (ret) {
+                       PERROR("close");
+               }
        }
        if (stream->shm_fd >= 0 && stream->wait_fd != stream->shm_fd) {
-               close(stream->shm_fd);
+               ret = close(stream->shm_fd);
+               if (ret) {
+                       PERROR("close");
+               }
        }
        if (!--stream->chan->refcount)
                free_chan = stream->chan;
-       free(stream);
+
+       call_rcu(&stream->node.head, consumer_free_stream);
 end:
        consumer_data.need_update = 1;
        pthread_mutex_unlock(&consumer_data.lock);
@@ -193,16 +226,6 @@ end:
                consumer_del_channel(free_chan);
 }
 
-static void consumer_del_stream_rcu(struct rcu_head *head)
-{
-       struct lttng_ht_node_ulong *node =
-               caa_container_of(head, struct lttng_ht_node_ulong, head);
-       struct lttng_consumer_stream *stream =
-               caa_container_of(node, struct lttng_consumer_stream, node);
-
-       consumer_del_stream(stream);
-}
-
 struct lttng_consumer_stream *consumer_allocate_stream(
                int channel_key, int stream_key,
                int shm_fd, int wait_fd,
@@ -275,11 +298,23 @@ end:
 int consumer_add_stream(struct lttng_consumer_stream *stream)
 {
        int ret = 0;
+       struct lttng_ht_node_ulong *node;
+       struct lttng_ht_iter iter;
 
        pthread_mutex_lock(&consumer_data.lock);
        /* Steal stream identifier, for UST */
        consumer_steal_stream_key(stream->key);
        rcu_read_lock();
+
+       lttng_ht_lookup(consumer_data.stream_ht,
+                       (void *)((unsigned long) stream->key), &iter);
+       node = lttng_ht_iter_get_node_ulong(&iter);
+       if (node != NULL) {
+               rcu_read_unlock();
+               /* Stream already exist. Ignore the insertion */
+               goto end;
+       }
+
        lttng_ht_add_unique_ulong(consumer_data.stream_ht, &stream->node);
        rcu_read_unlock();
        consumer_data.stream_count++;
@@ -301,6 +336,7 @@ int consumer_add_stream(struct lttng_consumer_stream *stream)
 
 end:
        pthread_mutex_unlock(&consumer_data.lock);
+
        return ret;
 }
 
@@ -321,6 +357,17 @@ void consumer_change_stream_state(int stream_key,
        pthread_mutex_unlock(&consumer_data.lock);
 }
 
+static
+void consumer_free_channel(struct rcu_head *head)
+{
+       struct lttng_ht_node_ulong *node =
+               caa_container_of(head, struct lttng_ht_node_ulong, head);
+       struct lttng_consumer_channel *channel =
+               caa_container_of(node, struct lttng_consumer_channel, node);
+
+       free(channel);
+}
+
 /*
  * Remove a channel from the global list protected by a mutex. This
  * function is also responsible for freeing its data structures.
@@ -346,12 +393,9 @@ void consumer_del_channel(struct lttng_consumer_channel *channel)
        }
 
        rcu_read_lock();
-
-       lttng_ht_lookup(consumer_data.channel_ht,
-                       (void *)((unsigned long) channel->key), &iter);
+       iter.iter.node = &channel->node.node;
        ret = lttng_ht_del(consumer_data.channel_ht, &iter);
        assert(!ret);
-
        rcu_read_unlock();
 
        if (channel->mmap_base != NULL) {
@@ -361,26 +405,23 @@ void consumer_del_channel(struct lttng_consumer_channel *channel)
                }
        }
        if (channel->wait_fd >= 0 && !channel->wait_fd_is_copy) {
-               close(channel->wait_fd);
+               ret = close(channel->wait_fd);
+               if (ret) {
+                       PERROR("close");
+               }
        }
        if (channel->shm_fd >= 0 && channel->wait_fd != channel->shm_fd) {
-               close(channel->shm_fd);
+               ret = close(channel->shm_fd);
+               if (ret) {
+                       PERROR("close");
+               }
        }
-       free(channel);
+
+       call_rcu(&channel->node.head, consumer_free_channel);
 end:
        pthread_mutex_unlock(&consumer_data.lock);
 }
 
-static void consumer_del_channel_rcu(struct rcu_head *head)
-{
-       struct lttng_ht_node_ulong *node =
-               caa_container_of(head, struct lttng_ht_node_ulong, head);
-       struct lttng_consumer_channel *channel=
-               caa_container_of(node, struct lttng_consumer_channel, node);
-
-       consumer_del_channel(channel);
-}
-
 struct lttng_consumer_channel *consumer_allocate_channel(
                int channel_key,
                int shm_fd, int wait_fd,
@@ -437,13 +478,28 @@ end:
  */
 int consumer_add_channel(struct lttng_consumer_channel *channel)
 {
+       struct lttng_ht_node_ulong *node;
+       struct lttng_ht_iter iter;
+
        pthread_mutex_lock(&consumer_data.lock);
        /* Steal channel identifier, for UST */
        consumer_steal_channel_key(channel->key);
        rcu_read_lock();
+
+       lttng_ht_lookup(consumer_data.channel_ht,
+                       (void *)((unsigned long) channel->key), &iter);
+       node = lttng_ht_iter_get_node_ulong(&iter);
+       if (node != NULL) {
+               /* Channel already exist. Ignore the insertion */
+               goto end;
+       }
+
        lttng_ht_add_unique_ulong(consumer_data.channel_ht, &channel->node);
+
+end:
        rcu_read_unlock();
        pthread_mutex_unlock(&consumer_data.lock);
+
        return 0;
 }
 
@@ -463,6 +519,7 @@ int consumer_update_poll_array(
        struct lttng_consumer_stream *stream;
 
        DBG("Updating poll fd array");
+       rcu_read_lock();
        cds_lfht_for_each_entry(consumer_data.stream_ht->ht, &iter.iter, stream,
                        node.node) {
                if (stream->state != LTTNG_CONSUMER_ACTIVE_STREAM) {
@@ -474,6 +531,7 @@ int consumer_update_poll_array(
                local_stream[i] = stream;
                i++;
        }
+       rcu_read_unlock();
 
        /*
         * Insert the consumer_poll_pipe at the end of the array and don't
@@ -492,8 +550,15 @@ int lttng_consumer_poll_socket(struct pollfd *consumer_sockpoll)
 {
        int num_rdy;
 
+restart:
        num_rdy = poll(consumer_sockpoll, 2, -1);
        if (num_rdy == -1) {
+               /*
+                * Restart interrupted system call.
+                */
+               if (errno == EINTR) {
+                       goto restart;
+               }
                perror("Poll error");
                goto exit;
        }
@@ -547,7 +612,6 @@ int lttng_consumer_send_error(
  */
 void lttng_consumer_cleanup(void)
 {
-       int ret;
        struct lttng_ht_iter iter;
        struct lttng_ht_node_ulong *node;
 
@@ -559,16 +623,16 @@ void lttng_consumer_cleanup(void)
         */
        cds_lfht_for_each_entry(consumer_data.stream_ht->ht, &iter.iter, node,
                        node) {
-               ret = lttng_ht_del(consumer_data.stream_ht, &iter);
-               assert(!ret);
-               call_rcu(&node->head, consumer_del_stream_rcu);
+               struct lttng_consumer_stream *stream =
+                       caa_container_of(node, struct lttng_consumer_stream, node);
+               consumer_del_stream(stream);
        }
 
        cds_lfht_for_each_entry(consumer_data.channel_ht->ht, &iter.iter, node,
                        node) {
-               ret = lttng_ht_del(consumer_data.channel_ht, &iter);
-               assert(!ret);
-               call_rcu(&node->head, consumer_del_channel_rcu);
+               struct lttng_consumer_channel *channel =
+                       caa_container_of(node, struct lttng_consumer_channel, node);
+               consumer_del_channel(channel);
        }
 
        rcu_read_unlock();
@@ -601,7 +665,7 @@ void lttng_consumer_sync_trace_file(
        if (orig_offset < stream->chan->max_sb_size) {
                return;
        }
-       sync_file_range(outfd, orig_offset - stream->chan->max_sb_size,
+       lttng_sync_file_range(outfd, orig_offset - stream->chan->max_sb_size,
                        stream->chan->max_sb_size,
                        SYNC_FILE_RANGE_WAIT_BEFORE
                        | SYNC_FILE_RANGE_WRITE
@@ -640,7 +704,7 @@ void lttng_consumer_sync_trace_file(
  */
 struct lttng_consumer_local_data *lttng_consumer_create(
                enum lttng_consumer_type type,
-               int (*buffer_ready)(struct lttng_consumer_stream *stream,
+               ssize_t (*buffer_ready)(struct lttng_consumer_stream *stream,
                        struct lttng_consumer_local_data *ctx),
                int (*recv_channel)(struct lttng_consumer_channel *channel),
                int (*recv_stream)(struct lttng_consumer_stream *stream),
@@ -692,14 +756,18 @@ error_thread_pipe:
                int err;
 
                err = close(ctx->consumer_should_quit[i]);
-               assert(!err);
+               if (err) {
+                       PERROR("close");
+               }
        }
 error_quit_pipe:
        for (i = 0; i < 2; i++) {
                int err;
 
                err = close(ctx->consumer_poll_pipe[i]);
-               assert(!err);
+               if (err) {
+                       PERROR("close");
+               }
        }
 error_poll_pipe:
        free(ctx);
@@ -712,13 +780,36 @@ error:
  */
 void lttng_consumer_destroy(struct lttng_consumer_local_data *ctx)
 {
-       close(ctx->consumer_error_socket);
-       close(ctx->consumer_thread_pipe[0]);
-       close(ctx->consumer_thread_pipe[1]);
-       close(ctx->consumer_poll_pipe[0]);
-       close(ctx->consumer_poll_pipe[1]);
-       close(ctx->consumer_should_quit[0]);
-       close(ctx->consumer_should_quit[1]);
+       int ret;
+
+       ret = close(ctx->consumer_error_socket);
+       if (ret) {
+               PERROR("close");
+       }
+       ret = close(ctx->consumer_thread_pipe[0]);
+       if (ret) {
+               PERROR("close");
+       }
+       ret = close(ctx->consumer_thread_pipe[1]);
+       if (ret) {
+               PERROR("close");
+       }
+       ret = close(ctx->consumer_poll_pipe[0]);
+       if (ret) {
+               PERROR("close");
+       }
+       ret = close(ctx->consumer_poll_pipe[1]);
+       if (ret) {
+               PERROR("close");
+       }
+       ret = close(ctx->consumer_should_quit[0]);
+       if (ret) {
+               PERROR("close");
+       }
+       ret = close(ctx->consumer_should_quit[1]);
+       if (ret) {
+               PERROR("close");
+       }
        unlink(ctx->consumer_command_sock_path);
        free(ctx);
 }
@@ -728,7 +819,7 @@ void lttng_consumer_destroy(struct lttng_consumer_local_data *ctx)
  *
  * Returns the number of bytes written
  */
-int lttng_consumer_on_read_subbuffer_mmap(
+ssize_t lttng_consumer_on_read_subbuffer_mmap(
                struct lttng_consumer_local_data *ctx,
                struct lttng_consumer_stream *stream, unsigned long len)
 {
@@ -742,6 +833,8 @@ int lttng_consumer_on_read_subbuffer_mmap(
                ERR("Unknown consumer_data type");
                assert(0);
        }
+
+       return 0;
 }
 
 /*
@@ -749,7 +842,7 @@ int lttng_consumer_on_read_subbuffer_mmap(
  *
  * Returns the number of bytes spliced.
  */
-int lttng_consumer_on_read_subbuffer_splice(
+ssize_t lttng_consumer_on_read_subbuffer_splice(
                struct lttng_consumer_local_data *ctx,
                struct lttng_consumer_stream *stream, unsigned long len)
 {
@@ -895,11 +988,22 @@ void *lttng_consumer_thread_poll_fds(void *data)
                }
                pthread_mutex_unlock(&consumer_data.lock);
 
+               /* No FDs and consumer_quit, consumer_cleanup the thread */
+               if (nb_fd == 0 && consumer_quit == 1) {
+                       goto end;
+               }
                /* poll on the array of fds */
+       restart:
                DBG("polling on %d fd", nb_fd + 1);
                num_rdy = poll(pollfd, nb_fd + 1, consumer_poll_timeout);
                DBG("poll num_rdy : %d", num_rdy);
                if (num_rdy == -1) {
+                       /*
+                        * Restart interrupted system call.
+                        */
+                       if (errno == EINTR) {
+                               goto restart;
+                       }
                        perror("Poll error");
                        lttng_consumer_send_error(ctx, CONSUMERD_POLL_ERROR);
                        goto end;
@@ -908,11 +1012,6 @@ void *lttng_consumer_thread_poll_fds(void *data)
                        goto end;
                }
 
-               /* No FDs and consumer_quit, consumer_cleanup the thread */
-               if (nb_fd == 0 && consumer_quit == 1) {
-                       goto end;
-               }
-
                /*
                 * If the consumer_poll_pipe triggered poll go
                 * directly to the beginning of the loop to update the
@@ -931,69 +1030,82 @@ void *lttng_consumer_thread_poll_fds(void *data)
                /* Take care of high priority channels first. */
                for (i = 0; i < nb_fd; i++) {
                        if (pollfd[i].revents & POLLPRI) {
+                               ssize_t len;
+
                                DBG("Urgent read on fd %d", pollfd[i].fd);
                                high_prio = 1;
-                               ret = ctx->on_buffer_ready(local_stream[i], ctx);
+                               len = ctx->on_buffer_ready(local_stream[i], ctx);
                                /* it's ok to have an unavailable sub-buffer */
-                               if (ret == EAGAIN) {
-                                       ret = 0;
+                               if (len < 0 && len != -EAGAIN) {
+                                       goto end;
+                               } else if (len > 0) {
+                                       local_stream[i]->data_read = 1;
                                }
-                       } else if (pollfd[i].revents & POLLERR) {
-                               ERR("Error returned in polling fd %d.", pollfd[i].fd);
-                               rcu_read_lock();
-                               consumer_del_stream_rcu(&local_stream[i]->node.head);
-                               rcu_read_unlock();
-                               num_hup++;
-                       } else if (pollfd[i].revents & POLLNVAL) {
-                               ERR("Polling fd %d tells fd is not open.", pollfd[i].fd);
-                               rcu_read_lock();
-                               consumer_del_stream_rcu(&local_stream[i]->node.head);
-                               rcu_read_unlock();
-                               num_hup++;
-                       } else if ((pollfd[i].revents & POLLHUP) &&
-                                       !(pollfd[i].revents & POLLIN)) {
-                               if (consumer_data.type == LTTNG_CONSUMER32_UST
-                                               || consumer_data.type == LTTNG_CONSUMER64_UST) {
-                                       DBG("Polling fd %d tells it has hung up. Attempting flush and read.",
-                                               pollfd[i].fd);
-                                       if (!local_stream[i]->hangup_flush_done) {
-                                               lttng_ustconsumer_on_stream_hangup(local_stream[i]);
-                                               /* read after flush */
-                                               do {
-                                                       ret = ctx->on_buffer_ready(local_stream[i], ctx);
-                                               } while (ret == EAGAIN);
-                                       }
-                               } else {
-                                       DBG("Polling fd %d tells it has hung up.", pollfd[i].fd);
-                               }
-                               rcu_read_lock();
-                               consumer_del_stream_rcu(&local_stream[i]->node.head);
-                               rcu_read_unlock();
-                               num_hup++;
                        }
                }
 
-               /* If every buffer FD has hung up, we end the read loop here */
-               if (nb_fd > 0 && num_hup == nb_fd) {
-                       DBG("every buffer FD has hung up\n");
-                       if (consumer_quit == 1) {
-                               goto end;
-                       }
+               /*
+                * If we read high prio channel in this loop, try again
+                * for more high prio data.
+                */
+               if (high_prio) {
                        continue;
                }
 
                /* Take care of low priority channels. */
-               if (high_prio == 0) {
-                       for (i = 0; i < nb_fd; i++) {
-                               if (pollfd[i].revents & POLLIN) {
-                                       DBG("Normal read on fd %d", pollfd[i].fd);
-                                       ret = ctx->on_buffer_ready(local_stream[i], ctx);
-                                       /* it's ok to have an unavailable subbuffer */
-                                       if (ret == EAGAIN) {
-                                               ret = 0;
-                                       }
+               for (i = 0; i < nb_fd; i++) {
+                       if ((pollfd[i].revents & POLLIN) ||
+                                       local_stream[i]->hangup_flush_done) {
+                               ssize_t len;
+
+                               DBG("Normal read on fd %d", pollfd[i].fd);
+                               len = ctx->on_buffer_ready(local_stream[i], ctx);
+                               /* it's ok to have an unavailable sub-buffer */
+                               if (len < 0 && len != -EAGAIN) {
+                                       goto end;
+                               } else if (len > 0) {
+                                       local_stream[i]->data_read = 1;
+                               }
+                       }
+               }
+
+               /* Handle hangup and errors */
+               for (i = 0; i < nb_fd; i++) {
+                       if (!local_stream[i]->hangup_flush_done
+                                       && (pollfd[i].revents & (POLLHUP | POLLERR | POLLNVAL))
+                                       && (consumer_data.type == LTTNG_CONSUMER32_UST
+                                               || consumer_data.type == LTTNG_CONSUMER64_UST)) {
+                               DBG("fd %d is hup|err|nval. Attempting flush and read.",
+                                       pollfd[i].fd);
+                               lttng_ustconsumer_on_stream_hangup(local_stream[i]);
+                               /* Attempt read again, for the data we just flushed. */
+                               local_stream[i]->data_read = 1;
+                       }
+                       /*
+                        * If the poll flag is HUP/ERR/NVAL and we have
+                        * read no data in this pass, we can remove the
+                        * stream from its hash table.
+                        */
+                       if ((pollfd[i].revents & POLLHUP)) {
+                               DBG("Polling fd %d tells it has hung up.", pollfd[i].fd);
+                               if (!local_stream[i]->data_read) {
+                                       consumer_del_stream(local_stream[i]);
+                                       num_hup++;
+                               }
+                       } else if (pollfd[i].revents & POLLERR) {
+                               ERR("Error returned in polling fd %d.", pollfd[i].fd);
+                               if (!local_stream[i]->data_read) {
+                                       consumer_del_stream(local_stream[i]);
+                                       num_hup++;
+                               }
+                       } else if (pollfd[i].revents & POLLNVAL) {
+                               ERR("Polling fd %d tells fd is not open.", pollfd[i].fd);
+                               if (!local_stream[i]->data_read) {
+                                       consumer_del_stream(local_stream[i]);
+                                       num_hup++;
                                }
                        }
+                       local_stream[i]->data_read = 0;
                }
        }
 end:
@@ -1125,7 +1237,7 @@ end:
        return NULL;
 }
 
-int lttng_consumer_read_subbuffer(struct lttng_consumer_stream *stream,
+ssize_t lttng_consumer_read_subbuffer(struct lttng_consumer_stream *stream,
                struct lttng_consumer_local_data *ctx)
 {
        switch (consumer_data.type) {
index dc5fc9968be02fbf45b223ef20a8371fdc4e0005..6ac781605c7284ecf7319e2b10fa0c3920b441b3 100644 (file)
@@ -2,19 +2,18 @@
  * Copyright (C) 2011 - Julien Desfossez <julien.desfossez@polymtl.ca>
  * Copyright (C) 2011 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; only version 2
- * of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
- * This program 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 General Public License for more details.
+ * This program 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 General Public License for
+ * more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #ifndef _LTTNG_CONSUMER_H
@@ -26,7 +25,8 @@
 
 #include <lttng/lttng.h>
 
-#include "src/common/hashtable/hashtable.h"
+#include <common/hashtable/hashtable.h>
+#include <common/compat/fcntl.h>
 
 /*
  * When the receiving thread dies, we need to have a way to make the polling
@@ -113,6 +113,7 @@ struct lttng_consumer_stream {
        /* For UST */
        struct lttng_ust_lib_ring_buffer *buf;
        int cpu;
+       int data_read;
        int hangup_flush_done;
        /* UID/GID of the user owning the session to which stream belongs */
        uid_t uid;
@@ -124,8 +125,11 @@ struct lttng_consumer_stream {
  * process.
  */
 struct lttng_consumer_local_data {
-       /* function to call when data is available on a buffer */
-       int (*on_buffer_ready)(struct lttng_consumer_stream *stream,
+       /*
+        * Function to call when data is available on a buffer.
+        * Returns the number of bytes read, or negative error value.
+        */
+       ssize_t (*on_buffer_ready)(struct lttng_consumer_stream *stream,
                        struct lttng_consumer_local_data *ctx);
        /*
         * function to call when we receive a new channel, it receives a
@@ -284,16 +288,16 @@ int consumer_add_channel(struct lttng_consumer_channel *channel);
 
 extern struct lttng_consumer_local_data *lttng_consumer_create(
                enum lttng_consumer_type type,
-               int (*buffer_ready)(struct lttng_consumer_stream *stream,
+               ssize_t (*buffer_ready)(struct lttng_consumer_stream *stream,
                        struct lttng_consumer_local_data *ctx),
                int (*recv_channel)(struct lttng_consumer_channel *channel),
                int (*recv_stream)(struct lttng_consumer_stream *stream),
                int (*update_stream)(int sessiond_key, uint32_t state));
 extern void lttng_consumer_destroy(struct lttng_consumer_local_data *ctx);
-extern int lttng_consumer_on_read_subbuffer_mmap(
+extern ssize_t lttng_consumer_on_read_subbuffer_mmap(
                struct lttng_consumer_local_data *ctx,
                struct lttng_consumer_stream *stream, unsigned long len);
-extern int lttng_consumer_on_read_subbuffer_splice(
+extern ssize_t lttng_consumer_on_read_subbuffer_splice(
                struct lttng_consumer_local_data *ctx,
                struct lttng_consumer_stream *stream, unsigned long len);
 extern int lttng_consumer_take_snapshot(struct lttng_consumer_local_data *ctx,
@@ -307,7 +311,7 @@ extern void *lttng_consumer_thread_receive_fds(void *data);
 extern int lttng_consumer_recv_cmd(struct lttng_consumer_local_data *ctx,
                int sock, struct pollfd *consumer_sockpoll);
 
-int lttng_consumer_read_subbuffer(struct lttng_consumer_stream *stream,
+ssize_t lttng_consumer_read_subbuffer(struct lttng_consumer_stream *stream,
                struct lttng_consumer_local_data *ctx);
 int lttng_consumer_on_recv_stream(struct lttng_consumer_stream *stream);
 
index 2389894219e20b3665d9f5707ffbfb116b66b19f..5ee6562d91906b01b54b7909b7148a704f9dc9ce 100644 (file)
@@ -2,18 +2,18 @@
  * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
  *                      Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; only version 2 of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
  * This program 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 General Public License for
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  * more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place - Suite 330, Boston, MA  02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #ifndef _DEFAULTS_H
index 81c20223d124282b59bb8ea23801cd714156f441..5837d1cc33184b34398f94a29775224e0d38e469 100644 (file)
@@ -1,18 +1,18 @@
 /*
  * Copyright (C)  2011 - David Goulet <david.goulet@polymtl.ca>
  *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; only version 2 of the License.
- * 
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
+ *
  * This program 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 General Public License for
  * more details.
- * 
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #ifndef _ERROR_H
 #include <stdio.h>
 #include <string.h>
 
+#ifndef _GNU_SOURCE
+#error "lttng-tools error.h needs _GNU_SOURCE"
+#endif
+
 /* Stringify the expansion of a define */
 #define XSTR(d) STR(d)
 #define STR(s) #s
 
-extern int opt_quiet;
-extern int opt_verbose;
+extern int lttng_opt_quiet;
+extern int lttng_opt_verbose;
 
 #define PRINT_ERR   0x1
 #define PRINT_WARN  0x2
@@ -40,21 +44,22 @@ extern int opt_verbose;
 /*
  * Macro for printing message depending on command line option and verbosity.
  */
-#define __lttng_print(type, fmt, args...)                                 \
-       do {                                                                  \
-               if (opt_quiet == 0) {                                             \
-                       if (type == PRINT_MSG) {                                      \
-                               fprintf(stdout, fmt, ## args);                            \
-                       } else if (((type & PRINT_DBG) && opt_verbose == 1) ||        \
-                                       ((type & (PRINT_DBG | PRINT_DBG2)) &&                 \
-                                               opt_verbose == 2) ||                              \
-                                       ((type & (PRINT_DBG | PRINT_DBG2 | PRINT_DBG3)) &&    \
-                                               opt_verbose == 3)) {                              \
-                               fprintf(stderr, fmt, ## args);                            \
-                       } else if (type & (PRINT_ERR | PRINT_WARN | PRINT_BUG)) {     \
-                               fprintf(stderr, fmt, ## args);                            \
-                       }                                                             \
-               }                                                                 \
+#define __lttng_print(type, fmt, args...)                           \
+       do {                                                            \
+               if (lttng_opt_quiet == 0 && type == PRINT_MSG) {            \
+                       fprintf(stdout, fmt, ## args);                          \
+               } else if (lttng_opt_quiet == 0 &&                          \
+                               (((type & PRINT_DBG) && lttng_opt_verbose == 1) ||  \
+                               ((type & (PRINT_DBG | PRINT_DBG2)) &&               \
+                                       lttng_opt_verbose == 2) ||                      \
+                               ((type & (PRINT_DBG | PRINT_DBG2 | PRINT_DBG3)) &&  \
+                                       lttng_opt_verbose == 3))) {                     \
+                       fprintf(stderr, fmt, ## args);                          \
+               } else if (lttng_opt_quiet == 0 && (type & (PRINT_WARN))) { \
+                       fprintf(stderr, fmt, ## args);                          \
+               } else if (type & (PRINT_ERR | PRINT_BUG)) {                \
+                       fprintf(stderr, fmt, ## args);                          \
+               }                                                           \
        } while (0);
 
 #define MSG(fmt, args...) \
@@ -75,14 +80,31 @@ extern int opt_verbose;
                " [in %s() at " __FILE__ ":" XSTR(__LINE__) "]\n", ## args, __func__)
 
 #define _PERROR(fmt, args...) \
-       __lttng_print(PRINT_ERR, "perror " fmt "\n", ## args)
+       __lttng_print(PRINT_ERR, "PERROR: " fmt \
+               " [in %s() at " __FILE__ ":" XSTR(__LINE__) "]\n", ## args, __func__)
+
+#if !defined(__linux__) || ((_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && !defined(_GNU_SOURCE))
 
+/*
+ * Version using XSI strerror_r.
+ */
+#define PERROR(call, args...) \
+       do { \
+               char buf[200]; \
+               strerror_r(errno, buf, sizeof(buf)); \
+               _PERROR(call ": %s", ## args, buf); \
+       } while(0);
+#else
+/*
+ * Version using GNU strerror_r, for linux with appropriate defines.
+ */
 #define PERROR(call, args...) \
-    do { \
+       do { \
                char *buf; \
                char tmp[200]; \
                buf = strerror_r(errno, tmp, sizeof(tmp)); \
                _PERROR(call ": %s", ## args, buf); \
        } while(0);
+#endif
 
 #endif /* _ERROR_H */
index 2080107005739f5d4cb61c5f9761a14d7b375998..ac39004e64617eceb6f1ba7d2b5b479021e50237 100644 (file)
@@ -1,18 +1,18 @@
 /*
  * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
  *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; only version 2 of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
  * This program 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 General Public License for
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  * more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place - Suite 330, Boston, MA  02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #define _GNU_SOURCE
@@ -110,6 +110,7 @@ void lttng_ht_destroy(struct lttng_ht *ht)
 
        ret = cds_lfht_destroy(ht->ht, NULL);
        assert(!ret);
+       free(ht);
 }
 
 /*
@@ -199,6 +200,28 @@ void lttng_ht_add_unique_ulong(struct lttng_ht *ht,
        assert(node_ptr == &node->node);
 }
 
+/*
+ * Add replace unsigned long node to hashtable.
+ */
+struct lttng_ht_node_ulong *lttng_ht_add_replace_ulong(struct lttng_ht *ht,
+               struct lttng_ht_node_ulong *node)
+{
+       struct cds_lfht_node *node_ptr;
+       assert(ht);
+       assert(ht->ht);
+       assert(node);
+
+       node_ptr = cds_lfht_add_replace(ht->ht,
+                       ht->hash_fct((void *) node->key, HASH_SEED), ht->match_fct,
+                       (void *) node->key, &node->node);
+       if (!node_ptr) {
+               return NULL;
+       } else {
+               return caa_container_of(node_ptr, struct lttng_ht_node_ulong, node);
+       }
+       assert(node_ptr == &node->node);
+}
+
 /*
  * Delete node from hashtable.
  */
index 1c2889d3e7e09be94d75bf1800197f6a1373ec08..f242e75e895c78ab22769468efca4aa3c074be95 100644 (file)
@@ -1,18 +1,18 @@
 /*
  * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
  *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; only version 2 of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
  * This program 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 General Public License for
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  * more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place - Suite 330, Boston, MA  02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #ifndef _LTT_HT_H
@@ -72,6 +72,8 @@ extern void lttng_ht_add_unique_str(struct lttng_ht *ht,
                struct lttng_ht_node_str *node);
 extern void lttng_ht_add_unique_ulong(struct lttng_ht *ht,
                struct lttng_ht_node_ulong *node);
+extern struct lttng_ht_node_ulong *lttng_ht_add_replace_ulong(
+               struct lttng_ht *ht, struct lttng_ht_node_ulong *node);
 
 extern int lttng_ht_del(struct lttng_ht *ht, struct lttng_ht_iter *iter);
 
index 4554ed6007f20df68bfac3f2fe74a5a9e39c55fc..b136e1ae0eb73b46d2035cf2bbd9e470f96861d3 100644 (file)
 #include <sys/mman.h>
 #include "rculfhash-internal.h"
 
+#ifndef MAP_ANONYMOUS
+#define MAP_ANONYMOUS MAP_ANON
+#endif
+
 /* reserve inaccessible memory space without allocation any memory */
 static void *memory_map(size_t length)
 {
index 50cd1ba959cd8dbb838b9785deaa83ffae8e4501..3a0e2b76c8e644d0b4930214e2ac04ab8bd88e93 100644 (file)
@@ -3,18 +3,18 @@
  * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
  * Copyright (C) 2011 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; only version 2 of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
  * This program 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 General Public License for
  * more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place - Suite 330, Boston, MA  02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 /*
@@ -50,7 +50,6 @@
  */
 
 #include <assert.h>
-#include <endian.h>    /* attempt to define endianness */
 #include <stdint.h>     /* defines uint32_t etc */
 #include <stdio.h>      /* defines printf for tests */
 #include <string.h>
@@ -59,6 +58,7 @@
 #include <urcu/compiler.h>
 
 #include "utils.h"
+#include <common/compat/endian.h>    /* attempt to define endianness */
 
 /*
  * My best guess at if you are big-endian or little-endian.  This may
index 86b340f72c75cf3b9ec8ddae3b72110ac894e3c7..4f0890892ef4b27bf964e3be5b7765fac77ec13e 100644 (file)
@@ -1,18 +1,18 @@
 /*
  * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
  *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; only version 2 of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
  * This program 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 General Public License for
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  * more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place - Suite 330, Boston, MA  02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #ifndef _LTT_HT_UTILS_H
index 3489ab6ed866970eec6915701ffef029d27d6c36..9abee1de8ad5d3bb01efdf2b04ada6270811de18 100644 (file)
@@ -2,24 +2,22 @@
  * Copyright (C) 2011 - Julien Desfossez <julien.desfossez@polymtl.ca>
  *                      Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; only version 2
- * of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
  * This program 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 General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #define _GNU_SOURCE
 #include <assert.h>
-#include <fcntl.h>
 #include <poll.h>
 #include <pthread.h>
 #include <stdlib.h>
 #include <sys/socket.h>
 #include <sys/types.h>
 #include <unistd.h>
+#include <sys/stat.h>
 
 #include <common/common.h>
 #include <common/kernel-ctl/kernel-ctl.h>
 #include <common/sessiond-comm/sessiond-comm.h>
+#include <common/compat/fcntl.h>
 
 #include "kernel-consumer.h"
 
@@ -44,12 +44,12 @@ extern volatile int consumer_quit;
  *
  * Returns the number of bytes written
  */
-int lttng_kconsumer_on_read_subbuffer_mmap(
+ssize_t lttng_kconsumer_on_read_subbuffer_mmap(
                struct lttng_consumer_local_data *ctx,
                struct lttng_consumer_stream *stream, unsigned long len)
 {
        unsigned long mmap_offset;
-       long ret = 0;
+       ssize_t ret = 0;
        off_t orig_offset = stream->out_fd_offset;
        int fd = stream->wait_fd;
        int outfd = stream->out_fd;
@@ -57,7 +57,7 @@ int lttng_kconsumer_on_read_subbuffer_mmap(
        /* get the offset inside the fd to mmap */
        ret = kernctl_get_mmap_read_offset(fd, &mmap_offset);
        if (ret != 0) {
-               ret = -errno;
+               errno = -ret;
                perror("kernctl_get_mmap_read_offset");
                goto end;
        }
@@ -67,12 +67,12 @@ int lttng_kconsumer_on_read_subbuffer_mmap(
                if (ret >= len) {
                        len = 0;
                } else if (ret < 0) {
-                       ret = -errno;
+                       errno = -ret;
                        perror("Error in file write");
                        goto end;
                }
                /* This won't block, but will start writeout asynchronously */
-               sync_file_range(outfd, stream->out_fd_offset, ret,
+               lttng_sync_file_range(outfd, stream->out_fd_offset, ret,
                                SYNC_FILE_RANGE_WRITE);
                stream->out_fd_offset += ret;
        }
@@ -90,11 +90,11 @@ end:
  *
  * Returns the number of bytes spliced.
  */
-int lttng_kconsumer_on_read_subbuffer_splice(
+ssize_t lttng_kconsumer_on_read_subbuffer_splice(
                struct lttng_consumer_local_data *ctx,
                struct lttng_consumer_stream *stream, unsigned long len)
 {
-       long ret = 0;
+       ssize_t ret = 0;
        loff_t offset = 0;
        off_t orig_offset = stream->out_fd_offset;
        int fd = stream->wait_fd;
@@ -105,24 +105,24 @@ int lttng_kconsumer_on_read_subbuffer_splice(
                                (unsigned long)offset, fd);
                ret = splice(fd, &offset, ctx->consumer_thread_pipe[1], NULL, len,
                                SPLICE_F_MOVE | SPLICE_F_MORE);
-               DBG("splice chan to pipe ret %ld", ret);
+               DBG("splice chan to pipe ret %zd", ret);
                if (ret < 0) {
-                       ret = errno;
+                       errno = -ret;
                        perror("Error in relay splice");
                        goto splice_error;
                }
 
                ret = splice(ctx->consumer_thread_pipe[0], NULL, outfd, NULL, ret,
                                SPLICE_F_MOVE | SPLICE_F_MORE);
-               DBG("splice pipe to file %ld", ret);
+               DBG("splice pipe to file %zd", ret);
                if (ret < 0) {
-                       ret = errno;
+                       errno = -ret;
                        perror("Error in file splice");
                        goto splice_error;
                }
                len -= ret;
                /* This won't block, but will start writeout asynchronously */
-               sync_file_range(outfd, stream->out_fd_offset, ret,
+               lttng_sync_file_range(outfd, stream->out_fd_offset, ret,
                                SYNC_FILE_RANGE_WRITE);
                stream->out_fd_offset += ret;
        }
@@ -164,7 +164,7 @@ int lttng_kconsumer_take_snapshot(struct lttng_consumer_local_data *ctx,
 
        ret = kernctl_snapshot(infd);
        if (ret != 0) {
-               ret = errno;
+               errno = -ret;
                perror("Getting sub-buffer snapshot.");
        }
 
@@ -186,7 +186,7 @@ int lttng_kconsumer_get_produced_snapshot(
 
        ret = kernctl_snapshot_get_produced(infd, pos);
        if (ret != 0) {
-               ret = errno;
+               errno = -ret;
                perror("kernctl_snapshot_get_produced");
        }
 
@@ -307,19 +307,18 @@ end_nosignal:
 /*
  * Consume data on a file descriptor and write it on a trace file.
  */
-int lttng_kconsumer_read_subbuffer(struct lttng_consumer_stream *stream,
+ssize_t lttng_kconsumer_read_subbuffer(struct lttng_consumer_stream *stream,
                struct lttng_consumer_local_data *ctx)
 {
        unsigned long len;
        int err;
-       long ret = 0;
+       ssize_t ret = 0;
        int infd = stream->wait_fd;
 
        DBG("In read_subbuffer (infd : %d)", infd);
        /* Get the next subbuffer */
        err = kernctl_get_next_subbuf(infd);
        if (err != 0) {
-               ret = errno;
                /*
                 * This is a debug message even for single-threaded consumer,
                 * because poll() have more relaxed criterions than get subbuf,
@@ -336,7 +335,7 @@ int lttng_kconsumer_read_subbuffer(struct lttng_consumer_stream *stream,
                        /* read the whole subbuffer */
                        err = kernctl_get_padded_subbuf_size(infd, &len);
                        if (err != 0) {
-                               ret = errno;
+                               errno = -ret;
                                perror("Getting sub-buffer len failed.");
                                goto end;
                        }
@@ -355,7 +354,7 @@ int lttng_kconsumer_read_subbuffer(struct lttng_consumer_stream *stream,
                        /* read the used subbuffer size */
                        err = kernctl_get_padded_subbuf_size(infd, &len);
                        if (err != 0) {
-                               ret = errno;
+                               errno = -ret;
                                perror("Getting sub-buffer len failed.");
                                goto end;
                        }
@@ -376,7 +375,7 @@ int lttng_kconsumer_read_subbuffer(struct lttng_consumer_stream *stream,
 
        err = kernctl_put_next_subbuf(infd);
        if (err != 0) {
-               ret = errno;
+               errno = -ret;
                if (errno == EFAULT) {
                        perror("Error in unreserving sub buffer\n");
                } else if (errno == EIO) {
@@ -414,7 +413,7 @@ int lttng_kconsumer_on_recv_stream(struct lttng_consumer_stream *stream)
 
                ret = kernctl_get_mmap_len(stream->wait_fd, &mmap_len);
                if (ret != 0) {
-                       ret = errno;
+                       errno = -ret;
                        perror("kernctl_get_mmap_len");
                        goto error_close_fd;
                }
index 6e820044bad2ea6618786ff4673bd009f405d199..18b5396eb111e92acdaf71c10420de93a9c408ea 100644 (file)
@@ -2,19 +2,18 @@
  * Copyright (C) 2011 - Julien Desfossez <julien.desfossez@polymtl.ca>
  * Copyright (C) 2011 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; only version 2
- * of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
  * This program 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
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #ifndef _LTTNG_KCONSUMER_H
 /*
  * Mmap the ring buffer, read it and write the data to the tracefile.
  *
- * Returns the number of bytes written.
+ * Returns the number of bytes written, or negative value on error.
  */
-extern int lttng_kconsumer_on_read_subbuffer_mmap(
+extern ssize_t lttng_kconsumer_on_read_subbuffer_mmap(
                struct lttng_consumer_local_data *ctx,
                struct lttng_consumer_stream *stream, unsigned long len);
 
 /*
  * Splice the data from the ring buffer to the tracefile.
  *
- * Returns the number of bytes spliced.
+ * Returns the number of bytes spliced, or negative error value on
+ * error.
  */
-extern int lttng_kconsumer_on_read_subbuffer_splice(
+extern ssize_t lttng_kconsumer_on_read_subbuffer_splice(
                struct lttng_consumer_local_data *ctx,
                struct lttng_consumer_stream *stream, unsigned long len);
 
@@ -62,7 +62,7 @@ int lttng_kconsumer_recv_cmd(struct lttng_consumer_local_data *ctx,
                int sock, struct pollfd *consumer_sockpoll);
 
 
-int lttng_kconsumer_read_subbuffer(struct lttng_consumer_stream *stream,
+ssize_t lttng_kconsumer_read_subbuffer(struct lttng_consumer_stream *stream,
                struct lttng_consumer_local_data *ctx);
 int lttng_kconsumer_on_recv_stream(struct lttng_consumer_stream *stream);
 
index 973ea7993076b04fb1ab71d87e182efcad8f45fa..f17bf3bc7bf6fb96052e912c474a0118b52754c3 100644 (file)
@@ -2,19 +2,18 @@
  * Copyright (C) 2011 - Julien Desfossez <julien.desfossez@polymtl.ca>
  *                      Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; only version 2
- * of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
  * This program 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 General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #include <sys/ioctl.h>
index 2bfb2b0484cc0b07a20ecab2f6579959821d5010..f9b81c334a647f205096ba56ed3d38bd91d7c36a 100644 (file)
@@ -2,19 +2,18 @@
  * Copyright (C) 2011 - Julien Desfossez <julien.desfossez@polymtl.ca>
  *                      Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; only version 2
- * of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
  * This program 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 General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #ifndef _LTTNG_KERNEL_CTL_H
index 408535d431a7578702cc4544f38f69dada71ae78..70408987b46dd4666e1a3a73bdec88d9d6779ae8 100644 (file)
@@ -2,19 +2,18 @@
  * Copyright (C) 2011 - Julien Desfossez <julien.desfossez@polymtl.ca>
  *                      Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; only version 2
- * of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
  * This program 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 General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #ifndef _LTT_KERNEL_IOCTL_H
index 05303a5e0d2c1c889c92f4adfecf2a552af8acf6..cbeed1b1982c057d944d64c5ba2496a4f411e492 100644 (file)
@@ -3,19 +3,18 @@
  *                      Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  *                      David Goulet <david.goulet@polymtl.ca>
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; only version 2
- * of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
- * This program 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 General Public License for more details.
+ * This program 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 General Public License for
+ * more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #ifndef _LTTNG_KERNEL_H
index 3c72285c34ce324c4d2856f1af36c37e624774d2..8185c85abfdacdece8bd4442cc10ca2898b8bd32 100644 (file)
@@ -2,18 +2,18 @@
  * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
  *                      Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; only version 2 of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
  * This program 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 General Public License for
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  * more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place - Suite 330, Boston, MA  02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #ifndef _MACROS_H
index 07912a7d68bf7ce97cf7ba765194fd66e28334c8..7de566ddb9fce211bb0db34d3c95c24a7cf6b3af 100644 (file)
@@ -2,18 +2,18 @@
  * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
  *                      Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; only version 2 of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
  * This program 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 General Public License for
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  * more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place - Suite 330, Boston, MA  02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #define _GNU_SOURCE
 #include <unistd.h>
 #include <fcntl.h>
 #include <sched.h>
-#include <sys/mman.h>
+#include <sys/signal.h>
 
 #include <common/error.h>
+#include <common/compat/mman.h>
+#include <common/compat/clone.h>
 
 #include "runas.h"
 
 #define MAP_STACK              0
 #endif
 
+#ifdef __FreeBSD__
+/* FreeBSD MAP_STACK always return -ENOMEM */
+#define LTTNG_MAP_STACK                0
+#else
+#define LTTNG_MAP_STACK                MAP_STACK
+#endif
+
+#ifndef MAP_GROWSDOWN
+#define MAP_GROWSDOWN          0
+#endif
+
+#ifndef MAP_ANONYMOUS
+#define MAP_ANONYMOUS          MAP_ANON
+#endif
+
 struct run_as_data {
        int (*cmd)(void *data);
        void *data;
@@ -154,14 +171,14 @@ int child_run_as(void *_data)
        if (data->gid != getegid()) {
                ret = setegid(data->gid);
                if (ret < 0) {
-                       perror("setegid");
+                       PERROR("setegid");
                        return EXIT_FAILURE;
                }
        }
        if (data->uid != geteuid()) {
                ret = seteuid(data->uid);
                if (ret < 0) {
-                       perror("seteuid");
+                       PERROR("seteuid");
                        return EXIT_FAILURE;
                }
        }
@@ -177,7 +194,7 @@ int child_run_as(void *_data)
                writelen = write(data->retval_pipe, &sendret.c[index],
                                writeleft);
                if (writelen < 0) {
-                       perror("write");
+                       PERROR("write");
                        return EXIT_FAILURE;
                }
                writeleft -= writelen;
@@ -187,7 +204,7 @@ int child_run_as(void *_data)
 }
 
 static
-int run_as(int (*cmd)(void *data), void *data, uid_t uid, gid_t gid)
+int run_as_clone(int (*cmd)(void *data), void *data, uid_t uid, gid_t gid)
 {
        struct run_as_data run_as_data;
        int ret = 0;
@@ -214,7 +231,8 @@ int run_as(int (*cmd)(void *data), void *data, uid_t uid, gid_t gid)
 
        ret = pipe(retval_pipe);
        if (ret < 0) {
-               perror("pipe");
+               PERROR("pipe");
+               retval.i = ret;
                goto end;
        }
        run_as_data.data = data;
@@ -224,23 +242,22 @@ int run_as(int (*cmd)(void *data), void *data, uid_t uid, gid_t gid)
        run_as_data.retval_pipe = retval_pipe[1];       /* write end */
        child_stack = mmap(NULL, RUNAS_CHILD_STACK_SIZE,
                PROT_WRITE | PROT_READ,
-               MAP_PRIVATE | MAP_GROWSDOWN | MAP_ANONYMOUS | MAP_STACK,
+               MAP_PRIVATE | MAP_GROWSDOWN | MAP_ANONYMOUS | LTTNG_MAP_STACK,
                -1, 0);
        if (child_stack == MAP_FAILED) {
-               perror("mmap");
-               ret = -ENOMEM;
+               PERROR("mmap");
+               retval.i = -ENOMEM;
                goto close_pipe;
        }
        /*
         * Pointing to the middle of the stack to support architectures
         * where the stack grows up (HPPA).
         */
-       pid = clone(child_run_as, child_stack + (RUNAS_CHILD_STACK_SIZE / 2),
-               CLONE_FILES | SIGCHLD,
-               &run_as_data, NULL);
+       pid = lttng_clone_files(child_run_as, child_stack + (RUNAS_CHILD_STACK_SIZE / 2),
+               &run_as_data);
        if (pid < 0) {
-               perror("clone");
-               ret = pid;
+               PERROR("clone");
+               retval.i = pid;
                goto unmap_stack;
        }
        /* receive return value */
@@ -249,7 +266,7 @@ int run_as(int (*cmd)(void *data), void *data, uid_t uid, gid_t gid)
        do {
                readlen = read(retval_pipe[0], &retval.c[index], readleft);
                if (readlen < 0) {
-                       perror("read");
+                       PERROR("read");
                        ret = -1;
                        break;
                }
@@ -263,21 +280,51 @@ int run_as(int (*cmd)(void *data), void *data, uid_t uid, gid_t gid)
         */
        pid = waitpid(pid, &status, 0);
        if (pid < 0 || !WIFEXITED(status) || WEXITSTATUS(status) != 0) {
-               perror("wait");
-               ret = -1;
+               PERROR("wait");
+               retval.i = -1;
        }
 unmap_stack:
        ret = munmap(child_stack, RUNAS_CHILD_STACK_SIZE);
        if (ret < 0) {
-               perror("munmap");
+               PERROR("munmap");
+               retval.i = ret;
        }
 close_pipe:
-       close(retval_pipe[0]);
-       close(retval_pipe[1]);
+       ret = close(retval_pipe[0]);
+       if (ret) {
+               PERROR("close");
+       }
+       ret = close(retval_pipe[1]);
+       if (ret) {
+               PERROR("close");
+       }
 end:
        return retval.i;
 }
 
+/*
+ * To be used on setups where gdb has issues debugging programs using
+ * clone/rfork. Note that this is for debuging ONLY, and should not be
+ * considered secure.
+ */
+static
+int run_as_noclone(int (*cmd)(void *data), void *data, uid_t uid, gid_t gid)
+{
+       return cmd(data);
+}
+
+static
+int run_as(int (*cmd)(void *data), void *data, uid_t uid, gid_t gid)
+{
+       if (!getenv("LTTNG_DEBUG_NOCLONE")) {
+               DBG("Using run_as_clone");
+               return run_as_clone(cmd, data, uid, gid);
+       } else {
+               DBG("Using run_as_noclone");
+               return run_as_noclone(cmd, data, uid, gid);
+       }
+}
+
 int run_as_mkdir_recursive(const char *path, mode_t mode, uid_t uid, gid_t gid)
 {
        struct run_as_mkdir_data data;
index c8c485c1f22357d8ee6eb6c7fdd78b3ce5b1b683..356bb22863fe2c448fed98e8b7b90677868ba6fb 100644 (file)
@@ -5,19 +5,18 @@
  * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
  *                      Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; only verion 2
- * of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
- * This program 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 General Public License for more details.
+ * This program 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 General Public License for
+ * more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #include <unistd.h>
index 0c29003a6267a382b204a6f277a9d0a1468ad182..f396c42f3c4417499a4534af41523a56fd2a1d33 100644 (file)
@@ -2,18 +2,18 @@
  * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
  *                      Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; only version 2 of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  * 
  * This program 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 General Public License for
  * more details.
  * 
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place - Suite 330, Boston, MA  02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #define _GNU_SOURCE
 #include <string.h>
 #include <sys/stat.h>
 #include <sys/types.h>
-#include <sys/un.h>
 #include <unistd.h>
 #include <errno.h>
 
 #include <common/defaults.h>
+#include <common/error.h>
 
 #include "sessiond-comm.h"
 
@@ -60,6 +60,7 @@ static const char *lttcomm_readable_code[] = {
        [ LTTCOMM_ERR_INDEX(LTTCOMM_KERN_VERSION) ] = "Kernel tracer version is not compatible",
        [ LTTCOMM_ERR_INDEX(LTTCOMM_KERN_EVENT_EXIST) ] = "Kernel event already exists",
        [ LTTCOMM_ERR_INDEX(LTTCOMM_KERN_SESS_FAIL) ] = "Kernel create session failed",
+       [ LTTCOMM_ERR_INDEX(LTTCOMM_KERN_CHAN_EXIST) ] = "Kernel channel already exists",
        [ LTTCOMM_ERR_INDEX(LTTCOMM_KERN_CHAN_FAIL) ] = "Kernel create channel failed",
        [ LTTCOMM_ERR_INDEX(LTTCOMM_KERN_CHAN_NOT_FOUND) ] = "Kernel channel not found",
        [ LTTCOMM_ERR_INDEX(LTTCOMM_KERN_CHAN_DISABLE_FAIL) ] = "Disable kernel channel failed",
@@ -101,6 +102,10 @@ static const char *lttcomm_readable_code[] = {
        [ LTTCOMM_ERR_INDEX(LTTCOMM_UST_EVENT_NOT_FOUND)] = "UST event not found",
        [ LTTCOMM_ERR_INDEX(LTTCOMM_UST_CONTEXT_EXIST)] = "UST context already exist",
        [ LTTCOMM_ERR_INDEX(LTTCOMM_UST_CONTEXT_INVAL)] = "UST invalid context",
+       [ LTTCOMM_ERR_INDEX(LTTCOMM_NEED_ROOT_SESSIOND) ] = "Tracing the kernel requires a root lttng-sessiond daemon and \"tracing\" group user membership",
+       [ LTTCOMM_ERR_INDEX(LTTCOMM_TRACE_ALREADY_STARTED) ] = "Tracing already started",
+       [ LTTCOMM_ERR_INDEX(LTTCOMM_TRACE_ALREADY_STOPPED) ] = "Tracing already stopped",
+
        [ LTTCOMM_ERR_INDEX(CONSUMERD_COMMAND_SOCK_READY) ] = "consumerd command socket ready",
        [ LTTCOMM_ERR_INDEX(CONSUMERD_SUCCESS_RECV_FD) ] = "consumerd success on receiving fds",
        [ LTTCOMM_ERR_INDEX(CONSUMERD_ERROR_RECV_FD) ] = "consumerd error on receiving fds",
@@ -116,6 +121,7 @@ static const char *lttcomm_readable_code[] = {
        [ LTTCOMM_ERR_INDEX(CONSUMERD_SPLICE_ENOMEM) ] = "consumerd splice ENOMEM",
        [ LTTCOMM_ERR_INDEX(CONSUMERD_SPLICE_ESPIPE) ] = "consumerd splice ESPIPE",
        [ LTTCOMM_ERR_INDEX(LTTCOMM_NO_EVENT) ] = "Event not found",
+       [ LTTCOMM_ERR_INDEX(LTTCOMM_INVALID) ] = "Invalid parameter",
 };
 
 /*
@@ -141,12 +147,11 @@ const char *lttcomm_get_readable_code(enum lttcomm_return_code code)
 int lttcomm_connect_unix_sock(const char *pathname)
 {
        struct sockaddr_un sun;
-       int fd;
-       int ret;
+       int fd, ret, closeret;
 
        fd = socket(PF_UNIX, SOCK_STREAM, 0);
        if (fd < 0) {
-               perror("socket");
+               PERROR("socket");
                ret = fd;
                goto error;
        }
@@ -168,7 +173,10 @@ int lttcomm_connect_unix_sock(const char *pathname)
        return fd;
 
 error_connect:
-       close(fd);
+       closeret = close(fd);
+       if (closeret) {
+               PERROR("close");
+       }
 error:
        return ret;
 }
@@ -186,7 +194,7 @@ int lttcomm_accept_unix_sock(int sock)
        /* Blocking call */
        new_fd = accept(sock, (struct sockaddr *) &sun, &len);
        if (new_fd < 0) {
-               perror("accept");
+               PERROR("accept");
        }
 
        return new_fd;
@@ -204,7 +212,7 @@ int lttcomm_create_unix_sock(const char *pathname)
 
        /* Create server socket */
        if ((fd = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) {
-               perror("socket");
+               PERROR("socket");
                goto error;
        }
 
@@ -217,7 +225,7 @@ int lttcomm_create_unix_sock(const char *pathname)
        (void) unlink(pathname);
        ret = bind(fd, (struct sockaddr *) &sun, sizeof(sun));
        if (ret < 0) {
-               perror("bind");
+               PERROR("bind");
                goto error;
        }
 
@@ -236,7 +244,7 @@ int lttcomm_listen_unix_sock(int sock)
 
        ret = listen(sock, LTTNG_SESSIOND_COMM_MAX_LISTEN);
        if (ret < 0) {
-               perror("listen");
+               PERROR("listen");
        }
 
        return ret;
@@ -261,9 +269,11 @@ ssize_t lttcomm_recv_unix_sock(int sock, void *buf, size_t len)
        msg.msg_iov = iov;
        msg.msg_iovlen = 1;
 
-       ret = recvmsg(sock, &msg, MSG_WAITALL);
+       do {
+               ret = recvmsg(sock, &msg, MSG_WAITALL);
+       } while (ret < 0 && errno == EINTR);
        if (ret < 0) {
-               perror("recvmsg");
+               PERROR("recvmsg");
        }
 
        return ret;
@@ -289,7 +299,13 @@ ssize_t lttcomm_send_unix_sock(int sock, void *buf, size_t len)
 
        ret = sendmsg(sock, &msg, 0);
        if (ret < 0) {
-               perror("sendmsg");
+               /*
+                * Only warn about EPIPE when quiet mode is deactivated.
+                * We consider EPIPE as expected.
+                */
+               if (errno != EPIPE || !lttng_opt_quiet) {
+                       PERROR("sendmsg");
+               }
        }
 
        return ret;
@@ -300,15 +316,18 @@ ssize_t lttcomm_send_unix_sock(int sock, void *buf, size_t len)
  */
 int lttcomm_close_unix_sock(int sock)
 {
-       int ret;
+       int ret, closeret;
 
        /* Shutdown receptions and transmissions */
        ret = shutdown(sock, SHUT_RDWR);
        if (ret < 0) {
-               perror("shutdown");
+               PERROR("shutdown");
        }
 
-       close(sock);
+       closeret = close(sock);
+       if (closeret) {
+               PERROR("close");
+       }
 
        return ret;
 }
@@ -349,9 +368,17 @@ ssize_t lttcomm_send_fds_unix_sock(int sock, int *fds, size_t nb_fd)
        msg.msg_iov = iov;
        msg.msg_iovlen = 1;
 
-       ret = sendmsg(sock, &msg, 0);
+       do {
+               ret = sendmsg(sock, &msg, 0);
+       } while (ret < 0 && errno == EINTR);
        if (ret < 0) {
-               perror("sendmsg");
+               /*
+                * Only warn about EPIPE when quiet mode is deactivated.
+                * We consider EPIPE as expected.
+                */
+               if (errno != EPIPE || !lttng_opt_quiet) {
+                       PERROR("sendmsg");
+               }
        }
        return ret;
 }
@@ -384,9 +411,11 @@ ssize_t lttcomm_recv_fds_unix_sock(int sock, int *fds, size_t nb_fd)
        msg.msg_control = recv_fd;
        msg.msg_controllen = sizeof(recv_fd);
 
-       ret = recvmsg(sock, &msg, 0);
+       do {
+               ret = recvmsg(sock, &msg, 0);
+       } while (ret < 0 && errno == EINTR);
        if (ret < 0) {
-               perror("recvmsg fds");
+               PERROR("recvmsg fds");
                goto end;
        }
        if (ret != 1) {
@@ -412,7 +441,7 @@ ssize_t lttcomm_recv_fds_unix_sock(int sock, int *fds, size_t nb_fd)
        }
        if (cmsg->cmsg_len != CMSG_LEN(sizeof_fds)) {
                fprintf(stderr, "Error: Received %zu bytes of ancillary data, expected %zu\n",
-                               cmsg->cmsg_len, CMSG_LEN(sizeof_fds));
+                               (size_t) cmsg->cmsg_len, (size_t) CMSG_LEN(sizeof_fds));
                ret = -1;
                goto end;
        }
@@ -430,12 +459,14 @@ end:
 ssize_t lttcomm_send_creds_unix_sock(int sock, void *buf, size_t len)
 {
        struct msghdr msg;
-       struct cmsghdr *cmptr;
        struct iovec iov[1];
        ssize_t ret = -1;
-       struct ucred *creds;
-       size_t sizeof_cred = sizeof(struct ucred);
+#ifdef __linux__
+       struct cmsghdr *cmptr;
+       size_t sizeof_cred = sizeof(lttng_sock_cred);
        char anc_buf[CMSG_SPACE(sizeof_cred)];
+       lttng_sock_cred *creds;
+#endif /* __linux__ */
 
        memset(&msg, 0, sizeof(msg));
 
@@ -444,25 +475,34 @@ ssize_t lttcomm_send_creds_unix_sock(int sock, void *buf, size_t len)
        msg.msg_iov = iov;
        msg.msg_iovlen = 1;
 
+#ifdef __linux__
        msg.msg_control = (caddr_t) anc_buf;
        msg.msg_controllen = CMSG_LEN(sizeof_cred);
 
        cmptr = CMSG_FIRSTHDR(&msg);
        cmptr->cmsg_level = SOL_SOCKET;
-       cmptr->cmsg_type = SCM_CREDENTIALS;
+       cmptr->cmsg_type = LTTNG_SOCK_CREDS;
        cmptr->cmsg_len = CMSG_LEN(sizeof_cred);
 
-       creds = (struct ucred *) CMSG_DATA(cmptr);
+       creds = (lttng_sock_cred*) CMSG_DATA(cmptr);
 
-       creds->uid = geteuid();
-       creds->gid = getegid();
-       creds->pid = getpid();
+       LTTNG_SOCK_SET_UID_CRED(creds, geteuid());
+       LTTNG_SOCK_SET_GID_CRED(creds, getegid());
+       LTTNG_SOCK_SET_PID_CRED(creds, getpid());
+#endif /* __linux__ */
 
-       ret = sendmsg(sock, &msg, 0);
+       do {
+               ret = sendmsg(sock, &msg, 0);
+       } while (ret < 0 && errno == EINTR);
        if (ret < 0) {
-               perror("sendmsg");
+               /*
+                * Only warn about EPIPE when quiet mode is deactivated.
+                * We consider EPIPE as expected.
+                */
+               if (errno != EPIPE || !lttng_opt_quiet) {
+                       PERROR("sendmsg");
+               }
        }
-
        return ret;
 }
 
@@ -472,14 +512,16 @@ ssize_t lttcomm_send_creds_unix_sock(int sock, void *buf, size_t len)
  * Returns the size of received data, or negative error value.
  */
 ssize_t lttcomm_recv_creds_unix_sock(int sock, void *buf, size_t len,
-               struct ucred *creds)
+               lttng_sock_cred *creds)
 {
        struct msghdr msg;
-       struct cmsghdr *cmptr;
        struct iovec iov[1];
        ssize_t ret;
-       size_t sizeof_cred = sizeof(struct ucred);
+#ifdef __linux__
+       struct cmsghdr *cmptr;
+       size_t sizeof_cred = sizeof(lttng_sock_cred);
        char anc_buf[CMSG_SPACE(sizeof_cred)];
+#endif /* __linux__ */
 
        memset(&msg, 0, sizeof(msg));
 
@@ -495,15 +537,20 @@ ssize_t lttcomm_recv_creds_unix_sock(int sock, void *buf, size_t len,
        msg.msg_iov = iov;
        msg.msg_iovlen = 1;
 
+#ifdef __linux__
        msg.msg_control = anc_buf;
        msg.msg_controllen = sizeof(anc_buf);
+#endif /* __linux__ */
 
-       ret = recvmsg(sock, &msg, 0);
+       do {
+               ret = recvmsg(sock, &msg, 0);
+       } while (ret < 0 && errno == EINTR);
        if (ret < 0) {
-               perror("recvmsg fds");
+               PERROR("recvmsg fds");
                goto end;
        }
 
+#ifdef __linux__
        if (msg.msg_flags & MSG_CTRUNC) {
                fprintf(stderr, "Error: Control message truncated.\n");
                ret = -1;
@@ -518,7 +565,7 @@ ssize_t lttcomm_recv_creds_unix_sock(int sock, void *buf, size_t len,
        }
 
        if (cmptr->cmsg_level != SOL_SOCKET ||
-                       cmptr->cmsg_type != SCM_CREDENTIALS) {
+                       cmptr->cmsg_type != LTTNG_SOCK_CREDS) {
                fprintf(stderr, "Didn't received any credentials\n");
                ret = -1;
                goto end;
@@ -526,12 +573,24 @@ ssize_t lttcomm_recv_creds_unix_sock(int sock, void *buf, size_t len,
 
        if (cmptr->cmsg_len != CMSG_LEN(sizeof_cred)) {
                fprintf(stderr, "Error: Received %zu bytes of ancillary data, expected %zu\n",
-                               cmptr->cmsg_len, CMSG_LEN(sizeof_cred));
+                               (size_t) cmptr->cmsg_len, (size_t) CMSG_LEN(sizeof_cred));
                ret = -1;
                goto end;
        }
 
        memcpy(creds, CMSG_DATA(cmptr), sizeof_cred);
+#elif defined(__FreeBSD__)
+       {
+               int peer_ret;
+
+               peer_ret = getpeereid(sock, &creds->uid, &creds->gid);
+               if (peer_ret != 0) {
+                       return peer_ret;
+               }
+       }
+#else
+#error "Please implement credential support for your OS."
+#endif /* __linux__ */
 
 end:
        return ret;
@@ -540,6 +599,7 @@ end:
 /*
  * Set socket option to use credentials passing.
  */
+#ifdef __linux__
 int lttcomm_setsockopt_creds_unix_sock(int sock)
 {
        int ret, on = 1;
@@ -547,8 +607,15 @@ int lttcomm_setsockopt_creds_unix_sock(int sock)
        /* Set socket for credentials retrieval */
        ret = setsockopt(sock, SOL_SOCKET, SO_PASSCRED, &on, sizeof(on));
        if (ret < 0) {
-               perror("setsockopt creds unix sock");
+               PERROR("setsockopt creds unix sock");
        }
-
        return ret;
 }
+#elif defined(__FreeBSD__)
+int lttcomm_setsockopt_creds_unix_sock(int sock)
+{
+       return 0;
+}
+#else
+#error "Please implement credential support for your OS."
+#endif /* __linux__ */
index 31b7fe4661cbd1db37acb52013d31048b873df2e..dbb744c0c1bfce51be428184e38176b1251dee01 100644 (file)
@@ -3,18 +3,18 @@
  *                      Julien Desfossez <julien.desfossez@polymtl.ca>
  *                      Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; only version 2 of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  * 
  * This program 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 General Public License for
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  * more details.
  * 
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place - Suite 330, Boston, MA 02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 /*
@@ -28,7 +28,7 @@
 #define _GNU_SOURCE
 #include <limits.h>
 #include <lttng/lttng.h>
-#include <sys/socket.h>
+#include <common/compat/socket.h>
 
 /* Queue size of listen(2) */
 #define LTTNG_SESSIOND_COMM_MAX_LISTEN 64
@@ -68,7 +68,7 @@ enum lttcomm_sessiond_command {
  * lttcomm error code.
  */
 enum lttcomm_return_code {
-       LTTCOMM_OK = 1000,                              /* Ok */
+       LTTCOMM_OK = 10,                                /* Ok */
        LTTCOMM_ERR,                                    /* Unknown Error */
        LTTCOMM_UND,                                    /* Undefine command */
        LTTCOMM_NOT_IMPLEMENTED,        /* Command not implemented */
@@ -95,6 +95,7 @@ enum lttcomm_return_code {
        LTTCOMM_KERN_VERSION,           /* Kernel tracer version is not compatible */
        LTTCOMM_KERN_EVENT_EXIST,       /* Kernel event already exists */
        LTTCOMM_KERN_SESS_FAIL,                 /* Kernel create session failed */
+       LTTCOMM_KERN_CHAN_EXIST,        /* Kernel channel already exists */
        LTTCOMM_KERN_CHAN_FAIL,                 /* Kernel create channel failed */
        LTTCOMM_KERN_CHAN_NOT_FOUND,    /* Kernel channel not found */
        LTTCOMM_KERN_CHAN_DISABLE_FAIL, /* Kernel disable channel failed */
@@ -136,6 +137,9 @@ enum lttcomm_return_code {
        LTTCOMM_UST_EVENT_NOT_FOUND,    /* UST event not found */
        LTTCOMM_UST_CONTEXT_EXIST,      /* UST context exist */
        LTTCOMM_UST_CONTEXT_INVAL,      /* UST context invalid */
+       LTTCOMM_NEED_ROOT_SESSIOND,             /* root sessiond is needed */
+       LTTCOMM_TRACE_ALREADY_STARTED,  /* Tracing already started */
+       LTTCOMM_TRACE_ALREADY_STOPPED,  /* Tracing already stopped */
 
        CONSUMERD_COMMAND_SOCK_READY,           /* when consumerd command socket ready */
        CONSUMERD_SUCCESS_RECV_FD,              /* success on receiving fds */
@@ -151,6 +155,8 @@ enum lttcomm_return_code {
        CONSUMERD_SPLICE_EINVAL,                /* EINVAL from splice(2) */
        CONSUMERD_SPLICE_ENOMEM,                /* ENOMEM from splice(2) */
        CONSUMERD_SPLICE_ESPIPE,                /* ESPIPE from splice(2) */
+       LTTCOMM_INVALID,                        /* Invalid parameter */
+
        /* MUST be last element */
        LTTCOMM_NR,                                             /* Last element */
 };
@@ -291,7 +297,7 @@ extern ssize_t lttcomm_send_unix_sock(int sock, void *buf, size_t len);
 
 extern ssize_t lttcomm_send_creds_unix_sock(int sock, void *buf, size_t len);
 extern ssize_t lttcomm_recv_creds_unix_sock(int sock, void *buf, size_t len,
-               struct ucred *creds);
+               lttng_sock_cred *creds);
 
 extern const char *lttcomm_get_readable_code(enum lttcomm_return_code code);
 extern int lttcomm_setsockopt_creds_unix_sock(int sock);
index 5f5e9582574011577297bf36123a64958a752793..bfdb7e968fe9aa77ba9ad922e8fb6bf8748f4353 100644 (file)
@@ -2,36 +2,36 @@
  * Copyright (C) 2011 - Julien Desfossez <julien.desfossez@polymtl.ca>
  *                      Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; only version 2
- * of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
  * This program 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 General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #define _GNU_SOURCE
 #include <assert.h>
-#include <fcntl.h>
 #include <poll.h>
 #include <pthread.h>
 #include <stdlib.h>
 #include <string.h>
 #include <sys/mman.h>
 #include <sys/socket.h>
+#include <sys/stat.h>
 #include <sys/types.h>
 #include <unistd.h>
 #include <lttng/ust-ctl.h>
 
 #include <common/common.h>
 #include <common/sessiond-comm/sessiond-comm.h>
+#include <common/compat/fcntl.h>
 
 #include "ust-consumer.h"
 
@@ -42,9 +42,9 @@ extern volatile int consumer_quit;
 /*
  * Mmap the ring buffer, read it and write the data to the tracefile.
  *
- * Returns the number of bytes written
+ * Returns the number of bytes written, else negative value on error.
  */
-int lttng_ustconsumer_on_read_subbuffer_mmap(
+ssize_t lttng_ustconsumer_on_read_subbuffer_mmap(
                struct lttng_consumer_local_data *ctx,
                struct lttng_consumer_stream *stream, unsigned long len)
 {
@@ -57,8 +57,8 @@ int lttng_ustconsumer_on_read_subbuffer_mmap(
        ret = ustctl_get_mmap_read_offset(stream->chan->handle,
                stream->buf, &mmap_offset);
        if (ret != 0) {
-               ret = -errno;
-               perror("ustctl_get_mmap_read_offset");
+               errno = -ret;
+               PERROR("ustctl_get_mmap_read_offset");
                goto end;
        }
        while (len > 0) {
@@ -66,12 +66,12 @@ int lttng_ustconsumer_on_read_subbuffer_mmap(
                if (ret >= len) {
                        len = 0;
                } else if (ret < 0) {
-                       ret = -errno;
-                       perror("Error in file write");
+                       errno = -ret;
+                       PERROR("Error in file write");
                        goto end;
                }
                /* This won't block, but will start writeout asynchronously */
-               sync_file_range(outfd, stream->out_fd_offset, ret,
+               lttng_sync_file_range(outfd, stream->out_fd_offset, ret,
                                SYNC_FILE_RANGE_WRITE);
                stream->out_fd_offset += ret;
        }
@@ -89,7 +89,7 @@ end:
  *
  * Returns the number of bytes spliced.
  */
-int lttng_ustconsumer_on_read_subbuffer_splice(
+ssize_t lttng_ustconsumer_on_read_subbuffer_splice(
                struct lttng_consumer_local_data *ctx,
                struct lttng_consumer_stream *stream, unsigned long len)
 {
@@ -108,8 +108,8 @@ int lttng_ustconsumer_take_snapshot(struct lttng_consumer_local_data *ctx,
 
        ret = ustctl_snapshot(stream->chan->handle, stream->buf);
        if (ret != 0) {
-               ret = errno;
-               perror("Getting sub-buffer snapshot.");
+               errno = -ret;
+               PERROR("Getting sub-buffer snapshot.");
        }
 
        return ret;
@@ -130,8 +130,8 @@ int lttng_ustconsumer_get_produced_snapshot(
        ret = ustctl_snapshot_get_produced(stream->chan->handle,
                        stream->buf, pos);
        if (ret != 0) {
-               ret = errno;
-               perror("kernctl_snapshot_get_produced");
+               errno = -ret;
+               PERROR("kernctl_snapshot_get_produced");
        }
 
        return ret;
@@ -260,7 +260,7 @@ end:
        /* signal the poll thread */
        ret = write(ctx->consumer_poll_pipe[1], "4", 1);
        if (ret < 0) {
-               perror("write consumer poll");
+               PERROR("write consumer poll");
        }
 end_nosignal:
        return 0;
@@ -346,7 +346,7 @@ int lttng_ustconsumer_read_subbuffer(struct lttng_consumer_stream *stream,
        if (!stream->hangup_flush_done) {
                do {
                        readlen = read(stream->wait_fd, &dummy, 1);
-               } while (readlen == -1 && errno == -EINTR);
+               } while (readlen == -1 && errno == EINTR);
                if (readlen == -1) {
                        ret = readlen;
                        goto end;
@@ -400,7 +400,7 @@ int lttng_ustconsumer_on_recv_stream(struct lttng_consumer_stream *stream)
                                stream->uid, stream->gid);
                if (ret < 0) {
                        ERR("Opening %s", stream->path_name);
-                       perror("open");
+                       PERROR("open");
                        goto error;
                }
                stream->out_fd = ret;
index 76b4eeece093b5804bfe51e4e33a0928a9370649..c07377f8ea38711cfbd72951982ff173640ff683 100644 (file)
@@ -2,19 +2,18 @@
  * Copyright (C) 2011 - Julien Desfossez <julien.desfossez@polymtl.ca>
  * Copyright (C) 2011 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; only version 2
- * of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
  * This program 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
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #ifndef _LTTNG_USTCONSUMER_H
 /*
  * Mmap the ring buffer, read it and write the data to the tracefile.
  *
- * Returns the number of bytes written.
+ * Returns the number of bytes written, else negative value on error.
  */
-extern int lttng_ustconsumer_on_read_subbuffer_mmap(
+extern ssize_t lttng_ustconsumer_on_read_subbuffer_mmap(
                struct lttng_consumer_local_data *ctx,
                struct lttng_consumer_stream *stream, unsigned long len);
 
 /* Not implemented */
-extern int lttng_ustconsumer_on_read_subbuffer_splice(
+extern ssize_t lttng_ustconsumer_on_read_subbuffer_splice(
                struct lttng_consumer_local_data *ctx,
                struct lttng_consumer_stream *stream, unsigned long len);
 
@@ -76,7 +75,7 @@ void lttng_ustconsumer_on_stream_hangup(struct lttng_consumer_stream *stream);
 #else /* HAVE_LIBLTTNG_UST_CTL */
 
 static inline
-int lttng_ustconsumer_on_read_subbuffer_mmap(
+ssize_t lttng_ustconsumer_on_read_subbuffer_mmap(
                struct lttng_consumer_local_data *ctx,
                struct lttng_consumer_stream *stream, unsigned long len)
 {
@@ -84,7 +83,7 @@ int lttng_ustconsumer_on_read_subbuffer_mmap(
 }
 
 static inline
-int lttng_ustconsumer_on_read_subbuffer_splice(
+ssize_t lttng_ustconsumer_on_read_subbuffer_splice(
                struct lttng_consumer_local_data *ctx,
                struct lttng_consumer_stream *uststream, unsigned long len)
 {
index dafe085dc9bc40b81f53a35b13fbc6791969492f..36069ef2816b7906bb9f19a8c0714912a8061f31 100644 (file)
@@ -5,19 +5,18 @@
  *
  * Copyright (C) 2011 David Goulet <david.goulet@polymtl.ca>
  *
- * 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; only
- * version 2.1 of the License.
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License, version 2.1 only,
+ * as published by the Free Software Foundation.
  *
  * 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
+ * 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
  */
 
 #define _GNU_SOURCE
@@ -41,6 +40,18 @@ static char sessiond_sock_path[PATH_MAX];
 static char *tracing_group;
 static int connected;
 
+/* Global */
+
+/*
+ * Those two variables are used by error.h to silent or control the verbosity of
+ * error message. They are global to the library so application linking with it
+ * are able to compile correctly and also control verbosity of the library.
+ *
+ * Note that it is *not* possible to silent ERR() and PERROR() macros.
+ */
+int lttng_opt_quiet;
+int lttng_opt_verbose;
+
 /*
  * Copy string from src to dst and enforce null terminated byte.
  */
@@ -138,11 +149,8 @@ static int check_tracing_group(const char *grp_name)
 
        /* Get GID of group 'tracing' */
        grp_tracing = getgrnam(grp_name);
-       if (grp_tracing == NULL) {
-               /* NULL means not found also. getgrnam(3) */
-               if (errno != 0) {
-                       perror("getgrnam");
-               }
+       if (!grp_tracing) {
+               /* If grp_tracing is NULL, the group does not exist. */
                goto end;
        }
 
index 1dd8bbea7b5e3d27671c3bec78e8cd53f0acb03d..8dd05a4f0cfb646fdf6cc590a7229fdddeaa3df5 100644 (file)
@@ -1,6 +1,7 @@
 SUBDIRS = .
 
-AM_CFLAGS=-g -Wall -lurcu -lurcu-cds
+AM_CFLAGS = -g -Wall
+AM_LDFLAGS = -lurcu -lurcu-cds
 
 EXTRA_DIST = runall.sh utils.sh lttng/runall.sh lttng/run-kernel-tests.sh
 
index f556db4fc2afbb796eac6f0245648a8fef0d4bc9..6964a6f97035a81495a0591527e151ef27fc6a90 100644 (file)
@@ -29,6 +29,8 @@
 
 #include "../utils.h"
 
+int lttng_opt_quiet;
+
 int main(int argc, char **argv)
 {
        struct lttng_handle *handle = NULL;
index 36eb039214b0c918e4dd969d1ce51ed2c3ae3057..0af797c054fc0dadc9f6ad50fde5283e45a12c60 100644 (file)
@@ -29,6 +29,8 @@
 
 #include "../utils.h"
 
+int lttng_opt_quiet;
+
 int main(int argc, char **argv)
 {
        struct lttng_handle *handle = NULL;
index 9feaa30575d9accd7bf1aa823db40a5f71a36fb3..03363a86b523dd21203ca35c1847625ba2cd0e98 100644 (file)
@@ -29,6 +29,8 @@
 
 #include "../utils.h"
 
+int lttng_opt_quiet;
+
 int main(int argc, char **argv)
 {
        struct lttng_handle *handle = NULL;
index 867e4391b811b208b425f37d78d15d52430e455b..24dcec53d9d473f9b34f6491dc39fc521aeccabf 100644 (file)
@@ -29,6 +29,8 @@
 
 #include "../utils.h"
 
+int lttng_opt_quiet;
+
 int main(int argc, char **argv)
 {
        struct lttng_handle *handle = NULL;
index 0a534699c5444552669f7c0d9043a528d6579949..6d7f291beefbf56217ce36bbed30fdc6ec195f54 100644 (file)
@@ -36,8 +36,8 @@
 #define RANDOM_STRING_LEN      11
 
 /* For lttngerr.h */
-int opt_quiet = 1;
-int opt_verbose = 0;
+int lttng_opt_quiet = 1;
+int lttng_opt_verbose;
 
 static const char alphanum[] =
        "0123456789"
@@ -72,13 +72,13 @@ static void create_one_kernel_session(void)
        PRINT_OK();
 
        printf("Validating kernel session: ");
-       assert(kern->fd == 0);
-       assert(kern->metadata_stream_fd == 0);
+       assert(kern->fd == -1);
+       assert(kern->metadata_stream_fd == -1);
        assert(kern->consumer_fds_sent == 0);
        assert(kern->channel_count == 0);
        assert(kern->stream_count_global == 0);
        assert(kern->metadata == NULL);
-       assert(kern->consumer_fd == 0);
+       assert(kern->consumer_fd == -1);
        PRINT_OK();
 
        /* Init list in order to avoid sefaults from cds_list_del */
@@ -95,7 +95,7 @@ static void create_kernel_metadata(void)
        PRINT_OK();
 
        printf("Validating kernel session metadata: ");
-       assert(kern->metadata->fd == 0);
+       assert(kern->metadata->fd == -1);
        assert(strlen(kern->metadata->pathname));
        assert(kern->metadata->conf != NULL);
        assert(kern->metadata->conf->attr.overwrite
@@ -128,7 +128,7 @@ static void create_kernel_channel(void)
        PRINT_OK();
 
        printf("Validating kernel channel: ");
-       assert(chan->fd == 0);
+       assert(chan->fd == -1);
        assert(chan->enabled == 1);
        assert(strcmp(PATH1, chan->pathname) == 0);
        assert(chan->stream_count == 0);
@@ -157,7 +157,7 @@ static void create_kernel_event(void)
        PRINT_OK();
 
        printf("Validating kernel event: ");
-       assert(event->fd == 0);
+       assert(event->fd == -1);
        assert(event->enabled == 1);
        assert(event->ctx == NULL);
        assert(event->event->instrumentation == LTTNG_KERNEL_TRACEPOINT);
@@ -179,7 +179,7 @@ static void create_kernel_stream(void)
        PRINT_OK();
 
        printf("Validating kernel stream: ");
-       assert(stream->fd == 0);
+       assert(stream->fd == -1);
        assert(stream->pathname == NULL);
        assert(stream->state == 0);
        PRINT_OK();
index 5134f0b38cc4fda11bd854ea56691b496f456cc2..e55593561891d2827ba8cb8761e188e31c1d3e92 100644 (file)
@@ -55,8 +55,8 @@
 static struct ltt_session_list *session_list;
 
 /* For lttngerr.h */
-int opt_quiet = 1;
-int opt_verbose = 0;
+int lttng_opt_quiet = 1;
+int lttng_opt_verbose = 0;
 
 static const char alphanum[] =
        "0123456789"
index 924cfe4b97f1fde75af52f075969280072eab932..459520db1e547e12fe988b5b5c5dc85d053b27f0 100644 (file)
@@ -38,8 +38,8 @@
 #define RANDOM_STRING_LEN      11
 
 /* For lttngerr.h */
-int opt_quiet = 1;
-int opt_verbose = 0;
+int lttng_opt_quiet = 1;
+int lttng_opt_verbose;
 
 static const char alphanum[] =
        "0123456789"
index 8b7a914ee617b6ad1498fb49ef0faac7a98da898..29652dcbbccb214a828eedc41214c8bd6baddb05 100644 (file)
@@ -1,5 +1,12 @@
 AM_CFLAGS = -I. -O2
-AM_LDFLAGS = -llttng-ust -ldl
+AM_LDFLAGS = -llttng-ust
+
+if LTTNG_TOOLS_BUILD_WITH_LIBDL
+AM_LDFLAGS += -ldl
+endif
+if LTTNG_TOOLS_BUILD_WITH_LIBC_DL
+AM_LDFLAGS += -lc
+endif
 
 noinst_PROGRAMS = gen-nevents
 gen_nevents_SOURCES = gen-nevents.c tp.c ust_gen_nevents.h
index 39168d6a2a72363829b98086dd8af93375b937ea..d3fdcbd4120cf5bdcf5c17250fbae09eabffd1dc 100644 (file)
@@ -1,5 +1,12 @@
 AM_CFLAGS = -I. -O2
-AM_LDFLAGS = -llttng-ust -ldl
+AM_LDFLAGS = -llttng-ust
+
+if LTTNG_TOOLS_BUILD_WITH_LIBDL
+AM_LDFLAGS += -ldl
+endif
+if LTTNG_TOOLS_BUILD_WITH_LIBC_DL
+AM_LDFLAGS += -lc
+endif
 
 noinst_PROGRAMS = gen-events-time
 gen_events_time_SOURCES = gen-events-time.c tp.c ust_gen_event.h
index 20f769afdefcec9facfe7a88ca56da5a00eefcec..cab42ef5cb28c458ed95ede066e6243babe6b0fb 100755 (executable)
@@ -43,7 +43,9 @@ do
        ./$CURDIR/$TEST_BIN_NAME 1000 >/dev/null 2>&1 &
 done
 
-echo -n "Validating registered apps: "
+echo -n "Validating registered apps in 3 seconds..."
+
+sleep 3
 
 listing=$($TESTDIR/../src/bin/lttng/$LTTNG_BIN list -u)
 reg_app_count=$(echo -n $listing | sed "s/$TEST_BIN_NAME/$TEST_BIN_NAME\n/g" | grep "$TEST_BIN_NAME" | wc -l)
@@ -61,6 +63,7 @@ enable_ust_lttng_event $SESSION_NAME $EVENT_NAME
 start_tracing $SESSION_NAME
 
 echo "Sleeping $TEST_WAIT_SEC seconds for tracing to start everywhere"
+echo "Warning: this arbitrary time can make the test fail on slower system"
 sleep $TEST_WAIT_SEC
 
 stop_tracing $SESSION_NAME
This page took 0.177542 seconds and 4 git commands to generate.