diff options
Diffstat (limited to 'fs/open.c')
-rw-r--r-- | fs/open.c | 14 |
1 files changed, 11 insertions, 3 deletions
@@ -855,7 +855,7 @@ EXPORT_SYMBOL(dentry_open); | |||
855 | /* | 855 | /* |
856 | * Find an empty file descriptor entry, and mark it busy. | 856 | * Find an empty file descriptor entry, and mark it busy. |
857 | */ | 857 | */ |
858 | int get_unused_fd(void) | 858 | static int get_unused_fd_flags(int flags) |
859 | { | 859 | { |
860 | struct files_struct * files = current->files; | 860 | struct files_struct * files = current->files; |
861 | int fd, error; | 861 | int fd, error; |
@@ -891,7 +891,10 @@ repeat: | |||
891 | } | 891 | } |
892 | 892 | ||
893 | FD_SET(fd, fdt->open_fds); | 893 | FD_SET(fd, fdt->open_fds); |
894 | FD_CLR(fd, fdt->close_on_exec); | 894 | if (flags & O_CLOEXEC) |
895 | FD_SET(fd, fdt->close_on_exec); | ||
896 | else | ||
897 | FD_CLR(fd, fdt->close_on_exec); | ||
895 | files->next_fd = fd + 1; | 898 | files->next_fd = fd + 1; |
896 | #if 1 | 899 | #if 1 |
897 | /* Sanity check */ | 900 | /* Sanity check */ |
@@ -907,6 +910,11 @@ out: | |||
907 | return error; | 910 | return error; |
908 | } | 911 | } |
909 | 912 | ||
913 | int get_unused_fd(void) | ||
914 | { | ||
915 | return get_unused_fd_flags(0); | ||
916 | } | ||
917 | |||
910 | EXPORT_SYMBOL(get_unused_fd); | 918 | EXPORT_SYMBOL(get_unused_fd); |
911 | 919 | ||
912 | static void __put_unused_fd(struct files_struct *files, unsigned int fd) | 920 | static void __put_unused_fd(struct files_struct *files, unsigned int fd) |
@@ -959,7 +967,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, int mode) | |||
959 | int fd = PTR_ERR(tmp); | 967 | int fd = PTR_ERR(tmp); |
960 | 968 | ||
961 | if (!IS_ERR(tmp)) { | 969 | if (!IS_ERR(tmp)) { |
962 | fd = get_unused_fd(); | 970 | fd = get_unused_fd_flags(flags); |
963 | if (fd >= 0) { | 971 | if (fd >= 0) { |
964 | struct file *f = do_filp_open(dfd, tmp, flags, mode); | 972 | struct file *f = do_filp_open(dfd, tmp, flags, mode); |
965 | if (IS_ERR(f)) { | 973 | if (IS_ERR(f)) { |