aboutsummaryrefslogtreecommitdiffstats
path: root/fs/pipe.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/pipe.c')
-rw-r--r--fs/pipe.c35
1 files changed, 24 insertions, 11 deletions
diff --git a/fs/pipe.c b/fs/pipe.c
index 700f4e0d9572..10c4e9aa5c49 100644
--- a/fs/pipe.c
+++ b/fs/pipe.c
@@ -950,7 +950,7 @@ fail_inode:
950 return NULL; 950 return NULL;
951} 951}
952 952
953struct file *create_write_pipe(void) 953struct file *create_write_pipe(int flags)
954{ 954{
955 int err; 955 int err;
956 struct inode *inode; 956 struct inode *inode;
@@ -983,7 +983,7 @@ struct file *create_write_pipe(void)
983 goto err_dentry; 983 goto err_dentry;
984 f->f_mapping = inode->i_mapping; 984 f->f_mapping = inode->i_mapping;
985 985
986 f->f_flags = O_WRONLY; 986 f->f_flags = O_WRONLY | (flags & O_NONBLOCK);
987 f->f_version = 0; 987 f->f_version = 0;
988 988
989 return f; 989 return f;
@@ -1007,7 +1007,7 @@ void free_write_pipe(struct file *f)
1007 put_filp(f); 1007 put_filp(f);
1008} 1008}
1009 1009
1010struct file *create_read_pipe(struct file *wrf) 1010struct file *create_read_pipe(struct file *wrf, int flags)
1011{ 1011{
1012 struct file *f = get_empty_filp(); 1012 struct file *f = get_empty_filp();
1013 if (!f) 1013 if (!f)
@@ -1019,7 +1019,7 @@ struct file *create_read_pipe(struct file *wrf)
1019 f->f_mapping = wrf->f_path.dentry->d_inode->i_mapping; 1019 f->f_mapping = wrf->f_path.dentry->d_inode->i_mapping;
1020 1020
1021 f->f_pos = 0; 1021 f->f_pos = 0;
1022 f->f_flags = O_RDONLY; 1022 f->f_flags = O_RDONLY | (flags & O_NONBLOCK);
1023 f->f_op = &read_pipe_fops; 1023 f->f_op = &read_pipe_fops;
1024 f->f_mode = FMODE_READ; 1024 f->f_mode = FMODE_READ;
1025 f->f_version = 0; 1025 f->f_version = 0;
@@ -1027,26 +1027,29 @@ struct file *create_read_pipe(struct file *wrf)
1027 return f; 1027 return f;
1028} 1028}
1029 1029
1030int do_pipe(int *fd) 1030int do_pipe_flags(int *fd, int flags)
1031{ 1031{
1032 struct file *fw, *fr; 1032 struct file *fw, *fr;
1033 int error; 1033 int error;
1034 int fdw, fdr; 1034 int fdw, fdr;
1035 1035
1036 fw = create_write_pipe(); 1036 if (flags & ~(O_CLOEXEC | O_NONBLOCK))
1037 return -EINVAL;
1038
1039 fw = create_write_pipe(flags);
1037 if (IS_ERR(fw)) 1040 if (IS_ERR(fw))
1038 return PTR_ERR(fw); 1041 return PTR_ERR(fw);
1039 fr = create_read_pipe(fw); 1042 fr = create_read_pipe(fw, flags);
1040 error = PTR_ERR(fr); 1043 error = PTR_ERR(fr);
1041 if (IS_ERR(fr)) 1044 if (IS_ERR(fr))
1042 goto err_write_pipe; 1045 goto err_write_pipe;
1043 1046
1044 error = get_unused_fd(); 1047 error = get_unused_fd_flags(flags);
1045 if (error < 0) 1048 if (error < 0)
1046 goto err_read_pipe; 1049 goto err_read_pipe;
1047 fdr = error; 1050 fdr = error;
1048 1051
1049 error = get_unused_fd(); 1052 error = get_unused_fd_flags(flags);
1050 if (error < 0) 1053 if (error < 0)
1051 goto err_fdr; 1054 goto err_fdr;
1052 fdw = error; 1055 fdw = error;
@@ -1074,16 +1077,21 @@ int do_pipe(int *fd)
1074 return error; 1077 return error;
1075} 1078}
1076 1079
1080int do_pipe(int *fd)
1081{
1082 return do_pipe_flags(fd, 0);
1083}
1084
1077/* 1085/*
1078 * sys_pipe() is the normal C calling standard for creating 1086 * sys_pipe() is the normal C calling standard for creating
1079 * a pipe. It's not the way Unix traditionally does this, though. 1087 * a pipe. It's not the way Unix traditionally does this, though.
1080 */ 1088 */
1081asmlinkage long __weak sys_pipe(int __user *fildes) 1089asmlinkage long __weak sys_pipe2(int __user *fildes, int flags)
1082{ 1090{
1083 int fd[2]; 1091 int fd[2];
1084 int error; 1092 int error;
1085 1093
1086 error = do_pipe(fd); 1094 error = do_pipe_flags(fd, flags);
1087 if (!error) { 1095 if (!error) {
1088 if (copy_to_user(fildes, fd, sizeof(fd))) { 1096 if (copy_to_user(fildes, fd, sizeof(fd))) {
1089 sys_close(fd[0]); 1097 sys_close(fd[0]);
@@ -1094,6 +1102,11 @@ asmlinkage long __weak sys_pipe(int __user *fildes)
1094 return error; 1102 return error;
1095} 1103}
1096 1104
1105asmlinkage long __weak sys_pipe(int __user *fildes)
1106{
1107 return sys_pipe2(fildes, 0);
1108}
1109
1097/* 1110/*
1098 * pipefs should _never_ be mounted by userland - too much of security hassle, 1111 * pipefs should _never_ be mounted by userland - too much of security hassle,
1099 * no real gain from having the whole whorehouse mounted. So we don't need 1112 * no real gain from having the whole whorehouse mounted. So we don't need