MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / tty_wait_background

Function tty_wait_background

components/lwp/terminal/freebsd/tty.c:414–496  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

412}
413
414int 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)

Callers 6

ttydisc_read_canonicalFunction · 0.85
ttydev_writeFunction · 0.85
ttydev_ioctlFunction · 0.85

Calls 5

tty_is_cttyFunction · 0.85
lwp_sigisignFunction · 0.85
lwp_sigismemberFunction · 0.85
lwp_pgrp_signal_killFunction · 0.85
tty_waitFunction · 0.85

Tested by

no test coverage detected