Skip to content

Commit

Permalink
close-on-exec fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuafried committed Jun 23, 2024
1 parent 3041341 commit 7fe250a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
12 changes: 8 additions & 4 deletions junction/fs/file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ std::shared_ptr<File> FileTable::Dup(int fd) {
return tbl->files[fd];
}

int FileTable::Insert(std::shared_ptr<File> f, size_t lowest, bool cloexec) {
int FileTable::Insert(std::shared_ptr<File> f, bool cloexec, size_t lowest) {
rt::SpinGuard g(lock_);
size_t i;
auto fin = finally([this, cloexec, &i] {
Expand Down Expand Up @@ -567,13 +567,17 @@ long usys_fcntl(int fd, unsigned int cmd, unsigned long arg) {
std::shared_ptr<File> fdup;
fdup = ftbl.Dup(fd);
if (!fdup) return -EBADF;
return ftbl.Insert(std::move(fdup), arg, cmd == F_DUPFD_CLOEXEC);
return ftbl.Insert(std::move(fdup), cmd == F_DUPFD_CLOEXEC, arg);
}
case F_GETFD:
return ftbl.TestCloseOnExec(fd) ? FD_CLOEXEC : 0;
case F_SETFD:
if (arg != FD_CLOEXEC) return -EINVAL;
ftbl.SetCloseOnExec(fd);
if (arg == FD_CLOEXEC)
ftbl.SetCloseOnExec(fd);
else if (arg == 0)
ftbl.ClearCloseOnExec(fd);
else
return -EINVAL;
return 0;
case F_GETFL:
return ToFlags(f->get_mode()) | f->get_flags();
Expand Down
2 changes: 1 addition & 1 deletion junction/fs/file.h
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ class FileTable {
std::shared_ptr<File> Dup(int fd);

// Inserts a file into the file table and refcounts it. Returns the fd number.
int Insert(std::shared_ptr<File> f, size_t lowest = 0, bool cloexec = false);
int Insert(std::shared_ptr<File> f, bool cloexec = false, size_t lowest = 0);

// Inserts a file into the file table at a specific fd number and refcounts
// it. If a file already exists for the fd number, it will be replaced
Expand Down
2 changes: 1 addition & 1 deletion junction/fs/procfs/procfs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class ProcFSInode : public Inode {
std::shared_ptr<IDir> parent_;
};

constexpr std::optional<pid_t> ParsePid(std::string_view s) {
std::optional<pid_t> ParsePid(std::string_view s) {
pid_t result;
if (std::from_chars(s.data(), s.data() + s.size(), result).ec == std::errc{})
return result;
Expand Down

0 comments on commit 7fe250a

Please sign in to comment.