Skip to content

Commit 14dc523

Browse files
authored
Fix a race condition in test_chmod (#25029)
Fix logic error in test_chmod that resulted in a race condition. The test would compare file metadata modification times of `file` vs `otherfile` to each other, when the intent was to test modification time of `otherfile` before vs after its `fchmodat()` operation. Fixes #24905.
1 parent 5ab4c12 commit 14dc523

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

test/stat/test_chmod.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ void test() {
4949
struct stat s;
5050

5151
//
52-
// chmod a file
52+
// chmod()ing a file should change metadata modification time (ctime),
53+
// but not the file modification time (mtime)
5354
//
5455
// get the current ctime for the file
5556
memset(&s, 0, sizeof s);
@@ -69,7 +70,8 @@ void test() {
6970
assert(s.st_mtime == lastmtime);
7071

7172
//
72-
// fchmod a file
73+
// fchmod()ing a file should change metadata modification time,
74+
// but not the file modification time
7375
//
7476
lastctime = s.st_ctime;
7577
lastmtime = s.st_mtime;
@@ -85,8 +87,11 @@ void test() {
8587
assert(s.st_mtime == lastmtime);
8688

8789
//
88-
// fchmodat a file
90+
// fchmodat()ing a file should also only change metadata modification time,
91+
// but not the file modification time.
8992
//
93+
memset(&s, 0, sizeof s);
94+
stat("otherfile", &s);
9095
lastctime = s.st_ctime;
9196
lastmtime = s.st_mtime;
9297
sleep(1);

0 commit comments

Comments
 (0)