Check user's oom_score_adj write permission for oom-score-adj test (#13111)

`CONFIG SET oom-score-adj handles configuration failures` test failed in
some CI jobs today.
Failed CI: https://github.com/redis/redis/actions/runs/8152519326

Not sure why the github action's docker image perssions have changed,
but the issue is similar to #12887,
where we can't assume the range of oom_score_adj that a user can change.

## Solution:
Modify the way of determining whether the current user has no privileges
or not,
instead of relying on whether the user id is 0 or not.
This commit is contained in:
debing.sun 2024-03-05 20:42:28 +08:00 committed by GitHub
parent 28976a9003
commit 9738ba9841
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 13 additions and 2 deletions

View File

@ -1,5 +1,4 @@
set system_name [string tolower [exec uname -s]]
set user_id [exec id -u]
if {$system_name eq {linux}} {
start_server {tags {"oom-score-adj external:skip"}} {
@ -56,8 +55,15 @@ if {$system_name eq {linux}} {
}
}
# Determine whether the current user is unprivileged
set original_value [exec cat /proc/self/oom_score_adj]
catch {
set fd [open "/proc/self/oom_score_adj" "w"]
puts $fd -1000
close $fd
} e
# Failed oom-score-adj tests can only run unprivileged
if {$user_id != 0} {
if {[string match "*permission denied*" $e]} {
test {CONFIG SET oom-score-adj handles configuration failures} {
# Bad config
r config set oom-score-adj no
@ -81,6 +87,11 @@ if {$system_name eq {linux}} {
# Make sure previous values remain
assert {[r config get oom-score-adj-values] == {oom-score-adj-values {0 100 100}}}
}
} else {
# Restore the original oom_score_adj value
set fd [open "/proc/self/oom_score_adj" "w"]
puts $fd $original_value
close $fd
}
test {CONFIG SET oom-score-adj-values doesn't touch proc when disabled} {