| 1412 | } |
| 1413 | |
| 1414 | static int |
| 1415 | pipe_poll(struct file *fp, int events, struct ucred *active_cred, |
| 1416 | struct thread *td) |
| 1417 | { |
| 1418 | struct pipe *rpipe; |
| 1419 | struct pipe *wpipe; |
| 1420 | int levents, revents; |
| 1421 | #ifdef MAC |
| 1422 | int error; |
| 1423 | #endif |
| 1424 | |
| 1425 | revents = 0; |
| 1426 | rpipe = fp->f_data; |
| 1427 | wpipe = PIPE_PEER(rpipe); |
| 1428 | PIPE_LOCK(rpipe); |
| 1429 | #ifdef MAC |
| 1430 | error = mac_pipe_check_poll(active_cred, rpipe->pipe_pair); |
| 1431 | if (error) |
| 1432 | goto locked_error; |
| 1433 | #endif |
| 1434 | if (fp->f_flag & FREAD && events & (POLLIN | POLLRDNORM)) |
| 1435 | if (rpipe->pipe_pages.cnt > 0 || rpipe->pipe_buffer.cnt > 0) |
| 1436 | revents |= events & (POLLIN | POLLRDNORM); |
| 1437 | |
| 1438 | if (fp->f_flag & FWRITE && events & (POLLOUT | POLLWRNORM)) |
| 1439 | if (wpipe->pipe_present != PIPE_ACTIVE || |
| 1440 | (wpipe->pipe_state & PIPE_EOF) || |
| 1441 | ((wpipe->pipe_state & PIPE_DIRECTW) == 0 && |
| 1442 | ((wpipe->pipe_buffer.size - wpipe->pipe_buffer.cnt) >= PIPE_BUF || |
| 1443 | wpipe->pipe_buffer.size == 0))) |
| 1444 | revents |= events & (POLLOUT | POLLWRNORM); |
| 1445 | |
| 1446 | levents = events & |
| 1447 | (POLLIN | POLLINIGNEOF | POLLPRI | POLLRDNORM | POLLRDBAND); |
| 1448 | if (rpipe->pipe_type & PIPE_TYPE_NAMED && fp->f_flag & FREAD && levents && |
| 1449 | fp->f_pipegen == rpipe->pipe_wgen) |
| 1450 | events |= POLLINIGNEOF; |
| 1451 | |
| 1452 | if ((events & POLLINIGNEOF) == 0) { |
| 1453 | if (rpipe->pipe_state & PIPE_EOF) { |
| 1454 | if (fp->f_flag & FREAD) |
| 1455 | revents |= (events & (POLLIN | POLLRDNORM)); |
| 1456 | if (wpipe->pipe_present != PIPE_ACTIVE || |
| 1457 | (wpipe->pipe_state & PIPE_EOF)) |
| 1458 | revents |= POLLHUP; |
| 1459 | } |
| 1460 | } |
| 1461 | |
| 1462 | if (revents == 0) { |
| 1463 | /* |
| 1464 | * Add ourselves regardless of eventmask as we have to return |
| 1465 | * POLLHUP even if it was not asked for. |
| 1466 | */ |
| 1467 | if ((fp->f_flag & FREAD) != 0) { |
| 1468 | selrecord(td, &rpipe->pipe_sel); |
| 1469 | if (SEL_WAITING(&rpipe->pipe_sel)) |
| 1470 | rpipe->pipe_state |= PIPE_SEL; |
| 1471 | } |
nothing calls this directly
no test coverage detected