| 412 | } |
| 413 | |
| 414 | int tty_wait_background(struct lwp_tty *tp, struct rt_thread *td, int sig) |
| 415 | { |
| 416 | struct rt_lwp *p; |
| 417 | struct rt_processgroup *pg; |
| 418 | int error; |
| 419 | |
| 420 | MPASS(sig == SIGTTIN || sig == SIGTTOU); |
| 421 | tty_assert_locked(tp); |
| 422 | |
| 423 | p = td->lwp; |
| 424 | for (;;) |
| 425 | { |
| 426 | pg = p->pgrp; |
| 427 | PGRP_LOCK(pg); |
| 428 | LWP_LOCK(p); |
| 429 | |
| 430 | /* |
| 431 | * pg may no longer be our process group. |
| 432 | * Re-check after locking. |
| 433 | */ |
| 434 | if (p->pgrp != pg) |
| 435 | { |
| 436 | LWP_UNLOCK(p); |
| 437 | PGRP_UNLOCK(pg); |
| 438 | continue; |
| 439 | } |
| 440 | |
| 441 | /* |
| 442 | * The process should only sleep, when: |
| 443 | * - This terminal is the controlling terminal |
| 444 | * - Its process group is not the foreground process |
| 445 | * group |
| 446 | * - The parent process isn't waiting for the child to |
| 447 | * exit |
| 448 | * - the signal to send to the process isn't masked |
| 449 | */ |
| 450 | if (!tty_is_ctty(tp, p) || pg == tp->t_pgrp) |
| 451 | { |
| 452 | /* Allow the action to happen. */ |
| 453 | LWP_UNLOCK(p); |
| 454 | PGRP_UNLOCK(pg); |
| 455 | return 0; |
| 456 | } |
| 457 | |
| 458 | /* Note: process itself don't have a sigmask in smart */ |
| 459 | if (lwp_sigisign(p, sig) || |
| 460 | lwp_sigismember(&td->signal.sigset_mask, sig)) |
| 461 | { |
| 462 | /* Only allow them in write()/ioctl(). */ |
| 463 | LWP_UNLOCK(p); |
| 464 | PGRP_UNLOCK(pg); |
| 465 | return (sig == SIGTTOU ? 0 : -EIO); |
| 466 | } |
| 467 | |
| 468 | #ifdef USING_VFORK_FLAG |
| 469 | if ((p->p_flag & P_PPWAIT) != 0 || pg->is_orphaned) |
| 470 | #else |
| 471 | if (pg->is_orphaned) |
no test coverage detected