39c39
< * $FreeBSD: head/sys/kern/tty.c 90375 2002-02-07 23:06:26Z peter $
---
> * $FreeBSD: head/sys/kern/tty.c 91140 2002-02-23 11:12:57Z tanimura $
77a78
> #include <sys/sx.h>
331c332,336
< pgsignal(tp->t_pgrp, SIGINT, 1);
---
> if (tp->t_pgrp != NULL) {
> PGRP_LOCK(tp->t_pgrp);
> pgsignal(tp->t_pgrp, SIGINT, 1);
> PGRP_UNLOCK(tp->t_pgrp);
> }
409,410c414,419
< pgsignal(tp->t_pgrp,
< CCEQ(cc[VINTR], c) ? SIGINT : SIGQUIT, 1);
---
> if (tp->t_pgrp != NULL) {
> PGRP_LOCK(tp->t_pgrp);
> pgsignal(tp->t_pgrp,
> CCEQ(cc[VINTR], c) ? SIGINT : SIGQUIT, 1);
> PGRP_UNLOCK(tp->t_pgrp);
> }
417c426,430
< pgsignal(tp->t_pgrp, SIGTSTP, 1);
---
> if (tp->t_pgrp != NULL) {
> PGRP_LOCK(tp->t_pgrp);
> pgsignal(tp->t_pgrp, SIGTSTP, 1);
> PGRP_UNLOCK(tp->t_pgrp);
> }
535c548,549
< if (ISSET(lflag, ISIG))
---
> if (ISSET(lflag, ISIG) && tp->t_pgrp != NULL) {
> PGRP_LOCK(tp->t_pgrp);
536a551,552
> PGRP_UNLOCK(tp->t_pgrp);
> }
754a771,772
> PGRPSESS_SLOCK();
> PROC_LOCK(p);
758c776,778
< if (p->p_pgrp->pg_jobc == 0)
---
> if (p->p_pgrp->pg_jobc == 0) {
> PROC_UNLOCK(p);
> PGRPSESS_SUNLOCK();
759a780,782
> }
> PROC_UNLOCK(p);
> PGRP_LOCK(p->p_pgrp);
760a784
> PGRP_UNLOCK(p->p_pgrp);
763c787,788
< if (error)
---
> if (error) {
> PGRPSESS_SUNLOCK();
764a790,791
> }
> PROC_LOCK(p);
765a793,794
> PROC_UNLOCK(p);
> PGRPSESS_SUNLOCK();
1014a1044
> PGRPSESS_XLOCK();
1017c1047,1048
< (tp->t_session != p->p_session)))
---
> (tp->t_session != p->p_session))) {
> PGRPSESS_XUNLOCK();
1018a1050
> }
1020a1053
> SESS_LOCK(p->p_session);
1021a1055,1056
> SESS_UNLOCK(p->p_session);
> PROC_LOCK(p);
1022a1058,1059
> PROC_UNLOCK(p);
> PGRPSESS_XUNLOCK();
1025c1062
< register struct pgrp *pgrp = pgfind(*(int *)data);
---
> register struct pgrp *pgrp;
1027c1064,1069
< if (!isctty(p, tp))
---
> PGRPSESS_SLOCK();
> pgrp = pgfind(*(int *)data);
> if (!isctty(p, tp)) {
> if (pgrp != NULL)
> PGRP_UNLOCK(pgrp);
> PGRPSESS_SUNLOCK();
1029c1071,1073
< else if (pgrp == NULL || pgrp->pg_session != p->p_session)
---
> }
> if (pgrp == NULL) {
> PGRPSESS_SUNLOCK();
1030a1075,1081
> }
> PGRP_UNLOCK(pgrp);
> if (pgrp->pg_session != p->p_session) {
> PGRPSESS_SUNLOCK();
> return (EPERM);
> }
> PGRPSESS_SUNLOCK();
1043c1094,1098
< pgsignal(tp->t_pgrp, SIGWINCH, 1);
---
> if (tp->t_pgrp != NULL) {
> PGRP_LOCK(tp->t_pgrp);
> pgsignal(tp->t_pgrp, SIGWINCH, 1);
> PGRP_UNLOCK(tp->t_pgrp);
> }
1462,1463c1517,1520
< if (tp->t_session && tp->t_session->s_leader) {
< struct proc *p;
---
> if (tp->t_session) {
> PGRPSESS_SLOCK();
> if (tp->t_session->s_leader) {
> struct proc *p;
1465,1468c1522,1527
< p = tp->t_session->s_leader;
< PROC_LOCK(p);
< psignal(p, SIGHUP);
< PROC_UNLOCK(p);
---
> p = tp->t_session->s_leader;
> PROC_LOCK(p);
> psignal(p, SIGHUP);
> PROC_UNLOCK(p);
> }
> PGRPSESS_SUNLOCK();
1551a1611,1612
> PGRPSESS_SLOCK();
> PROC_LOCK(p);
1554c1615,1617
< (p->p_flag & P_PPWAIT) || p->p_pgrp->pg_jobc == 0)
---
> (p->p_flag & P_PPWAIT) || p->p_pgrp->pg_jobc == 0) {
> PROC_UNLOCK(p);
> PGRPSESS_SUNLOCK();
1555a1619,1622
> }
> PROC_UNLOCK(p);
> PGRP_LOCK(p->p_pgrp);
> PGRPSESS_SUNLOCK();
1556a1624
> PGRP_UNLOCK(p->p_pgrp);
1730c1798,1802
< pgsignal(tp->t_pgrp, SIGTSTP, 1);
---
> if (tp->t_pgrp != NULL) {
> PGRP_LOCK(tp->t_pgrp);
> pgsignal(tp->t_pgrp, SIGTSTP, 1);
> PGRP_UNLOCK(tp->t_pgrp);
> }
1857a1930,1931
> PGRPSESS_SLOCK();
> PROC_LOCK(p);
1862a1937,1938
> PROC_UNLOCK(p);
> PGRPSESS_SUNLOCK();
1865a1942,1944
> PROC_UNLOCK(p);
> PGRP_LOCK(p->p_pgrp);
> PGRPSESS_SUNLOCK();
1866a1946
> PGRP_UNLOCK(p->p_pgrp);
1870a1951,1953
> } else {
> PROC_UNLOCK(p);
> PGRPSESS_SUNLOCK();
2331,2332d2413
< else if ((p = LIST_FIRST(&tp->t_pgrp->pg_members)) == 0)
< ttyprintf(tp, "empty foreground process group\n");
2334c2415,2421
< mtx_lock_spin(&sched_lock);
---
> PGRP_LOCK(tp->t_pgrp);
> if ((p = LIST_FIRST(&tp->t_pgrp->pg_members)) == 0) {
> PGRP_UNLOCK(tp->t_pgrp);
> ttyprintf(tp, "empty foreground process group\n");
> } else {
> PGRP_UNLOCK(tp->t_pgrp);
> mtx_lock_spin(&sched_lock);
2336,2339c2423,2426
< /* Pick interesting process. */
< for (pick = NULL; p != 0; p = LIST_NEXT(p, p_pglist))
< if (proc_compare(pick, p))
< pick = p;
---
> /* Pick interesting process. */
> for (pick = NULL; p != 0; p = LIST_NEXT(p, p_pglist))
> if (proc_compare(pick, p))
> pick = p;
2341,2348c2428,2435
< td = FIRST_THREAD_IN_PROC(pick);
< stmp = pick->p_stat == SRUN ? "running" : /* XXXKSE */
< td->td_wmesg ? td->td_wmesg : "iowait";
< calcru(pick, &utime, &stime, NULL);
< ltmp = pick->p_stat == SIDL || pick->p_stat == SWAIT ||
< pick->p_stat == SZOMB ? 0 :
< pgtok(vmspace_resident_count(pick->p_vmspace));
< mtx_unlock_spin(&sched_lock);
---
> td = FIRST_THREAD_IN_PROC(pick);
> stmp = pick->p_stat == SRUN ? "running" : /* XXXKSE */
> td->td_wmesg ? td->td_wmesg : "iowait";
> calcru(pick, &utime, &stime, NULL);
> ltmp = pick->p_stat == SIDL || pick->p_stat == SWAIT ||
> pick->p_stat == SZOMB ? 0 :
> pgtok(vmspace_resident_count(pick->p_vmspace));
> mtx_unlock_spin(&sched_lock);
2350,2351c2437,2438
< ttyprintf(tp, " cmd: %s %d [%s] ", pick->p_comm, pick->p_pid,
< stmp);
---
> ttyprintf(tp, " cmd: %s %d [%s] ", pick->p_comm, pick->p_pid,
> stmp);
2353,2355c2440,2442
< /* Print user time. */
< ttyprintf(tp, "%ld.%02ldu ",
< (long)utime.tv_sec, utime.tv_usec / 10000);
---
> /* Print user time. */
> ttyprintf(tp, "%lld.%02ldu ",
> utime.tv_sec, utime.tv_usec / 10000);
2357,2359c2444,2446
< /* Print system time. */
< ttyprintf(tp, "%ld.%02lds ",
< (long)stime.tv_sec, stime.tv_usec / 10000);
---
> /* Print system time. */
> ttyprintf(tp, "%ld.%02lds ",
> (long)stime.tv_sec, stime.tv_usec / 10000);
2361,2362c2448,2451
< /* Print percentage cpu, resident set size. */
< ttyprintf(tp, "%d%% %ldk\n", tmp / 100, ltmp);
---
> /* Print percentage cpu, resident set size. */
> ttyprintf(tp, "%d%% %ldk\n", tmp / 100, ltmp);
>
> }
< * $FreeBSD: head/sys/kern/tty.c 90375 2002-02-07 23:06:26Z peter $
---
> * $FreeBSD: head/sys/kern/tty.c 91140 2002-02-23 11:12:57Z tanimura $
77a78
> #include <sys/sx.h>
331c332,336
< pgsignal(tp->t_pgrp, SIGINT, 1);
---
> if (tp->t_pgrp != NULL) {
> PGRP_LOCK(tp->t_pgrp);
> pgsignal(tp->t_pgrp, SIGINT, 1);
> PGRP_UNLOCK(tp->t_pgrp);
> }
409,410c414,419
< pgsignal(tp->t_pgrp,
< CCEQ(cc[VINTR], c) ? SIGINT : SIGQUIT, 1);
---
> if (tp->t_pgrp != NULL) {
> PGRP_LOCK(tp->t_pgrp);
> pgsignal(tp->t_pgrp,
> CCEQ(cc[VINTR], c) ? SIGINT : SIGQUIT, 1);
> PGRP_UNLOCK(tp->t_pgrp);
> }
417c426,430
< pgsignal(tp->t_pgrp, SIGTSTP, 1);
---
> if (tp->t_pgrp != NULL) {
> PGRP_LOCK(tp->t_pgrp);
> pgsignal(tp->t_pgrp, SIGTSTP, 1);
> PGRP_UNLOCK(tp->t_pgrp);
> }
535c548,549
< if (ISSET(lflag, ISIG))
---
> if (ISSET(lflag, ISIG) && tp->t_pgrp != NULL) {
> PGRP_LOCK(tp->t_pgrp);
536a551,552
> PGRP_UNLOCK(tp->t_pgrp);
> }
754a771,772
> PGRPSESS_SLOCK();
> PROC_LOCK(p);
758c776,778
< if (p->p_pgrp->pg_jobc == 0)
---
> if (p->p_pgrp->pg_jobc == 0) {
> PROC_UNLOCK(p);
> PGRPSESS_SUNLOCK();
759a780,782
> }
> PROC_UNLOCK(p);
> PGRP_LOCK(p->p_pgrp);
760a784
> PGRP_UNLOCK(p->p_pgrp);
763c787,788
< if (error)
---
> if (error) {
> PGRPSESS_SUNLOCK();
764a790,791
> }
> PROC_LOCK(p);
765a793,794
> PROC_UNLOCK(p);
> PGRPSESS_SUNLOCK();
1014a1044
> PGRPSESS_XLOCK();
1017c1047,1048
< (tp->t_session != p->p_session)))
---
> (tp->t_session != p->p_session))) {
> PGRPSESS_XUNLOCK();
1018a1050
> }
1020a1053
> SESS_LOCK(p->p_session);
1021a1055,1056
> SESS_UNLOCK(p->p_session);
> PROC_LOCK(p);
1022a1058,1059
> PROC_UNLOCK(p);
> PGRPSESS_XUNLOCK();
1025c1062
< register struct pgrp *pgrp = pgfind(*(int *)data);
---
> register struct pgrp *pgrp;
1027c1064,1069
< if (!isctty(p, tp))
---
> PGRPSESS_SLOCK();
> pgrp = pgfind(*(int *)data);
> if (!isctty(p, tp)) {
> if (pgrp != NULL)
> PGRP_UNLOCK(pgrp);
> PGRPSESS_SUNLOCK();
1029c1071,1073
< else if (pgrp == NULL || pgrp->pg_session != p->p_session)
---
> }
> if (pgrp == NULL) {
> PGRPSESS_SUNLOCK();
1030a1075,1081
> }
> PGRP_UNLOCK(pgrp);
> if (pgrp->pg_session != p->p_session) {
> PGRPSESS_SUNLOCK();
> return (EPERM);
> }
> PGRPSESS_SUNLOCK();
1043c1094,1098
< pgsignal(tp->t_pgrp, SIGWINCH, 1);
---
> if (tp->t_pgrp != NULL) {
> PGRP_LOCK(tp->t_pgrp);
> pgsignal(tp->t_pgrp, SIGWINCH, 1);
> PGRP_UNLOCK(tp->t_pgrp);
> }
1462,1463c1517,1520
< if (tp->t_session && tp->t_session->s_leader) {
< struct proc *p;
---
> if (tp->t_session) {
> PGRPSESS_SLOCK();
> if (tp->t_session->s_leader) {
> struct proc *p;
1465,1468c1522,1527
< p = tp->t_session->s_leader;
< PROC_LOCK(p);
< psignal(p, SIGHUP);
< PROC_UNLOCK(p);
---
> p = tp->t_session->s_leader;
> PROC_LOCK(p);
> psignal(p, SIGHUP);
> PROC_UNLOCK(p);
> }
> PGRPSESS_SUNLOCK();
1551a1611,1612
> PGRPSESS_SLOCK();
> PROC_LOCK(p);
1554c1615,1617
< (p->p_flag & P_PPWAIT) || p->p_pgrp->pg_jobc == 0)
---
> (p->p_flag & P_PPWAIT) || p->p_pgrp->pg_jobc == 0) {
> PROC_UNLOCK(p);
> PGRPSESS_SUNLOCK();
1555a1619,1622
> }
> PROC_UNLOCK(p);
> PGRP_LOCK(p->p_pgrp);
> PGRPSESS_SUNLOCK();
1556a1624
> PGRP_UNLOCK(p->p_pgrp);
1730c1798,1802
< pgsignal(tp->t_pgrp, SIGTSTP, 1);
---
> if (tp->t_pgrp != NULL) {
> PGRP_LOCK(tp->t_pgrp);
> pgsignal(tp->t_pgrp, SIGTSTP, 1);
> PGRP_UNLOCK(tp->t_pgrp);
> }
1857a1930,1931
> PGRPSESS_SLOCK();
> PROC_LOCK(p);
1862a1937,1938
> PROC_UNLOCK(p);
> PGRPSESS_SUNLOCK();
1865a1942,1944
> PROC_UNLOCK(p);
> PGRP_LOCK(p->p_pgrp);
> PGRPSESS_SUNLOCK();
1866a1946
> PGRP_UNLOCK(p->p_pgrp);
1870a1951,1953
> } else {
> PROC_UNLOCK(p);
> PGRPSESS_SUNLOCK();
2331,2332d2413
< else if ((p = LIST_FIRST(&tp->t_pgrp->pg_members)) == 0)
< ttyprintf(tp, "empty foreground process group\n");
2334c2415,2421
< mtx_lock_spin(&sched_lock);
---
> PGRP_LOCK(tp->t_pgrp);
> if ((p = LIST_FIRST(&tp->t_pgrp->pg_members)) == 0) {
> PGRP_UNLOCK(tp->t_pgrp);
> ttyprintf(tp, "empty foreground process group\n");
> } else {
> PGRP_UNLOCK(tp->t_pgrp);
> mtx_lock_spin(&sched_lock);
2336,2339c2423,2426
< /* Pick interesting process. */
< for (pick = NULL; p != 0; p = LIST_NEXT(p, p_pglist))
< if (proc_compare(pick, p))
< pick = p;
---
> /* Pick interesting process. */
> for (pick = NULL; p != 0; p = LIST_NEXT(p, p_pglist))
> if (proc_compare(pick, p))
> pick = p;
2341,2348c2428,2435
< td = FIRST_THREAD_IN_PROC(pick);
< stmp = pick->p_stat == SRUN ? "running" : /* XXXKSE */
< td->td_wmesg ? td->td_wmesg : "iowait";
< calcru(pick, &utime, &stime, NULL);
< ltmp = pick->p_stat == SIDL || pick->p_stat == SWAIT ||
< pick->p_stat == SZOMB ? 0 :
< pgtok(vmspace_resident_count(pick->p_vmspace));
< mtx_unlock_spin(&sched_lock);
---
> td = FIRST_THREAD_IN_PROC(pick);
> stmp = pick->p_stat == SRUN ? "running" : /* XXXKSE */
> td->td_wmesg ? td->td_wmesg : "iowait";
> calcru(pick, &utime, &stime, NULL);
> ltmp = pick->p_stat == SIDL || pick->p_stat == SWAIT ||
> pick->p_stat == SZOMB ? 0 :
> pgtok(vmspace_resident_count(pick->p_vmspace));
> mtx_unlock_spin(&sched_lock);
2350,2351c2437,2438
< ttyprintf(tp, " cmd: %s %d [%s] ", pick->p_comm, pick->p_pid,
< stmp);
---
> ttyprintf(tp, " cmd: %s %d [%s] ", pick->p_comm, pick->p_pid,
> stmp);
2353,2355c2440,2442
< /* Print user time. */
< ttyprintf(tp, "%ld.%02ldu ",
< (long)utime.tv_sec, utime.tv_usec / 10000);
---
> /* Print user time. */
> ttyprintf(tp, "%lld.%02ldu ",
> utime.tv_sec, utime.tv_usec / 10000);
2357,2359c2444,2446
< /* Print system time. */
< ttyprintf(tp, "%ld.%02lds ",
< (long)stime.tv_sec, stime.tv_usec / 10000);
---
> /* Print system time. */
> ttyprintf(tp, "%ld.%02lds ",
> (long)stime.tv_sec, stime.tv_usec / 10000);
2361,2362c2448,2451
< /* Print percentage cpu, resident set size. */
< ttyprintf(tp, "%d%% %ldk\n", tmp / 100, ltmp);
---
> /* Print percentage cpu, resident set size. */
> ttyprintf(tp, "%d%% %ldk\n", tmp / 100, ltmp);
>
> }