Use "getent group" instead of reading "/etc/group" to get group information#14316
Conversation
| if command -v getent > /dev/null 2>&1; then | ||
| getent group "${1:-""}" | ||
| else | ||
| cat /etc/group | grep "^${1}:" |
There was a problem hiding this comment.
I suggest dev null stdout and stderr in this function so a caller doesn't need to do it
There was a problem hiding this comment.
I will leave it as is due to the following call that needs to evaluate the function return value:
if get_group "${groupname}" | cut -d ':' -f 4 | grep -wq "${username}"; then
But I renamed group_exists() to get_group() to make the function purpose clearer.
There was a problem hiding this comment.
As it is now, get_group == getent group. Do we need cat /etc/group (also can be just grep "^${1}:" /etc/group) at all? I see we used getent group before this PR and it wasn't a problem.
There was a problem hiding this comment.
It's a fallback, see the other thread. You are right about cat, I am just used to do it this way for other reasons and forgot you can do grep directly. Not a big deal so I will merge it.
There was a problem hiding this comment.
It's a fallback, see the other thread.
Yes, I understood that.
My point is - why do we need this fallback? We had no fallback previously and it wasn't a problem.
There was a problem hiding this comment.
I agree but it was suggested by both @thiagoftsm and @Ferroin so I just added it.
thiagoftsm
left a comment
There was a problem hiding this comment.
Installation was successful after changes and netdata is running as expected, LGTM!
Summary
SSIA, Fixes #13711 .
Test Plan
netdata-installer.sh.netdata-uninstaller.shAdditional Information
For users: How does this change affect me?