sessiond/lttng-ctl: Introduce LTTNG_RUNDIR
authorKienan Stewart <kstewart@efficios.com>
Thu, 18 Apr 2024 20:35:40 +0000 (16:35 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 31 Oct 2024 16:06:08 +0000 (12:06 -0400)
commit1fa11e2f48f15ba299133841d28a59662f61bb75
treed96d0d5de10f449784144b79f3dff196c5af77e4
parent11ababaeaf2a133ea263041cb254e2a272a8f893
sessiond/lttng-ctl: Introduce LTTNG_RUNDIR

Observed issue
==============

Starting multiple instances of lttng-sessiond as the root user isn't
possible, even with setting different values for the `LTTNG_HOME`
environment variable.

Cause
=====

When starting `lttng-sessiond` the `apps_unix_sock_path`,
`client_unix_sock_path`, and `health_unix_sock_path` are set to
configure time static defines under `CONFIG_LTTNG_SYSTEM_RUNDIR`,
e.g. `/var/lib/lttng`.

Solution
========

A new environment variable `LTTNG_RUNDIR` is introduced to control the
base directory used by applications to find communication sockets.

The default behaviour is to emulate the existing divide: if
`LTTNG_RUNDIR` is not set the root `lttng-sessiond` will continue to
use `CONFIG_LTTNG_SYSTEM_RUNDIR`, and a non-root user `lttng-sessiond`
will use `LTTNG_HOME/.lttng`.

When `LTTNG_RUNDIR` is set, it takes priority over `LTTNG_HOME` for
determining the base directory. The output directory for traces is
not affected by `LTTNG_RUNDIR`, it continues to respect `LTTNG_HOME`.

Example with starting multiple root `lttng-sessiond`s:

```
DIR_A=$(mktemp -d)
DIR_B=$(mktemp -d)

LTTNG_RUNDIR="${DIR_A}" lttng-sessiond -b
LTTNG_RUNDIR="${DIR_B}" lttng-sessiond -b

LTTNG_RUNDIR="${DIR_A}" lttng list

LTTNG_RUNDIR="${DIR_B}" lttng list
```

In the example above, as `LTTNG_HOME` is not set, the default output
directory for traces by both over the `lttng-sessiond` instances will
be `$HOME/lttng-traces`.

The following will also work:

```
DIR_A=$(mktemp -d)
LTTNG_RUNDIR="${DIR_A}" lttng create
LTTNG_RUNDIR="${DIR_A}" lttng enable-event -u --all
LTTNG_RUNDIR="${DIR_A}" lttng start

LTTNG_UST_APP_PATH="${DIR_A}" test-application
```

The `LTTNG_UST_CTL_PATH` can be set to a location other than the
rundir as follows;

```
DIR_A=$(mktemp -d)
DIR_B=$(mktemp -d)
LTTNG_UST_CTL_PATH="${DIR_B}" LTTNG_RUNDIR="${DIR_A}" lttng create
LTTNG_RUNDIR="${DIR_A}" lttng enable-event -u -all
LTTNG_RUNDIR="${DIR_A}" lttng start

LTTNG_UST_APP_PATH="${DIR_B}" test-application

LTTNG_UST_APP_PATH="${DIR_A}" test-application
```

Known drawbacks
===============

None.

Change-Id: I371c2c72644277b7dcafaf970ee7b75d9bfbaedc
Signed-off-by: Kienan Stewart <kstewart@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
22 files changed:
doc/man/lttng-sessiond.8.txt
src/bin/lttng-consumerd/health-consumerd.cpp
src/bin/lttng-relayd/health-relayd.cpp
src/bin/lttng-sessiond/client.cpp
src/bin/lttng-sessiond/main.cpp
src/bin/lttng-sessiond/notification-thread.cpp
src/bin/lttng-sessiond/sessiond-config.cpp
src/common/config/session-config.cpp
src/common/consumer/consumer.hpp
src/common/defaults.hpp
src/common/exception.cpp
src/common/exception.hpp
src/common/format.hpp
src/common/utils.cpp
src/common/utils.hpp
src/lib/lttng-ctl/channel.cpp
src/lib/lttng-ctl/lttng-ctl-health.cpp
src/lib/lttng-ctl/lttng-ctl.cpp
tests/regression/tools/config-directory/test_config.py.in
tests/regression/ust/ust-app-ctl-paths/test_blocking
tests/regression/ust/ust-app-ctl-paths/test_ust_app_ctl_paths
tests/utils/lttngtest/lttng.py
This page took 0.030029 seconds and 4 git commands to generate.