Skip to content

Comments

Fix rc.log missing shutdown messages in some cases.#980

Open
e-pirate wants to merge 1 commit intoOpenRC:masterfrom
e-pirate:master
Open

Fix rc.log missing shutdown messages in some cases.#980
e-pirate wants to merge 1 commit intoOpenRC:masterfrom
e-pirate:master

Conversation

@e-pirate
Copy link

Fix rc.log missing shutdown messages if located on separate (non-root) file system by preventing localmount from unmouting this file system to early keeping rc.log file writible.

Closes: #977

file system by preventing localmount from unmouting this file system
to early keeping rc.log file writible.

Closes: OpenRC#977

if yesno ${rc_logger:-NO}; then
[ ! -f "${rc_log_path}" ] && touch "${rc_log_path}"
local rc_log_mntpnt=$(stat --format %m "${rc_log_path}")
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this portable? I haven't checked but mountinfo may have a way to return the mountpoint.

Copy link
Member

Choose a reason for hiding this comment

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

mountinfo does not, but adding such flag was what i was considering doing

don't think it can be done truly portably since posix doesn't specify mounting at all, so if stat -c %m exists on all our platforms, that's enough i think

Copy link
Contributor

Choose a reason for hiding this comment

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

Right, I don't mean portable as in POSIX, I mean in terms of whether BSDs and busybox/alpine support it or not.

Copy link
Author

Choose a reason for hiding this comment

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

Is this portable? I haven't checked but mountinfo may have a way to return the mountpoint.

I also took care about this. stat is a part of coreutils and should be available, unlike mountpoint that is part of sys-apps/util-linux.

Copy link
Contributor

Choose a reason for hiding this comment

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

Right, but (GNU) coreutils isn't used everywhere. BSDs don't use it, and even some linux distros such as alpine doesn't use it.

Looking at busybox's stat, I see that it supports -c but I can't find %m there, so it's likely not supported.

Copy link
Author

Choose a reason for hiding this comment

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

Right, but (GNU) coreutils isn't used everywhere. BSDs don't use it, and even some linux distros such as alpine doesn't use it.

Looking at busybox's stat, I see that it supports -c but I can't find %m there, so it's likely not supported.

I will ask an actual BSD user. If not supported, we may put this section inside the next block that works only for Linux.

Copy link
Contributor

Choose a reason for hiding this comment

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

we may put this section inside the next block that works only for Linux.

Except that linux != GNU coreutils. Alpine is linux. Alpine uses openrc. But it does NOT use GNU coreutils, it uses busybox.

The linux specific section below works because it's doing linux specific file system things. It doesn't make assumption about userland. Assuming linux kernel == GNU coreutils is not correct.

done

if yesno ${rc_logger:-NO}; then
[ ! -f "${rc_log_path}" ] && touch "${rc_log_path}"
Copy link
Member

Choose a reason for hiding this comment

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

if the logger is on, we'll always have the file by this point, so we might as well just check for it's existence directly i think

also rc_log_path isn't always set, it defaults to /var/log/rc.log if unset

Copy link
Author

@e-pirate e-pirate Feb 20, 2026

Choose a reason for hiding this comment

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

if the logger is on, we'll always have the file by this point, so we might as well just check for it's existence directly i think

also rc_log_path isn't always set, it defaults to /var/log/rc.log if unset

It is not the case as far as I can see. The rc.log file may present and the path is set by user but user may not enable logging (or disable it) and we should not bother at all in that cases. I believe we should attempt doing just anything only in case user deliberately enabled logging regardless path is set. I have to investigate it rc_log_path is available if not deliberately set and how to handle this case.

Copy link
Author

Choose a reason for hiding this comment

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

OK. that's pretty easy, just check if rc_log_path variable is set, if not, set to to default value = /var/log/rc.log, otherwise keep as is.

Copy link
Author

Choose a reason for hiding this comment

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

How do you like this implementation?
[ -z ${rc_log_path+x} ] && rc_log_path="/var/log/rc.log" just before checking for file existence?

Copy link
Member

Choose a reason for hiding this comment

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

you can instead, [ -f "${rc_log_path:=/var/log/rc.log}" ] to both check and assign if unset at once

Copy link
Author

Choose a reason for hiding this comment

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

@navi-desu we also may not have the file with logging enabled. If you enable logging for the first time during system is already running you will have rc_logger set to YES, but no file. There will be no file until next complete reboot.

Copy link
Member

@navi-desu navi-desu Feb 20, 2026

Choose a reason for hiding this comment

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

then check both, yesno "$rc_logger" && [ -f ... ]

@e-pirate
Copy link
Author

OK. this is a little bit more difficult as I expected. As expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

localmount unmount /var/log on shutdown preventing rc_logger from saving messages and throwing "Unable to.." errors

3 participants