Skip to content

Commit 332e0e8

Browse files
Alexey Dobriyantorvalds
authored andcommitted
proc: more robust bulk read test
/proc may not be mounted and test will exit successfully. Ensure proc is mounted at /proc. Link: http://lkml.kernel.org/r/20190209105613.GA10384@avx2 Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent e483b02 commit 332e0e8

File tree

1 file changed

+14
-0
lines changed
  • tools/testing/selftests/proc

1 file changed

+14
-0
lines changed

tools/testing/selftests/proc/read.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@
2626
#include <dirent.h>
2727
#include <stdbool.h>
2828
#include <stdlib.h>
29+
#include <stdio.h>
2930
#include <string.h>
3031
#include <sys/stat.h>
32+
#include <sys/vfs.h>
3133
#include <fcntl.h>
3234
#include <unistd.h>
3335

@@ -123,10 +125,22 @@ static void f(DIR *d, unsigned int level)
123125
int main(void)
124126
{
125127
DIR *d;
128+
struct statfs sfs;
126129

127130
d = opendir("/proc");
128131
if (!d)
129132
return 4;
133+
134+
/* Ensure /proc is proc. */
135+
if (fstatfs(dirfd(d), &sfs) == -1) {
136+
return 1;
137+
}
138+
if (sfs.f_type != 0x9fa0) {
139+
fprintf(stderr, "error: unexpected f_type %lx\n", (long)sfs.f_type);
140+
return 2;
141+
}
142+
130143
f(d, 0);
144+
131145
return 0;
132146
}

0 commit comments

Comments
 (0)