Skip to content

sap*preconfigure: sysctl checks fail when config file has comments#996

Merged
berndfinger merged 2 commits into
sap-linuxlab:devfrom
rob0d:sysctl-fixes
Mar 13, 2025
Merged

sap*preconfigure: sysctl checks fail when config file has comments#996
berndfinger merged 2 commits into
sap-linuxlab:devfrom
rob0d:sysctl-fixes

Conversation

@rob0d
Copy link
Copy Markdown
Contributor

@rob0d rob0d commented Mar 12, 2025

Hi @berndfinger,

PR#807 introduced checks of kernel parameters to support indepotency.
However, under very rare circumstances when the sysctl conf files contain comments (#) this check fails as the awk command includes the line with the comments as a kernel parameter to check.
It generates something like:
sysctl #This is comment net.ipv4.tcp_rmem

This PR makes a minor change to make awk exclude all lines starting with # (i.e. ^#).

Kudos @James-Allen_nbs.

@berndfinger berndfinger self-requested a review March 13, 2025 08:37
@berndfinger
Copy link
Copy Markdown
Member

@rob0d Thanks for this. I had a quick look at man sysctl.d (RHEL 9) and it mentions that empty lines and those whose first non-whitespace character is "#" or ";" are ignored.

The following example should contain any allowed patterns I can think of (note that the second empty line contains three spaces and that the third empty line contained a tab character, and that the lines with a comment sign at column 8 were starting with a tab character):

net.ipv4.tcp_max_syn_backlog=8192
net.ipv4.tcp_timestamps=1

   
        
net.ipv4.tcp_slow_start_after_idle=0
net.core.wmem_max=4194304
#net.core.wmem_max=4194304
# net.core.wmem_max=4194304
 # net.core.wmem_max=4194304
        # net.core.wmem_max=4194304
;net.core.wmem_max=4194304
; net.core.wmem_max=4194304
 ; net.core.wmem_max=4194304
        ; net.core.wmem_max=4194304
net.core.rmem_max=6291456

It seems that the following awk statement will display only valid parameters:

awk 'BEGIN{FS="="; printf ("sysctl ")}NF>1&&!/^\s*[#;]/{printf ("%s ", $1)}' FILE

Note: NF is 0 for a line without a white space and 1 for a line with one or more white space characters.

…sctl parameter construction - improved version from Bernd
@rob0d
Copy link
Copy Markdown
Contributor Author

rob0d commented Mar 13, 2025

@berndfinger oh yes. We rushed a fix out as we needed to continue, but this is definitely better. Updated. Thanks Bernd.

Copy link
Copy Markdown
Member

@berndfinger berndfinger left a comment

Choose a reason for hiding this comment

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

LGTM!

@berndfinger berndfinger merged commit a14e78b into sap-linuxlab:dev Mar 13, 2025
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.

2 participants