Browse Source

Close file descriptors in destructor of syscall_t

pull/1333/head
Yinan Xu 3 years ago
parent
commit
5afa62e541
  1. 13
      fesvr/syscall.cc
  2. 2
      fesvr/syscall.h

13
fesvr/syscall.cc

@ -174,9 +174,16 @@ syscall_t::syscall_t(htif_t* htif)
if (stdin_fd < 0 || stdout_fd0 < 0 || stdout_fd1 < 0)
throw std::runtime_error("could not dup stdin/stdout");
fds.alloc(stdin_fd); // stdin -> stdin
fds.alloc(stdout_fd0); // stdout -> stdout
fds.alloc(stdout_fd1); // stderr -> stdout
fds_index.push_back(fds.alloc(stdin_fd)); // stdin -> stdin
fds_index.push_back(fds.alloc(stdout_fd0)); // stdout -> stdout
fds_index.push_back(fds.alloc(stdout_fd1)); // stderr -> stdout
}
syscall_t::~syscall_t() {
for (auto i: fds_index) {
close(fds.lookup(i));
fds.dealloc(i);
}
}
std::string syscall_t::do_chroot(const char* fn)

2
fesvr/syscall.h

@ -28,6 +28,7 @@ class syscall_t : public device_t
{
public:
syscall_t(htif_t*);
~syscall_t();
void set_chroot(const char* where);
@ -38,6 +39,7 @@ class syscall_t : public device_t
memif_t* memif;
std::vector<syscall_func_t> table;
fds_t fds;
std::vector<reg_t> fds_index;
void handle_syscall(command_t cmd);
void dispatch(addr_t mm);

Loading…
Cancel
Save