1
0
mirror of https://github.com/systemd/systemd synced 2026-03-16 01:54:45 +01:00

Compare commits

..

3 Commits

Author SHA1 Message Date
Peter Oliver
af718e0535
ansi-color: new option SYSTEMD_COLORS=auto-16/auto-256/auto-24bit (#40303)
Setting SYSTEMD_COLORS=auto-16 is like SYSTEMD_COLORS=16 if output is to
a non-dumb TTY, and like SYSTEMD_COLORS=no otherwise.

Relates to
https://github.com/systemd/systemd/issues/15498#issuecomment-1682025186
2026-01-23 13:54:31 +01:00
Lennart Poettering
fa41ce1142 hostnamed: after unescaping fancy name, validate it's valid UTF-8
The fancy name could contain arbitrary bytes, in escaped fashion. Before
using it, let's validate that this contains only valid UTF-8.

(Note that D-Bus might kick us off the bus if we don't ensure everything
we send around is UTF-8).

(While we are at it, do the same in PID 1, even though it's not that
important there)

Addresses this issue found by @YHNdnzj:

https://github.com/systemd/systemd/pull/40367#discussion_r2714614301

Follow-up for: #40367
2026-01-23 13:35:43 +01:00
Antonio Alvarez Feijoo
236033fd48 man/fstab-generator: correct root= options
Remove duplicate "fstab" option, and add missing "tmpfs" and "bind:" options.
2026-01-23 13:29:31 +01:00
8 changed files with 84 additions and 19 deletions

6
NEWS
View File

@ -31,6 +31,12 @@ CHANGES WITH 260 in spe:
rather than the first, to keep these options coherent with other
unit settings.
Changes in other components:
* New options SYSTEMD_COLORS=auto-16 and SYSTEMD_COLORS=auto-256, which
are like SYSTEMD_COLORS=16 and SYSTEMD_COLORS=256 respectively when
output is to a non-dumb TTY, and like SYSTEMD_COLORS=no otherwise.
CHANGES WITH 259:
Announcements of Future Feature Removals and Incompatible Changes:

View File

@ -224,11 +224,40 @@
<varlistentry id='colors'>
<term><varname>$SYSTEMD_COLORS</varname></term>
<listitem><para>Takes a boolean argument. When true, <command>systemd</command> and related utilities
will use colors in their output, otherwise the output will be monochrome. Additionally, the variable can
take one of the following special values: <literal>16</literal>, <literal>256</literal> to restrict the use
of colors to the base 16 or 256 ANSI colors, respectively. This can be specified to override the automatic
decision based on <varname>$TERM</varname> and what the console is connected to.</para></listitem>
<listitem>
<para>Takes a boolean argument, or a special value.</para>
<variablelist>
<varlistentry>
<term><option>true</option></term>
<listitem><para>The default. <command>systemd</command> and related utilities will use colors in
their output if possible. Same as <literal>auto-24bit</literal> if <varname>$COLORTERM</varname>
is set to <literal>truecolor</literal> or <literal>24bit</literal>; same as
<literal>auto-256</literal> otherwise.</para></listitem>
</varlistentry>
<varlistentry>
<term><option>false</option></term>
<listitem><para>The output will be monochrome.</para></listitem>
</varlistentry>
<varlistentry>
<term><literal>16</literal></term>
<term><literal>256</literal></term>
<term><literal>24bit</literal></term>
<listitem><para>Always use the base 16 ANSI colors, 256 colors, or 24 bit color,
respectively.</para></listitem>
</varlistentry>
<varlistentry>
<term><literal>auto-16</literal></term>
<term><literal>auto-256</literal></term>
<term><literal>auto-24bit</literal></term>
<listitem><para>Use the given quantity of colours, subject to <varname>$TERM</varname>, and what
the console is connected to.</para></listitem>
</varlistentry>
</variablelist>
</listitem>
</varlistentry>
<!-- This is not documented on purpose, because it is not clear if $NO_COLOR will become supported
@ -236,7 +265,8 @@
<varlistentry id='no-color'>
<term><varname>$NO_COLOR</varname></term>
<listitem><para>If set (to any value), and <varname>$SYSTEMD_COLORS</varname> is not set, equivalent to
<listitem><para>If set (to any value), and <varname>$SYSTEMD_COLORS</varname> is not set to
<literal>16</literal>, <literal>256</literal>, or <literal>24bit</literal>, equivalent to
<option>SYSTEMD_COLORS=0</option>. See <ulink url="https://no-color.org/">no-color.org</ulink>.</para>
</listitem>
</varlistentry>

View File

@ -85,8 +85,8 @@
initrd. This accepts a device node path (usually <filename>/dev/disk/by-uuid/…</filename> or
<filename>/dev/disk/by-label/…</filename> or similar), or the special values
<literal>gpt-auto</literal>, <literal>gpt-auto-force</literal>, <literal>dissect</literal>,
<literal>dissect-force</literal>, <literal>fstab</literal>, <literal>fstab</literal>, and
<literal>off</literal>.</para>
<literal>dissect-force</literal>, <literal>fstab</literal>, <literal>tmpfs</literal>,
<literal>bind:…</literal>, and <literal>off</literal>.</para>
<para>Set to <literal>gpt-auto</literal>, <literal>gpt-auto-force</literal>,
<literal>dissect</literal>, <literal>dissect-force</literal> to explicitly request automatic root

View File

@ -55,7 +55,7 @@ static ColorMode get_color_mode_impl(void) {
/* First, we check $SYSTEMD_COLORS, which is the explicit way to change the mode. */
ColorMode m = parse_systemd_colors();
if (m >= 0)
if (IN_SET(m, COLOR_OFF, COLOR_16, COLOR_256, COLOR_24BIT))
return m;
/* Next, check for the presence of $NO_COLOR; value is ignored. */
@ -70,6 +70,13 @@ static ColorMode get_color_mode_impl(void) {
return COLOR_OFF;
/* We failed to figure out any reason to *disable* colors. Let's see how many colors we shall use. */
if (m == COLOR_AUTO_16)
return COLOR_16;
if (m == COLOR_AUTO_256)
return COLOR_256;
if (m == COLOR_AUTO_24BIT)
return COLOR_24BIT;
if (STRPTR_IN_SET(getenv("COLORTERM"),
"truecolor",
"24bit"))
@ -97,6 +104,9 @@ static const char* const color_mode_table[_COLOR_MODE_MAX] = {
[COLOR_16] = "16",
[COLOR_256] = "256",
[COLOR_24BIT] = "24bit",
[COLOR_AUTO_16] = "auto-16",
[COLOR_AUTO_256] = "auto-256",
[COLOR_AUTO_24BIT] = "auto-24bit",
};
DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(color_mode, ColorMode, COLOR_24BIT);

View File

@ -9,6 +9,9 @@ typedef enum ColorMode {
COLOR_16, /* Only the base 16 colors. */
COLOR_256, /* Only 256 colors. */
COLOR_24BIT, /* For truecolor or 24bit color support, no restriction. */
COLOR_AUTO_16, /* The "AUTO" modes are as the above, but subject to suitable settings for */
COLOR_AUTO_256, /* the environment variables TERM and NO_COLOR. */
COLOR_AUTO_24BIT,
_COLOR_MODE_MAX,
_COLOR_MODE_INVALID = -EINVAL,
} ColorMode;

View File

@ -1422,6 +1422,9 @@ static int os_release_status(void) {
if (l < 0) {
log_debug_errno(l, "Failed to unescape FANCY_NAME=, ignoring: %m");
fancy_name = mfree(fancy_name);
} else if (!utf8_is_valid(fancy_name)) {
log_debug("Unescaped FANCY_NAME= contains invalid UTF-8, ignoring.");
fancy_name = mfree(fancy_name);
} else {
free_and_replace(fancy_name, unescaped);

View File

@ -238,6 +238,9 @@ static void context_read_os_release(Context *c) {
if (l < 0) {
log_warning_errno(l, "Failed to unescape fancy OS name, ignoring: %m");
os_fancy_name = mfree(os_fancy_name);
} else if (!utf8_is_valid(unescaped)) {
log_warning("Unescaped fancy OS name contains invalid UTF-8, ignoring.");
os_fancy_name = mfree(os_fancy_name);
} else
free_and_replace(os_fancy_name, unescaped);
}

View File

@ -336,7 +336,17 @@ TEST(get_color_mode) {
test_get_color_mode_with_env("SYSTEMD_COLORS", "yes", COLOR_24BIT);
test_get_color_mode_with_env("SYSTEMD_COLORS", "24bit", COLOR_24BIT);
test_get_color_mode_with_env("SYSTEMD_COLORS", "auto-16", terminal_is_dumb() ? COLOR_OFF : COLOR_16);
test_get_color_mode_with_env("SYSTEMD_COLORS", "auto-256", terminal_is_dumb() ? COLOR_OFF : COLOR_256);
ASSERT_OK_ERRNO(setenv("COLORTERM", "truecolor", true));
test_get_color_mode_with_env("SYSTEMD_COLORS", "auto-24bit", terminal_is_dumb() ? COLOR_OFF : COLOR_24BIT);
ASSERT_OK_ERRNO(unsetenv("COLORTERM"));
test_get_color_mode_with_env("SYSTEMD_COLORS", "auto-24bit", terminal_is_dumb() ? COLOR_OFF : COLOR_256);
ASSERT_OK_ERRNO(setenv("NO_COLOR", "1", true));
test_get_color_mode_with_env("SYSTEMD_COLORS", "auto-16", COLOR_OFF);
test_get_color_mode_with_env("SYSTEMD_COLORS", "auto-256", COLOR_OFF);
test_get_color_mode_with_env("SYSTEMD_COLORS", "auto-24bit", COLOR_OFF);
test_get_color_mode_with_env("SYSTEMD_COLORS", "42", COLOR_OFF);
test_get_color_mode_with_env("SYSTEMD_COLORS", "invalid", COLOR_OFF);
ASSERT_OK_ERRNO(unsetenv("NO_COLOR"));