Skip to content

Commit

Permalink
lapi/stat.h: Handle invalid __NR_fchmodat2 syscall return value
Browse files Browse the repository at this point in the history
Only 0 and -1 are valid for __NR_fchmodat2. Reporting invalid return
value is current approach for LTP safe macros.

While at it, unify the error message with safe macros.

Fixes: 49e1c01 ("Add fchmodat2 fallback definition")
Signed-off-by: Petr Vorel <[email protected]>
Acked-by: Andrea Cervesato <[email protected]>
Reviewed-by: Li Wang <[email protected]>
  • Loading branch information
pevik authored and wangli5665 committed Aug 6, 2024
1 parent adc878f commit 98cf903
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions include/lapi/stat.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,15 @@ static inline int safe_fchmodat2(const char *file, const int lineno,
int ret;

ret = tst_syscall(__NR_fchmodat2, dfd, filename, mode, flags);
if (ret == -1)
tst_brk_(file, lineno, TBROK | TERRNO, "%s(%d,%s,%d,%d) error",
__func__, dfd, filename, mode, flags);
if (ret == -1) {
tst_brk_(file, lineno, TBROK | TERRNO,
"syscall(__NR_fchmodat2,%d,%s,%d,%d) failed",
dfd, filename, mode, flags);
} else if (ret) {
tst_brk_(file, lineno, TBROK | TERRNO,
"Invalid syscall(__NR_fchmodat2,%d,%s,%d,%d) return value %d",
dfd, filename, mode, flags, ret);
}

return ret;
}
Expand Down

0 comments on commit 98cf903

Please sign in to comment.