Consider about situation, I'd suggest go with non-safe macros and add
additional check in the last.
e.g.
--- a/lib/tst_memutils.c
+++ b/lib/tst_memutils.c
@@ -108,17 +108,21 @@ static void set_oom_score_adj(pid_t pid, int value)
else
sprintf(score_path, "/proc/%d/oom_score_adj", pid);
- if (access(score_path, R_OK | W_OK) == -1) {
- tst_res(TINFO, "Warning: %s cannot be accessed for reading/writing,
- please check if test run with root user.",
- score_path);
- return
- }
-
- SAFE_FILE_PRINTF(score_path, "%d", value);
- SAFE_FILE_SCANF(score_path, "%d", &val);
- if (val != value)
+ if (access(score_path, F_OK) == -1)
+ tst_brk(TBROK, "%s does not exist, please check if PID is valid");
+
+ FILE_PRINTF(score_path, "%d", value);
+ FILE_SCANF(score_path, "%d", &val);
+
+ if (val != value) {
+ if (value < 0) {
+ tst_res(TINFO, "Warning: %s cannot be set to negative value,
+ please check if test run with root user.",
+ score_path);
+ return
+ }
tst_brk(TBROK, "oom_score_adj = %d, but expect %d.", val, value);
+ }
}