]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
getty-generator: show original path in the log message
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 18 Jul 2025 17:55:01 +0000 (02:55 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 22 Jul 2025 23:32:05 +0000 (08:32 +0900)
This fixes the following log message:
Before:
```
Invalid container tty device specified, ignoring: (null)
```
After:
```
Invalid container tty device specified, ignoring: /dev/tty0
```

If a non-pts device path is passed to add_container_getty(), we call
add_getty_impl() with NULL tty, so previously (null) was logged.
Let's log the original path when an invalid tty is specified.

src/getty-generator/getty-generator.c

index 810ee9a2f9f80e07e492743d9eb4f1f338f0b784..a4014a8b975d457f9f950d07a527a8879b167462 100644 (file)
 static const char *arg_dest = NULL;
 static bool arg_enabled = true;
 
-static int add_getty_impl(const char *tty, const char *type, const char *unit_path) {
+static int add_getty_impl(const char *tty, const char *path, const char *type, const char *unit_path) {
         int r;
 
         assert(type);
+        assert(path);
         assert(unit_path);
 
         if (!filename_is_valid(tty)) {
-                log_debug("Invalid %s tty device specified, ignoring: %s", type, tty);
+                log_debug("Invalid %s tty device specified, ignoring: %s", type, path);
                 return 0;
         }
 
@@ -45,17 +46,23 @@ static int add_getty_impl(const char *tty, const char *type, const char *unit_pa
         return generator_add_symlink_full(arg_dest, "getty.target", "wants", unit_path, instance);
 }
 
-static int add_serial_getty(const char *tty) {
-        tty = skip_dev_prefix(ASSERT_PTR(tty));
-        return add_getty_impl(tty, "serial", SYSTEM_DATA_UNIT_DIR "/serial-getty@.service");
+static int add_serial_getty(const char *path) {
+        const char *tty = skip_dev_prefix(ASSERT_PTR(path));
+        return add_getty_impl(tty, path, "serial", SYSTEM_DATA_UNIT_DIR "/serial-getty@.service");
 }
 
-static int add_container_getty(const char *tty) {
-        if (is_path(tty))
+static int add_container_getty(const char *tty_or_path) {
+        const char *tty;
+
+        assert(tty_or_path);
+
+        if (is_path(tty_or_path))
                 /* Check if it is actually a pty. */
-                tty = path_startswith(skip_dev_prefix(tty), "pts/");
+                tty = path_startswith(skip_dev_prefix(tty_or_path), "pts/");
+        else
+                tty = tty_or_path;
 
-        return add_getty_impl(tty, "container", SYSTEM_DATA_UNIT_DIR "/container-getty@.service");
+        return add_getty_impl(tty, tty_or_path, "container", SYSTEM_DATA_UNIT_DIR "/container-getty@.service");
 }
 
 static int verify_tty(const char *path) {