Print this page
7127 remove -Wno-missing-braces from Makefile.uts
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/syscall/pipe.c
+++ new/usr/src/uts/common/syscall/pipe.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright 2013 OmniTI Computer Consulting, Inc. All rights reserved.
23 23 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
24 24 * Use is subject to license terms.
25 25 * Copyright (c) 2011 Bayard G. Bell. All rights reserved.
26 26 */
27 27
28 28 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
29 29 /* All Rights Reserved */
30 30
31 31
32 32 #include <sys/types.h>
33 33 #include <sys/sysmacros.h>
34 34 #include <sys/param.h>
35 35 #include <sys/systm.h>
36 36 #include <sys/cred.h>
37 37 #include <sys/user.h>
38 38 #include <sys/vnode.h>
39 39 #include <sys/file.h>
40 40 #include <sys/stream.h>
41 41 #include <sys/strsubr.h>
42 42 #include <sys/errno.h>
43 43 #include <sys/debug.h>
44 44 #include <sys/fs/fifonode.h>
45 45 #include <sys/fcntl.h>
46 46
47 47 /*
48 48 * This is the loadable module wrapper.
49 49 */
50 50 #include <sys/modctl.h>
51 51 #include <sys/syscall.h>
52 52
53 53 int pipe(intptr_t fds, int);
54 54
55 55 static struct sysent pipe_sysent = {
56 56 2,
57 57 SE_ARGC | SE_32RVAL1 | SE_NOUNLOAD,
58 58 (int (*)())pipe
59 59 };
60 60
61 61 /*
62 62 * Module linkage information for the kernel.
63 63 */
64 64 static struct modlsys modlsys = {
65 65 &mod_syscallops, "pipe(2) syscall", &pipe_sysent
↓ open down ↓ |
65 lines elided |
↑ open up ↑ |
66 66 };
67 67
68 68 #ifdef _SYSCALL32_IMPL
69 69 static struct modlsys modlsys32 = {
70 70 &mod_syscallops32, "32-bit pipe(2) syscall", &pipe_sysent
71 71 };
72 72 #endif
73 73
74 74 static struct modlinkage modlinkage = {
75 75 MODREV_1,
76 - &modlsys,
76 + { &modlsys,
77 77 #ifdef _SYSCALL32_IMPL
78 - &modlsys32,
78 + &modlsys32,
79 79 #endif
80 - NULL
80 + NULL
81 + }
81 82 };
82 83
83 84 int
84 85 _init(void)
85 86 {
86 87 return (mod_install(&modlinkage));
87 88 }
88 89
89 90 int
90 91 _fini(void)
91 92 {
92 93 return (EBUSY);
93 94 }
94 95
95 96 int
96 97 _info(struct modinfo *modinfop)
97 98 {
98 99 return (mod_info(&modlinkage, modinfop));
99 100 }
100 101
101 102 /*
102 103 * pipe(2) system call.
103 104 * Create a pipe by connecting two streams together. Associate
104 105 * each end of the pipe with a vnode, a file descriptor and
105 106 * one of the streams.
106 107 */
107 108 int
108 109 pipe(intptr_t arg, int flags)
109 110 {
110 111 vnode_t *vp1, *vp2;
111 112 struct file *fp1, *fp2;
112 113 int error = 0;
113 114 int flag1, flag2, iflags;
114 115 int fd1, fd2;
115 116
116 117 /*
117 118 * Validate allowed flags.
118 119 */
119 120 if ((flags & ~(FCLOEXEC|FNONBLOCK)) != 0) {
120 121 return (set_errno(EINVAL));
121 122 }
122 123 /*
123 124 * Allocate and initialize two vnodes.
124 125 */
125 126 makepipe(&vp1, &vp2);
126 127
127 128 /*
128 129 * Allocate and initialize two file table entries and two
129 130 * file pointers. Each file pointer is open for read and
130 131 * write.
131 132 */
132 133 if (error = falloc(vp1, FWRITE|FREAD, &fp1, &fd1)) {
133 134 VN_RELE(vp1);
134 135 VN_RELE(vp2);
135 136 return (set_errno(error));
136 137 }
137 138
138 139 if (error = falloc(vp2, FWRITE|FREAD, &fp2, &fd2))
139 140 goto out2;
140 141
141 142 /*
142 143 * Create two stream heads and attach to each vnode.
143 144 */
144 145 if (error = fifo_stropen(&vp1, FWRITE|FREAD, fp1->f_cred, 0, 0))
145 146 goto out;
146 147
147 148 if (error = fifo_stropen(&vp2, FWRITE|FREAD, fp2->f_cred, 0, 0)) {
148 149 (void) VOP_CLOSE(vp1, FWRITE|FREAD, 1, (offset_t)0,
149 150 fp1->f_cred, NULL);
150 151 goto out;
151 152 }
152 153
153 154 strmate(vp1, vp2);
154 155
155 156 VTOF(vp1)->fn_ino = VTOF(vp2)->fn_ino = fifogetid();
156 157
157 158 /*
158 159 * Set the O_NONBLOCK flag if requested.
159 160 */
160 161 if (flags & FNONBLOCK) {
161 162 flag1 = fp1->f_flag;
162 163 flag2 = fp2->f_flag;
163 164 iflags = flags & FNONBLOCK;
164 165
165 166 if (error = VOP_SETFL(vp1, flag1, iflags, fp1->f_cred, NULL)) {
166 167 goto out_vop_close;
167 168 }
168 169 fp1->f_flag |= iflags;
169 170
170 171 if (error = VOP_SETFL(vp2, flag2, iflags, fp2->f_cred, NULL)) {
171 172 goto out_vop_close;
172 173 }
173 174 fp2->f_flag |= iflags;
174 175 }
175 176
176 177 /*
177 178 * Return the file descriptors to the user. They now
178 179 * point to two different vnodes which have different
179 180 * stream heads.
180 181 */
181 182 if (copyout(&fd1, &((int *)arg)[0], sizeof (int)) ||
182 183 copyout(&fd2, &((int *)arg)[1], sizeof (int))) {
183 184 error = EFAULT;
184 185 goto out_vop_close;
185 186 }
186 187
187 188 /*
188 189 * Now fill in the entries that falloc reserved
189 190 */
190 191 mutex_exit(&fp1->f_tlock);
191 192 mutex_exit(&fp2->f_tlock);
192 193 setf(fd1, fp1);
193 194 setf(fd2, fp2);
194 195
195 196 /*
196 197 * Optionally set the FCLOEXEC flag
197 198 */
198 199 if ((flags & FCLOEXEC) != 0) {
199 200 f_setfd(fd1, FD_CLOEXEC);
200 201 f_setfd(fd2, FD_CLOEXEC);
201 202 }
202 203
203 204 return (0);
204 205 out_vop_close:
205 206 (void) VOP_CLOSE(vp1, FWRITE|FREAD, 1, (offset_t)0, fp1->f_cred, NULL);
206 207 (void) VOP_CLOSE(vp2, FWRITE|FREAD, 1, (offset_t)0, fp2->f_cred, NULL);
207 208 out:
208 209 setf(fd2, NULL);
209 210 unfalloc(fp2);
210 211 out2:
211 212 setf(fd1, NULL);
212 213 unfalloc(fp1);
213 214 VN_RELE(vp1);
214 215 VN_RELE(vp2);
215 216 return (set_errno(error));
216 217 }
↓ open down ↓ |
126 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX