sys_pipe.c (104094) | sys_pipe.c (104269) |
---|---|
1/* 2 * Copyright (c) 1996 John S. Dyson 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice immediately at the beginning of the file, without modification, 10 * this list of conditions, and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. Absolutely no warranty of function or purpose is made by the author 15 * John S. Dyson. 16 * 4. Modifications may be freely made to this file if the above conditions 17 * are met. 18 * | 1/* 2 * Copyright (c) 1996 John S. Dyson 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice immediately at the beginning of the file, without modification, 10 * this list of conditions, and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. Absolutely no warranty of function or purpose is made by the author 15 * John S. Dyson. 16 * 4. Modifications may be freely made to this file if the above conditions 17 * are met. 18 * |
19 * $FreeBSD: head/sys/kern/sys_pipe.c 104094 2002-09-28 17:15:38Z phk $ | 19 * $FreeBSD: head/sys/kern/sys_pipe.c 104269 2002-10-01 04:30:19Z rwatson $ |
20 */ 21 22/* 23 * This file contains a high-performance replacement for the socket-based 24 * pipes scheme originally used in FreeBSD/4.4Lite. It does not support 25 * all features of sockets, but does do everything that pipes normally 26 * do. 27 */ --- 1132 unchanged lines hidden (view full) --- 1160 u_long cmd; 1161 void *data; 1162 struct ucred *active_cred; 1163 struct thread *td; 1164{ 1165 struct pipe *mpipe = (struct pipe *)fp->f_data; 1166#ifdef MAC 1167 int error; | 20 */ 21 22/* 23 * This file contains a high-performance replacement for the socket-based 24 * pipes scheme originally used in FreeBSD/4.4Lite. It does not support 25 * all features of sockets, but does do everything that pipes normally 26 * do. 27 */ --- 1132 unchanged lines hidden (view full) --- 1160 u_long cmd; 1161 void *data; 1162 struct ucred *active_cred; 1163 struct thread *td; 1164{ 1165 struct pipe *mpipe = (struct pipe *)fp->f_data; 1166#ifdef MAC 1167 int error; |
1168#endif |
|
1168 | 1169 |
1169 /* XXXMAC: Pipe should be locked for this check. */ | 1170 PIPE_LOCK(mpipe); 1171 1172#ifdef MAC |
1170 error = mac_check_pipe_ioctl(active_cred, mpipe, cmd, data); 1171 if (error) 1172 return (error); 1173#endif 1174 1175 switch (cmd) { 1176 1177 case FIONBIO: | 1173 error = mac_check_pipe_ioctl(active_cred, mpipe, cmd, data); 1174 if (error) 1175 return (error); 1176#endif 1177 1178 switch (cmd) { 1179 1180 case FIONBIO: |
1181 PIPE_UNLOCK(mpipe); |
|
1178 return (0); 1179 1180 case FIOASYNC: | 1182 return (0); 1183 1184 case FIOASYNC: |
1181 PIPE_LOCK(mpipe); | |
1182 if (*(int *)data) { 1183 mpipe->pipe_state |= PIPE_ASYNC; 1184 } else { 1185 mpipe->pipe_state &= ~PIPE_ASYNC; 1186 } 1187 PIPE_UNLOCK(mpipe); 1188 return (0); 1189 1190 case FIONREAD: | 1185 if (*(int *)data) { 1186 mpipe->pipe_state |= PIPE_ASYNC; 1187 } else { 1188 mpipe->pipe_state &= ~PIPE_ASYNC; 1189 } 1190 PIPE_UNLOCK(mpipe); 1191 return (0); 1192 1193 case FIONREAD: |
1191 PIPE_LOCK(mpipe); | |
1192 if (mpipe->pipe_state & PIPE_DIRECTW) 1193 *(int *)data = mpipe->pipe_map.cnt; 1194 else 1195 *(int *)data = mpipe->pipe_buffer.cnt; 1196 PIPE_UNLOCK(mpipe); 1197 return (0); 1198 1199 case FIOSETOWN: | 1194 if (mpipe->pipe_state & PIPE_DIRECTW) 1195 *(int *)data = mpipe->pipe_map.cnt; 1196 else 1197 *(int *)data = mpipe->pipe_buffer.cnt; 1198 PIPE_UNLOCK(mpipe); 1199 return (0); 1200 1201 case FIOSETOWN: |
1202 PIPE_UNLOCK(mpipe); |
|
1200 return (fsetown(*(int *)data, &mpipe->pipe_sigio)); 1201 1202 case FIOGETOWN: | 1203 return (fsetown(*(int *)data, &mpipe->pipe_sigio)); 1204 1205 case FIOGETOWN: |
1206 PIPE_UNLOCK(mpipe); |
|
1203 *(int *)data = fgetown(mpipe->pipe_sigio); 1204 return (0); 1205 1206 /* This is deprecated, FIOSETOWN should be used instead. */ 1207 case TIOCSPGRP: | 1207 *(int *)data = fgetown(mpipe->pipe_sigio); 1208 return (0); 1209 1210 /* This is deprecated, FIOSETOWN should be used instead. */ 1211 case TIOCSPGRP: |
1212 PIPE_UNLOCK(mpipe); |
|
1208 return (fsetown(-(*(int *)data), &mpipe->pipe_sigio)); 1209 1210 /* This is deprecated, FIOGETOWN should be used instead. */ 1211 case TIOCGPGRP: | 1213 return (fsetown(-(*(int *)data), &mpipe->pipe_sigio)); 1214 1215 /* This is deprecated, FIOGETOWN should be used instead. */ 1216 case TIOCGPGRP: |
1217 PIPE_UNLOCK(mpipe); |
|
1212 *(int *)data = -fgetown(mpipe->pipe_sigio); 1213 return (0); 1214 1215 } | 1218 *(int *)data = -fgetown(mpipe->pipe_sigio); 1219 return (0); 1220 1221 } |
1222 PIPE_UNLOCK(mpipe); |
|
1216 return (ENOTTY); 1217} 1218 1219static int 1220pipe_poll(fp, events, active_cred, td) 1221 struct file *fp; 1222 int events; 1223 struct ucred *active_cred; --- 59 unchanged lines hidden (view full) --- 1283 struct stat *ub; 1284 struct ucred *active_cred; 1285 struct thread *td; 1286{ 1287 struct pipe *pipe = (struct pipe *)fp->f_data; 1288#ifdef MAC 1289 int error; 1290 | 1223 return (ENOTTY); 1224} 1225 1226static int 1227pipe_poll(fp, events, active_cred, td) 1228 struct file *fp; 1229 int events; 1230 struct ucred *active_cred; --- 59 unchanged lines hidden (view full) --- 1290 struct stat *ub; 1291 struct ucred *active_cred; 1292 struct thread *td; 1293{ 1294 struct pipe *pipe = (struct pipe *)fp->f_data; 1295#ifdef MAC 1296 int error; 1297 |
1291 /* XXXMAC: Pipe should be locked for this check. */ | 1298 PIPE_LOCK(pipe); |
1292 error = mac_check_pipe_stat(active_cred, pipe); | 1299 error = mac_check_pipe_stat(active_cred, pipe); |
1300 PIPE_UNLOCK(pipe); |
|
1293 if (error) 1294 return (error); 1295#endif 1296 bzero(ub, sizeof(*ub)); 1297 ub->st_mode = S_IFIFO; 1298 ub->st_blksize = pipe->pipe_buffer.size; 1299 ub->st_size = pipe->pipe_buffer.cnt; 1300 ub->st_blocks = (ub->st_size + ub->st_blksize - 1) / ub->st_blksize; --- 205 unchanged lines hidden --- | 1301 if (error) 1302 return (error); 1303#endif 1304 bzero(ub, sizeof(*ub)); 1305 ub->st_mode = S_IFIFO; 1306 ub->st_blksize = pipe->pipe_buffer.size; 1307 ub->st_size = pipe->pipe_buffer.cnt; 1308 ub->st_blocks = (ub->st_size + ub->st_blksize - 1) / ub->st_blksize; --- 205 unchanged lines hidden --- |