mirror of
https://github.com/samba-team/samba.git
synced 2024-12-23 17:34:34 +03:00
lib: Add a little closefrom() test
Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org> Autobuild-User(master): Andreas Schneider <asn@cryptomilk.org> Autobuild-Date(master): Mon Jun 13 14:11:11 CEST 2016 on sn-devel-144
This commit is contained in:
parent
55529d0f85
commit
46916b24e9
@ -1063,6 +1063,38 @@ static int test_memmem(void)
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool test_closefrom(void)
|
||||
{
|
||||
int i, fd;
|
||||
|
||||
for (i=0; i<100; i++) {
|
||||
fd = dup(0);
|
||||
if (fd == -1) {
|
||||
perror("dup failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
/* 1000 is just an arbitrarily chosen upper bound */
|
||||
|
||||
if (fd >= 1000) {
|
||||
printf("fd=%d\n", fd);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
closefrom(3);
|
||||
|
||||
for (i=3; i<=fd; i++) {
|
||||
off_t off;
|
||||
off = lseek(i, 0, SEEK_CUR);
|
||||
if ((off != (off_t)-1) || (errno != EBADF)) {
|
||||
printf("fd %d not closed\n", i);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool torture_local_replace(struct torture_context *ctx)
|
||||
{
|
||||
@ -1113,6 +1145,7 @@ bool torture_local_replace(struct torture_context *ctx)
|
||||
ret &= test_utime();
|
||||
ret &= test_utimes();
|
||||
ret &= test_memmem();
|
||||
ret &= test_closefrom();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user