]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
machinectl: set TERM=dumb when running on a dumb terminal or with a pipe
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 11 Aug 2025 06:58:31 +0000 (15:58 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 13 Aug 2025 14:43:51 +0000 (23:43 +0900)
Fixes #38527.

src/machine/machinectl.c

index 4e3138b2ff152455dcc4ac26af072c2ac39187d6..fd37bde874a70f37165c92ffde89726f0b02e1e2 100644 (file)
@@ -1400,18 +1400,25 @@ static int shell_machine(int argc, char *argv[], void *userdata) {
                 return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
                                        "Shell only supported on local machines.");
 
-        /* Pass $TERM & Co. to shell session, if not explicitly specified. */
-        FOREACH_STRING(v, "TERM=", "COLORTERM=", "NO_COLOR=") {
-                if (strv_find_prefix(arg_setenv, v))
-                        continue;
+        if (terminal_is_dumb()) {
+                /* Set TERM=dumb if we are running on a dumb terminal or with a pipe.
+                 * Otherwise, we will get unwanted OSC sequences. */
+                if (!strv_find_prefix(arg_setenv, "TERM="))
+                        if (strv_extend(&arg_setenv, "TERM=dumb") < 0)
+                                return log_oom();
+        } else
+                /* Pass $TERM & Co. to shell session, if not explicitly specified. */
+                FOREACH_STRING(v, "TERM=", "COLORTERM=", "NO_COLOR=") {
+                        if (strv_find_prefix(arg_setenv, v))
+                                continue;
 
-                const char *t = strv_find_prefix(environ, v);
-                if (!t)
-                        continue;
+                        const char *t = strv_find_prefix(environ, v);
+                        if (!t)
+                                continue;
 
-                if (strv_extend(&arg_setenv, t) < 0)
-                        return log_oom();
-        }
+                        if (strv_extend(&arg_setenv, t) < 0)
+                                return log_oom();
+                }
 
         (void) polkit_agent_open_if_enabled(arg_transport, arg_ask_password);