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>
/* Init lttng session config */
ret = config_init(created_session_name);
if (ret < 0) {
- ret = CMD_ERROR;
+ MSG("Unable to initialize configuration for created session: future commands will require the target session name explicitly");
+ ret = CMD_WARNING;
goto error;
}
fp = fopen(file_path, mode);
if (fp == nullptr) {
+ PWARN("Failed to open configuration file '%s'", file_path);
goto error;
}
fp = open_config(path, "w+");
if (fp == nullptr) {
- ERR("Unable to create config file");
ret = -1;
goto error;
}