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)
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

index dce13866f6dea7d2948149de093e49af65935bde..e1756c3d30a30c4449a641e5548391f58da9413e 100644 (file)
@@ -479,7 +479,8 @@ static int create_session(const char *session_name)
        /* 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;
        }
 
index 65be35a158f70518dda1317f78900347ba67b117..81aa654384c97bbccf0360be39d91a2e7326f230 100644 (file)
@@ -54,6 +54,7 @@ static FILE *open_config(const char *path, const char *mode)
 
        fp = fopen(file_path, mode);
        if (fp == nullptr) {
+               PWARN("Failed to open configuration file '%s'", file_path);
                goto error;
        }
 
@@ -74,7 +75,6 @@ static int create_config_file(const char *path)
 
        fp = open_config(path, "w+");
        if (fp == nullptr) {
-               ERR("Unable to create config file");
                ret = -1;
                goto error;
        }
This page took 0.053188 seconds and 4 git commands to generate.