Skip to content
Snippets Groups Projects
Commit 42684f7b authored by Fredrik Hübinette (Hubbe)'s avatar Fredrik Hübinette (Hubbe)
Browse files

Fixed bug in close_fd(), hope it is good enough

Rev: src/modules/files/file.c:1.9.2.1
parent eb719a45
No related merge requests found
...@@ -85,19 +85,31 @@ static int close_fd(int fd) ...@@ -85,19 +85,31 @@ static int close_fd(int fd)
{ {
while(1) while(1)
{ {
if(close(fd) >= 0) break; if(close(fd) < 0)
{
switch(errno) switch(errno)
{ {
default: default:
fatal("Unknown error in close().\n"); /* What happened? */
files[fd].errno=errno;
/* Try waiting it out in blocking mode */
set_nonblocking(fd,0);
if(close(fd) >= 0 || errno==EBADF)
break; /* It was actually closed, good! */
/* Failed, give up, crash, burn, die */
error("Failed to close file.\n");
case EBADF: case EBADF:
fatal("Closing a non-active file descriptor.\n"); fatal("Closing a non-active file descriptor.\n");
case EINTR: case EINTR:
break; continue;
} }
} }
break;
}
set_read_callback(fd,0,0); set_read_callback(fd,0,0);
set_write_callback(fd,0,0); set_write_callback(fd,0,0);
...@@ -351,7 +363,6 @@ static void do_close(int fd, int flags) ...@@ -351,7 +363,6 @@ static void do_close(int fd, int flags)
return; return;
case FILE_READ: case FILE_READ:
files[fd].open_mode &=~ FILE_READ;
if(files[fd].open_mode & FILE_WRITE) if(files[fd].open_mode & FILE_WRITE)
{ {
set_read_callback(fd,0,0); set_read_callback(fd,0,0);
...@@ -359,10 +370,10 @@ static void do_close(int fd, int flags) ...@@ -359,10 +370,10 @@ static void do_close(int fd, int flags)
}else{ }else{
close_fd(fd); close_fd(fd);
} }
files[fd].open_mode &=~ FILE_READ;
break; break;
case FILE_WRITE: case FILE_WRITE:
files[fd].open_mode &=~ FILE_WRITE;
if(files[fd].open_mode & FILE_READ) if(files[fd].open_mode & FILE_READ)
{ {
set_write_callback(fd,0,0); set_write_callback(fd,0,0);
...@@ -370,6 +381,7 @@ static void do_close(int fd, int flags) ...@@ -370,6 +381,7 @@ static void do_close(int fd, int flags)
}else{ }else{
close_fd(fd); close_fd(fd);
} }
files[fd].open_mode &=~ FILE_WRITE;
break; break;
case FILE_READ | FILE_WRITE: case FILE_READ | FILE_WRITE:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment