systemctl: warn when cat shows changed unit files#4493
systemctl: warn when cat shows changed unit files#4493keszybz merged 1 commit intosystemd:masterfrom
Conversation
src/systemctl/systemctl.c
Outdated
| puts(""); | ||
|
|
||
| if (need_daemon_reload(bus, *name)) | ||
| printf("%s# %sWarning:%s %s changed on disk, showing current disk contents.\n" |
There was a problem hiding this comment.
Ha, I thought that this would be a more complicated patch. It's nice when existing functionality gets reused like that.
It prints the warning without any special formatting to stderr, which doesn’t break systemctl cat foo.service > foo2.service, but looks ugly in the terminal.
Hm, maybe we could print the warning to stdout if we were originally on the terminal (before the pager was started), and to stderr otherwise? We do a similar check in various other cases.
Why make the message blue? Shouldn't it be red as other warnings?
I'm not sure about the message:
# Warning: abrt-ccpp.service changed on disk, showing current disk contents.
# Run 'systemctl daemon-reload' to reload units.
The first line basically says that you're showing the latest version ;)
There are two cases to consider:
- an existing file was modified, either the main unit file, or one of the drop-ins.
- a drop in was added or removed
In the first case, cat is showing good content, but the manager has an outdated view.
In the second case, cat is showing bad content, and the manager has an outdated view.
I don't think we can distinguish those cases with existing functionality, so the message should be updated to reflect both. Maybe something like "...service was changed on disk, systemd has an outdated version loaded. If drop-ins were added or removed, they are not properly reflected in this output. Run 'systmectl daemon-reload' to update to the version shown here."
There was a problem hiding this comment.
Ha, I thought that this would be a more complicated patch. It's nice when existing functionality gets reused like that.
Yes, I’m very glad I didn’t have to add a new dbus method to return unit files + time loaded or something like that :)
Why make the message blue? Shouldn't it be red as other warnings?
The word “Warning” is still red, just as in systemctl status. I only changed the color of the rest of the text from default to blue, to match the file name comments.
The first line basically says that you're showing the latest version ;)
I’m not sure what you mean… systemctl cat really is cat, it boils down to open(filename) and copy_bytes(fd, STDOUT_FILENO) (see function cat_file), showing whatever is currently on disk, not what the daemon loaded. Are you saying the message sounds like it’s showing what the daemon loaded? Then I should clarify it.
There’s another condition to consider, which exhibits the same behavior as the second case.
- a file was added that replaces the main unit file (
/etcvs./usr/lib,~/.configvs./etc, etc.)
This case is also not detected by need_daemon_reload.
I’m not sure if the message should reflect both cases – unless I’m missing something, we won’t even print the message in the second case, since we don’t know it’s happening.
|
On Wed, Oct 26, 2016 at 08:51:43AM -0700, Lucas Werkmeister wrote:
I think the whole thing should be in red. I used blue for the
I'm saying that 'cat' always shows the latest version (unless a file a
That's nasty. It'd be great to fix it for both 'systemctl cat' and
I think it should, since we should be able to detect both kinds of cases. |
7dff7e8 to
01835d3
Compare
|
New version pushed. Entire message is now red, and the text has been updated.
Why not fix the dbus property (
I was thinking it should only be updated when both kinds of cases are actually detected, but sure. |
|
Issue #4500 is for the needs-reload part. What about this comment?
|
Sorry, I missed that. But if we are using the pager, then both stdout and stderr go into the pager (see (I have an updated patch ready for either version, just let me know which one you’d prefer.) |
Ah, OK, I forgot that. So yeah, stderr seems fine. |
01835d3 to
1710476
Compare
|
Alright, thanks, updated again. |
Suggested by @keszybz in systemd#4488.
|
Thanks. |
|
Ouch, I just noticed that this caused CI failures, and they don’t look spurious…
Looks like something is assuming that any stderr output means a test failure. I’ll try to fix this. |
Yes, as that's a good tool to notice new unexpected warnings. I can disable that behaviour in the test, or filter it out. But ATM I don't actually see failures, just the i386 and amd64 tests are still running (i. e. this was apparently merged without waiting for CI to finish). |
|
Oh, I do see them now, e. g. in PR #4508 :-( |
|
I moved from |
|
Thanks, that looks like a better solution. |
|
Like that perhaps? I'll put up a PR for this. |
|
... but this isn't actually important, as this only runs through |
|
Oh, right, I forgot that |
|
I see this warning always: -bash-4.3# cat <<'EOF' >/etc/systemd/system/hola.service
[Service]
ExecStart=/bin/sh -x -c id
EOF
-bash-4.3# systemctl cat hola --no-pager
# Warning: hola.service changed on disk, the version systemd has loaded is outdated.
# This output shows the current version of the unit's original fragment and drop-in files.
# If fragments or drop-ins were added or removed, they are not properly reflected in this output.
# Run 'systemctl daemon-reload' to reload units.
# /etc/systemd/system/hola.service
[Service]
ExecStart=/bin/sh -x -c id
-bash-4.3# systemctl daemon-reload
-bash-4.3# systemctl cat hola --no-pager
# Warning: hola.service changed on disk, the version systemd has loaded is outdated.
# This output shows the current version of the unit's original fragment and drop-in files.
# If fragments or drop-ins were added or removed, they are not properly reflected in this output.
# Run 'systemctl daemon-reload' to reload units.
# /etc/systemd/system/hola.service
[Service]
ExecStart=/bin/sh -x -c id
-bash-4.3# systemctl show --value --property=NeedDaemonReload hola --no-pager
no |
Reported by @evverx in systemd#4493.
…memory one With systemd/systemd#4493, systemctl cat now warns that the on-disk unit changed, which causes failure due to unexpected stderr. We actually intend to use the on-disk one instead of the potentially older in-memory one, so change this to ask for the unit file path and operate on that instead.
…memory one With systemd/systemd#4493, systemctl cat now warns that the on-disk unit changed, which causes failure due to unexpected stderr. We actually intend to use the on-disk one instead of the potentially older in-memory one, so change this to ask for the unit file path and operate on that instead.
Suggested by @keszybz in #4488.
The warning is based on
warn_unit_file_changed, but there are so many changes that I think it’s better to copy a bit of code than to attempt to generalizewarn_unit_file_changedto fit this use case:#)Alternatively, here’s a minimal patch:
It prints the warning without any special formatting to stderr, which doesn’t break
systemctl cat foo.service > foo2.service, but looks ugly in the terminal.