void termios_disable_echo(struct termios *termios);
+/* The $TERM value we use for terminals other than the Linux console */
+#define FALLBACK_TERM "vt220"
+
int get_default_background_color(double *ret_red, double *ret_green, double *ret_blue);
int terminal_get_size_by_dsr(int input_fd, int output_fd, unsigned *ret_rows, unsigned *ret_columns);
int terminal_fix_size(int input_fd, int output_fd);
}
if (exec_context_needs_term(c)) {
- _cleanup_free_ char *cmdline = NULL;
+ _cleanup_free_ char *cmdline = NULL, *dcs_term = NULL;
const char *tty_path, *term = NULL;
tty_path = exec_context_tty_path(c);
term = cmdline;
}
+ if (!term && tty_path) {
+ /* This handles real virtual terminals (returning "linux") and
+ * any terminals which support the DCS +q query sequence. */
+ r = query_term_for_tty(tty_path, &dcs_term);
+ if (r >= 0)
+ term = dcs_term;
+ }
+
if (!term) {
- /* If no precise $TERM is known and we pick a fallback default, then let's also set
+ /* If $TERM is not known and we pick a fallback default, then let's also set
* $COLORTERM=truecolor. That's because our fallback default is vt220, which is
* generally a safe bet (as it supports PageUp/PageDown unlike vt100, and is quite
* universally available in terminfo/termcap), except for the fact that real DEC
our_env[n_env++] = x;
- term = default_term_for_tty(tty_path);
+ term = FALLBACK_TERM;
}
x = strjoin("TERM=", term);
return r;
}
- const char *t = term ?: default_term_for_tty("/dev/console");
- if (setenv("TERM", t, /* overwrite= */ true) < 0)
+ if (!term)
+ (void) query_term_for_tty("/dev/console", &term);
+
+ if (setenv("TERM", term ?: FALLBACK_TERM, /* overwrite= */ true) < 0)
return -errno;
/* The kernels sets HOME=/ for init. Let's undo this. */