lttng: Indicate file path and error reason when open_config fails
authorKienan Stewart <kstewart@efficios.com>
Mon, 15 Apr 2024 19:15:28 +0000 (15:15 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 24 May 2024 15:24:14 +0000 (11:24 -0400)
commitdcffe9462d11f9de5b441b801da5b2b7ae42c79a
treefcf6fdc4dfb43c1117323b1c14b5a76b36686344
parentac559d09a23994f9f52014b0efba3a3c566dcfea
lttng: Indicate file path and error reason when open_config fails

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

In a test environment where the configuration file had been chowned to
no longer be writeable by the current user, `lttng` commands would work
but return a non-zero exit code and print `Error: Unable to create
config file`.

This doesn't give the user much information to work with to address the
issue.

Solution
========

The `PWARN` macro is used to print the file_path and reason when the
call to `fopen` fails.

This is done since the `file_path` percolated up to where the existing
error message is may be null for multiple reasons (eg. allocation
failure).

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

The output of `PWARN` is inconsistent with the output used for most of
the `lttng` client.

Eg.

```
$ lttng create
Spawning a session daemon
Session auto-20240415-151450 created.
Traces will be output to /home/lttng-traces/auto-20240415-151450
PWARN - 15:14:50.420628389 [1184515/1184515]: fopen '/home/.lttngrc': Permission denied (in open_config() at conf.cpp:57)
Error: Unable to create config file
```

Change-Id: I5a9253fb02f3a712e7c5c2567311920dc33d36c7
Signed-off-by: Kienan Stewart <kstewart@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/bin/lttng/commands/create.cpp
src/bin/lttng/conf.cpp
This page took 0.02692 seconds and 4 git commands to generate.