Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(network-manager): disable tty output if the console is not usable #1611

Merged
merged 2 commits into from
Oct 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions modules.d/35network-manager/nm-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@ if getargbool 0 rd.debug -d -y rdinitdebug -d -y rdnetdebug; then
echo '[logging]'
echo 'level=TRACE'
) > /run/NetworkManager/conf.d/initrd-logging.conf

if [ -n "$DRACUT_SYSTEMD" ]; then
# Enable tty output if a usable console is found
# See https://github.com/coreos/fedora-coreos-tracker/issues/943
# shellcheck disable=SC2217
if [ -w /dev/console ] && (echo < /dev/console) > /dev/null 2> /dev/null; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume echo < /dev/console is a test and will fail if the console doesn't work? It seems weird to me to send anything to stdin of echo since it doesn't do anything with it. cat does.

Also:

Suggested change
if [ -w /dev/console ] && (echo < /dev/console) > /dev/null 2> /dev/null; then
if [ -w /dev/console ] && (echo < /dev/console) &> /dev/null; then

I think this is equivalent with less characters.

Copy link
Contributor Author

@bengal bengal Oct 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume echo < /dev/console is a test and will fail if the console doesn't work? It seems weird to me to send anything to stdin of echo since it doesn't do anything with it. cat does.

I copied this code from https://github.com/dracutdevs/dracut/blob/055/modules.d/99shutdown/shutdown.sh#L15

The idea is to try to open the console via shell redirection, but don't actually read or write anything from/to it. If /dev/console can't be opened, the command returns a non-zero value which is interpreted as false.

I think this is equivalent with less characters.

The interpreter of this script is /bin/sh, so it must be POSIX compatible.
&> is a bashism and is not POSIX.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the reply/explanation.

mkdir -p /run/systemd/system/nm-initrd.service.d
cat << EOF > /run/systemd/system/nm-initrd.service.d/tty-output.conf
[Service]
StandardOutput=tty
EOF
systemctl --no-block daemon-reload
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any implications of running this daemon-reload here? If we ran this as part of a systemd generator would we need to do the daemon-reload?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not aware of any side effect of calling daemon-reload here.

A generator would be an alternative and wouldn't require a daemon-reload; I think it requires to ship new service and a script. I like how the current code is self-contained, but I have no objections in turning it into a generator if that's the general consensus.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lucab - any thoughts here on the tradeoffs?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, reloading in the middle of a boot isn't the nicest, a generator would be advisable.
I don't think it directly breaks anything so not strictly a problem, but may trigger some unexpected second-order effects.
For reference, I see there are some dracut modules already shipping a generator in this repository, like modules.d/95nbd/.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree a generator would be slightly cleaner and would make a good follow-up, but if this is already tested IMO it's not worth the respin.

fi
fi
fi

nm_generate_connections
4 changes: 3 additions & 1 deletion modules.d/35network-manager/nm-initrd.service
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ BusName=org.freedesktop.NetworkManager
ExecReload=/usr/bin/busctl call org.freedesktop.NetworkManager /org/freedesktop/NetworkManager org.freedesktop.NetworkManager Reload u 0
ExecStart=/usr/sbin/NetworkManager --debug
KillMode=process
StandardOutput=tty
# The following gets changed to StandardOutput=tty by nm-config.sh
# when debug is enabled and a usable console is found.
StandardOutput=null
Environment=NM_CONFIG_ENABLE_TAG=initrd
Restart=on-failure
ProtectSystem=true
Expand Down