From c67f39142ca8fe4d544835156403e0c0cf51a0f5 Mon Sep 17 00:00:00 2001 From: "debing.sun" Date: Tue, 5 Mar 2024 20:42:28 +0800 Subject: [PATCH] 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. --- tests/unit/oom-score-adj.tcl | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tests/unit/oom-score-adj.tcl b/tests/unit/oom-score-adj.tcl index c557fee42..4c32a318f 100644 --- a/tests/unit/oom-score-adj.tcl +++ b/tests/unit/oom-score-adj.tcl @@ -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} {