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

Pipe output from '/sbin/sysctl -n' through sed to remove spaces/tabs #76

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

PaulGale
Copy link

@PaulGale PaulGale commented May 3, 2023

The exec resource "enforce-sysctl-value-${qtitle}" for enforcing sysctl values fails for kernel parameters whose values are returned as a white space separated tuple.

Example:

% /sbin/sysctl -n net.ipv4.tcp_wmem
4096 229376 4194304

Each value in the results is separated by a horizontal tab which, if not removed, causes the call to /usr/bin/test to always fail and Puppet to report that a change has been applied when none should have.

One can verify the presence of tabs in the output by piping it through /usr/bin/xxd.

% /sbin/sysctl -n net.ipv4.tcp_wmem | xxd
00000000: 3430 3936 0932 3239 3337 3609 3431 3934 4096.229376.4194
00000010: 3330 340a 304.

Tabs are the bytes with the value 09.

By piping the output through sed tabs are converted to a single white space making comparison possible:

% /sbin/sysctl -n net.ipv4.tcp_wmem | sed -r -e 's/[ \t]+/ /g' | xxd
00000000: 3430 3936 2032 3239 3337 3620 3431 3934 4096 229376 4194
00000010: 3330 340a 304.

Space characters are the bytes with the value 20.

I would have included an automated unit test to verify this but I am unfamiliar with how write tests for Puppet modules. However, I did test it manually and it works on RHEL 8.

Kernel parameters that don't contain tabs are unaffected and are enforced as normal.

@nebakke
Copy link

nebakke commented Aug 9, 2024

@thias Any chance of getting this merged and released, if you're still looking?

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