patch-2.4.0-test7 linux/include/linux/file.h

Next file: linux/include/linux/fs.h
Previous file: linux/include/linux/etherdevice.h
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.4.0-test6/linux/include/linux/file.h linux/include/linux/file.h
@@ -7,6 +7,27 @@
 
 extern void FASTCALL(fput(struct file *));
 extern struct file * FASTCALL(fget(unsigned int fd));
+ 
+static inline int get_close_on_exec(unsigned int fd)
+{
+	struct files_struct *files = current->files;
+	int res;
+	read_lock(&files->file_lock);
+	res = FD_ISSET(fd, files->close_on_exec);
+	read_unlock(&files->file_lock);
+	return res;
+}
+
+static inline void set_close_on_exec(unsigned int fd, int flag)
+{
+	struct files_struct *files = current->files;
+	write_lock(&files->file_lock);
+	if (flag)
+		FD_SET(fd, files->close_on_exec);
+	else
+		FD_CLR(fd, files->close_on_exec);
+	write_unlock(&files->file_lock);
+}
 
 static inline struct file * fcheck_files(struct files_struct *files, unsigned int fd)
 {
@@ -30,15 +51,6 @@
 	return file;
 }
 
-static inline struct file * frip(struct files_struct *files, unsigned int fd)
-{
-	struct file * file = NULL;
-
-	if (fd < files->max_fds)
-		file = xchg(&files->fd[fd], NULL);
-	return file;
-}
-
 extern void put_filp(struct file *);
 
 extern int get_unused_fd(void);
@@ -67,18 +79,20 @@
  * array.  At any such point, we are vulnerable to a dup2() race
  * installing a file in the array before us.  We need to detect this and
  * fput() the struct file we are about to overwrite in this case.
+ *
+ * It should never happen - if we allow dup2() do it, _really_ bad things
+ * will follow.
  */
 
 static inline void fd_install(unsigned int fd, struct file * file)
 {
 	struct files_struct *files = current->files;
-	struct file * result;
 	
 	write_lock(&files->file_lock);
-	result = xchg(&files->fd[fd], file);
+	if (files->fd[fd])
+		BUG();
+	files->fd[fd] = file;
 	write_unlock(&files->file_lock);
-	if (result)
-		fput(result);
 }
 
 void put_files_struct(struct files_struct *fs);

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)