GitHub

Original file line numberDiff line numberDiff line change

@@ -125,13 +125,16 @@ static int dupfd(struct file *file, unsigned int start, int cloexec)

125125

return fd;

126126

}

127127
128-

asmlinkage long sys_dup2(unsigned int oldfd, unsigned int newfd)

128+

asmlinkage long sys_dup3(unsigned int oldfd, unsigned int newfd, int flags)

129129

{

130130

int err = -EBADF;

131131

struct file * file, *tofree;

132132

struct files_struct * files = current->files;

133133

struct fdtable *fdt;

134134
135+

if ((flags & ~O_CLOEXEC) != 0)

136+

return -EINVAL;

137+
135138

spin_lock(&files->file_lock);

136139

if (!(file = fcheck(oldfd)))

137140

goto out_unlock;

@@ -163,7 +166,10 @@ asmlinkage long sys_dup2(unsigned int oldfd, unsigned int newfd)

163166
164167

rcu_assign_pointer(fdt->fd[newfd], file);

165168

FD_SET(newfd, fdt->open_fds);

166-

FD_CLR(newfd, fdt->close_on_exec);

169+

if (flags & O_CLOEXEC)

170+

FD_SET(newfd, fdt->close_on_exec);

171+

else

172+

FD_CLR(newfd, fdt->close_on_exec);

167173

spin_unlock(&files->file_lock);

168174
169175

if (tofree)

@@ -181,6 +187,11 @@ asmlinkage long sys_dup2(unsigned int oldfd, unsigned int newfd)

181187

goto out;

182188

}

183189
190+

asmlinkage long sys_dup2(unsigned int oldfd, unsigned int newfd)

191+

{

192+

return sys_dup3(oldfd, newfd, 0);

193+

}

194+
184195

asmlinkage long sys_dup(unsigned int fildes)

185196

{

186197

int ret = -EBADF;

Read the original on github.com ↗