Fix logrotate.set dropping endscript on second script block (#68293)#69424
Open
dwoz wants to merge 1 commit into
Open
Fix logrotate.set dropping endscript on second script block (#68293)#69424dwoz wants to merge 1 commit into
dwoz wants to merge 1 commit into
Conversation
logrotate stanzas may contain more than one shell-script directive (``prerotate``/``postrotate``/``firstaction``/``lastaction``/``preremove``), each terminated by its own ``endscript``. ``_parse_conf`` was parsing every line inside those blocks as an ordinary ``key value`` setting, so the embedded shell commands became bogus dict keys and the two ``endscript`` terminators collapsed into a single dict entry. When ``logrotate.set`` rewrote the stanza via ``_dict_to_stanza`` only one ``endscript`` was emitted, leaving the second script block unterminated and the config invalid. Recognize the script directives explicitly: collect their body lines as opaque shell content until ``endscript``, store them under the directive key as a list, and emit them back as a proper script block (with their own ``endscript``) on rewrite. Fixes saltstack#68293
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Fix
logrotate.setcorrupting stanzas that contain more than one shellscript directive.
_parse_confnow recognizesprerotate/postrotate/firstaction/lastaction/preremoveandcaptures the body between the directive and its
endscriptas opaquemulti-line content, instead of treating each shell command as a setting and
collapsing the two
endscriptterminators into a single dict key._dict_to_stanzaemits the recovered blocks back with their ownendscripton rewrite.What issues does this PR fix or reference?
Fixes #68293
Previous Behavior
Calling
salt-call logrotate.set <stanza> size 21Magainst a config thatcontained both a
prerotateand apostrotateblock silently droppedthe
endscriptterminator from the second block, producing an invalidlogrotate config.
New Behavior
Both script blocks round-trip through
logrotate.setwith their ownendscriptpreserved; embedded shell commands no longer leak into thestanza dict as bogus setting keys.
Merge requirements satisfied?
Commits signed with GPG?
Yes