|
Lines 684-690
Link Here
|
| 684 |
* The dirty work is handled by kern_wait(). |
684 |
* The dirty work is handled by kern_wait(). |
| 685 |
*/ |
685 |
*/ |
| 686 |
int |
686 |
int |
| 687 |
sys_wait4(struct thread *td, struct wait_args *uap) |
687 |
sys_wait4(struct thread *td, struct wait4_args *uap) |
| 688 |
{ |
688 |
{ |
| 689 |
struct rusage ru, *rup; |
689 |
struct rusage ru, *rup; |
| 690 |
int error, status; |
690 |
int error, status; |
|
Lines 693-698
Link Here
|
| 693 |
rup = &ru; |
693 |
rup = &ru; |
| 694 |
else |
694 |
else |
| 695 |
rup = NULL; |
695 |
rup = NULL; |
|
|
696 |
|
| 696 |
error = kern_wait(td, uap->pid, &status, uap->options, rup); |
697 |
error = kern_wait(td, uap->pid, &status, uap->options, rup); |
| 697 |
if (uap->status != NULL && error == 0) |
698 |
if (uap->status != NULL && error == 0) |
| 698 |
error = copyout(&status, uap->status, sizeof(status)); |
699 |
error = copyout(&status, uap->status, sizeof(status)); |
|
Lines 701-714
Link Here
|
| 701 |
return (error); |
702 |
return (error); |
| 702 |
} |
703 |
} |
| 703 |
|
704 |
|
|
|
705 |
int |
| 706 |
sys_wait6(struct thread *td, struct wait6_args *uap) |
| 707 |
{ |
| 708 |
struct wrusage wru, *wrup; |
| 709 |
siginfo_t si, *sip; |
| 710 |
int error, status; |
| 711 |
idtype_t idtype; |
| 712 |
id_t id; |
| 713 |
|
| 714 |
idtype = uap->idtype; |
| 715 |
id = uap->id; |
| 716 |
|
| 717 |
if (uap->wrusage != NULL) |
| 718 |
wrup = &wru; |
| 719 |
else |
| 720 |
wrup = NULL; |
| 721 |
|
| 722 |
if (uap->info != NULL) |
| 723 |
sip = &si; |
| 724 |
else |
| 725 |
sip = NULL; |
| 726 |
|
| 727 |
/* |
| 728 |
* We expect all callers of wait6() |
| 729 |
* to know about WEXITED and WTRAPPED! |
| 730 |
*/ |
| 731 |
error = kern_wait6(td, idtype, id, &status, uap->options, wrup, sip); |
| 732 |
|
| 733 |
if (uap->status != NULL && error == 0) |
| 734 |
error = copyout(&status, uap->status, sizeof(status)); |
| 735 |
if (uap->wrusage != NULL && error == 0) |
| 736 |
error = copyout(&wru, uap->wrusage, sizeof(wru)); |
| 737 |
if (uap->info != NULL && error == 0) |
| 738 |
error = copyout(&si, uap->info, sizeof(si)); |
| 739 |
return (error); |
| 740 |
} |
| 741 |
|
| 704 |
/* |
742 |
/* |
| 705 |
* Reap the remains of a zombie process and optionally return status and |
743 |
* Reap the remains of a zombie process and optionally return status and |
| 706 |
* rusage. Asserts and will release both the proctree_lock and the process |
744 |
* rusage. Asserts and will release both the proctree_lock and the process |
| 707 |
* lock as part of its work. |
745 |
* lock as part of its work. |
| 708 |
*/ |
746 |
*/ |
| 709 |
void |
747 |
void |
| 710 |
proc_reap(struct thread *td, struct proc *p, int *status, int options, |
748 |
proc_reap(struct thread *td, struct proc *p, int *status, int options) |
| 711 |
struct rusage *rusage) |
|
|
| 712 |
{ |
749 |
{ |
| 713 |
struct proc *q, *t; |
750 |
struct proc *q, *t; |
| 714 |
|
751 |
|
|
Lines 718-727
Link Here
|
| 718 |
KASSERT(p->p_state == PRS_ZOMBIE, ("proc_reap: !PRS_ZOMBIE")); |
755 |
KASSERT(p->p_state == PRS_ZOMBIE, ("proc_reap: !PRS_ZOMBIE")); |
| 719 |
|
756 |
|
| 720 |
q = td->td_proc; |
757 |
q = td->td_proc; |
| 721 |
if (rusage) { |
758 |
|
| 722 |
*rusage = p->p_ru; |
|
|
| 723 |
calcru(p, &rusage->ru_utime, &rusage->ru_stime); |
| 724 |
} |
| 725 |
PROC_SUNLOCK(p); |
759 |
PROC_SUNLOCK(p); |
| 726 |
td->td_retval[0] = p->p_pid; |
760 |
td->td_retval[0] = p->p_pid; |
| 727 |
if (status) |
761 |
if (status) |
|
Lines 834-841
Link Here
|
| 834 |
} |
868 |
} |
| 835 |
|
869 |
|
| 836 |
static int |
870 |
static int |
| 837 |
proc_to_reap(struct thread *td, struct proc *p, pid_t pid, int *status, |
871 |
proc_to_reap(struct thread *td, struct proc *p, |
| 838 |
int options, struct rusage *rusage) |
872 |
idtype_t idtype, id_t id, |
|
|
873 |
int *status, int options, |
| 874 |
struct wrusage *wrusage, siginfo_t *siginfo) |
| 839 |
{ |
875 |
{ |
| 840 |
struct proc *q; |
876 |
struct proc *q; |
| 841 |
|
877 |
|
|
Lines 843-857
Link Here
|
| 843 |
|
879 |
|
| 844 |
q = td->td_proc; |
880 |
q = td->td_proc; |
| 845 |
PROC_LOCK(p); |
881 |
PROC_LOCK(p); |
| 846 |
if (pid != WAIT_ANY && p->p_pid != pid && p->p_pgid != -pid) { |
882 |
|
|
|
883 |
switch (idtype) { |
| 884 |
case P_ALL: |
| 885 |
break; |
| 886 |
case P_PID: |
| 887 |
if (p->p_pid != (pid_t) id) { |
| 888 |
PROC_UNLOCK(p); |
| 889 |
return (0); |
| 890 |
} |
| 891 |
break; |
| 892 |
case P_PGID: |
| 893 |
if (p->p_pgid != (pid_t) id) { |
| 894 |
PROC_UNLOCK(p); |
| 895 |
return (0); |
| 896 |
} |
| 897 |
break; |
| 898 |
case P_SID: |
| 899 |
if (p->p_session->s_sid != (pid_t) id) { |
| 900 |
PROC_UNLOCK(p); |
| 901 |
return (0); |
| 902 |
} |
| 903 |
break; |
| 904 |
case P_UID: |
| 905 |
if (p->p_ucred->cr_uid != (uid_t) id) { |
| 906 |
PROC_UNLOCK(p); |
| 907 |
return (0); |
| 908 |
} |
| 909 |
break; |
| 910 |
case P_GID: |
| 911 |
if (p->p_ucred->cr_gid != (gid_t) id) { |
| 912 |
PROC_UNLOCK(p); |
| 913 |
return (0); |
| 914 |
} |
| 915 |
break; |
| 916 |
case P_ZONEID: /* jail */ |
| 917 |
if (! p->p_ucred->cr_prison || |
| 918 |
(p->p_ucred->cr_prison->pr_id != (int) id)) { |
| 919 |
PROC_UNLOCK(p); |
| 920 |
return (0); |
| 921 |
} |
| 922 |
break; |
| 923 |
#if 0 |
| 924 |
/* |
| 925 |
* It seems that the thread structures get zeroed out |
| 926 |
* at process exit. |
| 927 |
* This makes toast of all useful info related to |
| 928 |
* CPU, CPU set, and scheduling priority class. |
| 929 |
*/ |
| 930 |
case P_PSETID: |
| 931 |
{ |
| 932 |
struct thread *td1; |
| 933 |
|
| 934 |
td1 = FIRST_THREAD_IN_PROC(p); |
| 935 |
if (td1->td_cpuset->cs_id != (cpusetid_t) id) { |
| 936 |
PROC_UNLOCK(p); |
| 937 |
return (0); |
| 938 |
} |
| 939 |
} |
| 940 |
break; |
| 941 |
case P_CID: |
| 942 |
{ |
| 943 |
struct thread *td1; |
| 944 |
|
| 945 |
td1 = FIRST_THREAD_IN_PROC(p); |
| 946 |
if (td1->td_pri_class != (unsigned) id) { |
| 947 |
PROC_UNLOCK(p); |
| 948 |
return (0); |
| 949 |
} |
| 950 |
} |
| 951 |
break; |
| 952 |
case P_CPUID: |
| 953 |
{ |
| 954 |
struct thread *td1; |
| 955 |
|
| 956 |
td1 = FIRST_THREAD_IN_PROC(p); |
| 957 |
if (td1->td_lastcpu != (unsigned) id) { |
| 958 |
PROC_UNLOCK(p); |
| 959 |
return (0); |
| 960 |
} |
| 961 |
} |
| 962 |
break; |
| 963 |
#endif |
| 964 |
|
| 965 |
default: |
| 847 |
PROC_UNLOCK(p); |
966 |
PROC_UNLOCK(p); |
| 848 |
return (0); |
967 |
return (0); |
|
|
968 |
break; |
| 849 |
} |
969 |
} |
|
|
970 |
|
| 850 |
if (p_canwait(td, p)) { |
971 |
if (p_canwait(td, p)) { |
| 851 |
PROC_UNLOCK(p); |
972 |
PROC_UNLOCK(p); |
| 852 |
return (0); |
973 |
return (0); |
| 853 |
} |
974 |
} |
| 854 |
|
975 |
|
|
|
976 |
if (((options & WEXITED) == 0) && (p->p_state == PRS_ZOMBIE)) { |
| 977 |
PROC_UNLOCK(p); |
| 978 |
return (0); |
| 979 |
} |
| 980 |
|
| 855 |
/* |
981 |
/* |
| 856 |
* This special case handles a kthread spawned by linux_clone |
982 |
* This special case handles a kthread spawned by linux_clone |
| 857 |
* (see linux_misc.c). The linux_wait4 and linux_waitpid |
983 |
* (see linux_misc.c). The linux_wait4 and linux_waitpid |
|
Lines 867-874
Link Here
|
| 867 |
} |
993 |
} |
| 868 |
|
994 |
|
| 869 |
PROC_SLOCK(p); |
995 |
PROC_SLOCK(p); |
|
|
996 |
|
| 997 |
if (siginfo) { |
| 998 |
bzero (siginfo, sizeof (*siginfo)); |
| 999 |
siginfo->si_signo = SIGCHLD; |
| 1000 |
siginfo->si_errno = 0; |
| 1001 |
|
| 1002 |
/* |
| 1003 |
* Right, this is still a rough estimate. |
| 1004 |
* We will fix the cases TRAPPED, STOPPED, |
| 1005 |
* and CONTINUED later. |
| 1006 |
*/ |
| 1007 |
|
| 1008 |
if (WCOREDUMP(p->p_xstat)) |
| 1009 |
siginfo->si_code = CLD_DUMPED; |
| 1010 |
else if (WIFSIGNALED(p->p_xstat)) |
| 1011 |
siginfo->si_code = CLD_KILLED; |
| 1012 |
else |
| 1013 |
siginfo->si_code = CLD_EXITED; |
| 1014 |
|
| 1015 |
siginfo->si_pid = p->p_pid; |
| 1016 |
siginfo->si_uid = p->p_ucred->cr_uid; |
| 1017 |
siginfo->si_status = p->p_xstat; |
| 1018 |
|
| 1019 |
/* |
| 1020 |
* The si_addr field would be useful additional detail, |
| 1021 |
* but apparently the PC value may be lost when we reach |
| 1022 |
* this point. |
| 1023 |
* bzero() above sets siginfo->si_addr to NULL. |
| 1024 |
*/ |
| 1025 |
} |
| 1026 |
|
| 1027 |
/* |
| 1028 |
* There should be no reason to limit resources usage info |
| 1029 |
* to exited processes only. |
| 1030 |
* A snapshot about any resources used by a stopped process |
| 1031 |
* may be exactly what is needed. |
| 1032 |
* We are now within the same PROC_SLOCK anyway. |
| 1033 |
*/ |
| 1034 |
|
| 1035 |
if (wrusage) { |
| 1036 |
#if 0 |
| 1037 |
*rusage = p->p_ru; |
| 1038 |
calcru(p, &rusage->ru_utime, &rusage->ru_stime); |
| 1039 |
#endif |
| 1040 |
struct rusage *rup; |
| 1041 |
|
| 1042 |
rup = &wrusage->wru_self; |
| 1043 |
*rup = p->p_ru; |
| 1044 |
calcru(p, &rup->ru_utime, &rup->ru_stime); |
| 1045 |
|
| 1046 |
rup = &wrusage->wru_children; |
| 1047 |
*rup = p->p_stats->p_cru; |
| 1048 |
calccru(p, &rup->ru_utime, &rup->ru_stime); |
| 1049 |
} |
| 1050 |
|
| 870 |
if (p->p_state == PRS_ZOMBIE) { |
1051 |
if (p->p_state == PRS_ZOMBIE) { |
| 871 |
proc_reap(td, p, status, options, rusage); |
1052 |
proc_reap(td, p, status, options); |
| 872 |
return (-1); |
1053 |
return (-1); |
| 873 |
} |
1054 |
} |
| 874 |
PROC_SUNLOCK(p); |
1055 |
PROC_SUNLOCK(p); |
|
Lines 877-900
Link Here
|
| 877 |
} |
1058 |
} |
| 878 |
|
1059 |
|
| 879 |
int |
1060 |
int |
| 880 |
kern_wait(struct thread *td, pid_t pid, int *status, int options, |
1061 |
kern_wait(struct thread *td, pid_t pid, |
| 881 |
struct rusage *rusage) |
1062 |
int *status, int options, struct rusage *rusage) |
|
|
1063 |
{ |
| 1064 |
struct wrusage wru, *wrup; |
| 1065 |
idtype_t idtype; |
| 1066 |
id_t id; |
| 1067 |
int ret; |
| 1068 |
|
| 1069 |
if (pid == WAIT_ANY) { |
| 1070 |
idtype = P_ALL; |
| 1071 |
id = 0; |
| 1072 |
} |
| 1073 |
else if (pid <= 0) { |
| 1074 |
idtype = P_PGID; |
| 1075 |
id = (id_t)-pid; |
| 1076 |
} |
| 1077 |
else { |
| 1078 |
idtype = P_PID; |
| 1079 |
id = (id_t)pid; |
| 1080 |
} |
| 1081 |
|
| 1082 |
if (rusage) |
| 1083 |
wrup = &wru; |
| 1084 |
else |
| 1085 |
wrup = NULL; |
| 1086 |
|
| 1087 |
/* |
| 1088 |
* For backward compatibility we implicitly |
| 1089 |
* add flags WEXITED and WTRAPPED here. |
| 1090 |
*/ |
| 1091 |
options |= (WEXITED | WTRAPPED); |
| 1092 |
|
| 1093 |
ret = kern_wait6 (td, idtype, id, status, options, wrup, NULL); |
| 1094 |
|
| 1095 |
if (rusage) |
| 1096 |
*rusage = wru.wru_self; |
| 1097 |
|
| 1098 |
return (ret); |
| 1099 |
} |
| 1100 |
|
| 1101 |
int |
| 1102 |
kern_wait6(struct thread *td, idtype_t idtype, id_t id, |
| 1103 |
int *status, int options, |
| 1104 |
struct wrusage *wrusage, siginfo_t *siginfo) |
| 882 |
{ |
1105 |
{ |
| 883 |
struct proc *p, *q; |
1106 |
struct proc *p, *q; |
| 884 |
int error, nfound, ret; |
1107 |
int error, nfound, ret; |
| 885 |
|
1108 |
|
| 886 |
AUDIT_ARG_PID(pid); |
1109 |
AUDIT_ARG_VALUE((int)idtype); /* XXX - This is likely wrong! */ |
|
|
1110 |
AUDIT_ARG_PID((pid_t)id); /* XXX - This may be wrong! */ |
| 887 |
AUDIT_ARG_VALUE(options); |
1111 |
AUDIT_ARG_VALUE(options); |
| 888 |
|
1112 |
|
| 889 |
q = td->td_proc; |
1113 |
q = td->td_proc; |
| 890 |
if (pid == 0) { |
1114 |
|
|
|
1115 |
if (((pid_t)id == WAIT_MYPGRP) && |
| 1116 |
((idtype == P_PID) || (idtype == P_PGID))) { |
| 891 |
PROC_LOCK(q); |
1117 |
PROC_LOCK(q); |
| 892 |
pid = -q->p_pgid; |
1118 |
id = (id_t)q->p_pgid; |
| 893 |
PROC_UNLOCK(q); |
1119 |
PROC_UNLOCK(q); |
|
|
1120 |
idtype = P_PGID; |
| 894 |
} |
1121 |
} |
|
|
1122 |
|
| 895 |
/* If we don't know the option, just return. */ |
1123 |
/* If we don't know the option, just return. */ |
| 896 |
if (options & ~(WUNTRACED|WNOHANG|WCONTINUED|WNOWAIT|WLINUXCLONE)) |
1124 |
if (options & ~(WUNTRACED|WNOHANG|WCONTINUED| |
|
|
1125 |
WNOWAIT|WEXITED|WTRAPPED|WLINUXCLONE)) |
| 897 |
return (EINVAL); |
1126 |
return (EINVAL); |
|
|
1127 |
|
| 1128 |
if ((options & (WEXITED|WUNTRACED|WCONTINUED|WTRAPPED)) == 0) { |
| 1129 |
/* |
| 1130 |
* We will be unable to find any matching processes, |
| 1131 |
* because there are no known events to look for. |
| 1132 |
* Tell the programmer (s)he is doing something |
| 1133 |
* patently dysfunctional. |
| 1134 |
*/ |
| 1135 |
return (EINVAL); |
| 1136 |
} |
| 1137 |
|
| 898 |
loop: |
1138 |
loop: |
| 899 |
if (q->p_flag & P_STATCHILD) { |
1139 |
if (q->p_flag & P_STATCHILD) { |
| 900 |
PROC_LOCK(q); |
1140 |
PROC_LOCK(q); |
|
Lines 904-910
Link Here
|
| 904 |
nfound = 0; |
1144 |
nfound = 0; |
| 905 |
sx_xlock(&proctree_lock); |
1145 |
sx_xlock(&proctree_lock); |
| 906 |
LIST_FOREACH(p, &q->p_children, p_sibling) { |
1146 |
LIST_FOREACH(p, &q->p_children, p_sibling) { |
| 907 |
ret = proc_to_reap(td, p, pid, status, options, rusage); |
1147 |
ret = proc_to_reap(td, p, idtype, id, |
|
|
1148 |
status, options, wrusage, siginfo); |
| 908 |
if (ret == 0) |
1149 |
if (ret == 0) |
| 909 |
continue; |
1150 |
continue; |
| 910 |
else if (ret == 1) |
1151 |
else if (ret == 1) |
|
Lines 914-950
Link Here
|
| 914 |
|
1155 |
|
| 915 |
PROC_LOCK(p); |
1156 |
PROC_LOCK(p); |
| 916 |
PROC_SLOCK(p); |
1157 |
PROC_SLOCK(p); |
| 917 |
if ((p->p_flag & P_STOPPED_SIG) && |
1158 |
|
|
|
1159 |
if ((options & WTRAPPED) && |
| 1160 |
(p->p_flag & P_TRACED) && |
| 1161 |
(p->p_flag & (P_STOPPED_TRACE | P_STOPPED_SIG)) && |
| 918 |
(p->p_suspcount == p->p_numthreads) && |
1162 |
(p->p_suspcount == p->p_numthreads) && |
| 919 |
(p->p_flag & P_WAITED) == 0 && |
1163 |
((p->p_flag & P_WAITED) == 0)) { |
| 920 |
(p->p_flag & P_TRACED || options & WUNTRACED)) { |
|
|
| 921 |
PROC_SUNLOCK(p); |
1164 |
PROC_SUNLOCK(p); |
| 922 |
p->p_flag |= P_WAITED; |
1165 |
|
|
|
1166 |
if ((options & WNOWAIT) == 0) |
| 1167 |
p->p_flag |= P_WAITED; |
| 1168 |
|
| 923 |
sx_xunlock(&proctree_lock); |
1169 |
sx_xunlock(&proctree_lock); |
| 924 |
td->td_retval[0] = p->p_pid; |
1170 |
td->td_retval[0] = p->p_pid; |
|
|
1171 |
|
| 925 |
if (status) |
1172 |
if (status) |
| 926 |
*status = W_STOPCODE(p->p_xstat); |
1173 |
*status = W_STOPCODE(p->p_xstat); |
|
|
1174 |
if (siginfo) { |
| 1175 |
siginfo->si_status = W_STOPCODE(p->p_xstat); |
| 1176 |
siginfo->si_code = CLD_TRAPPED; |
| 1177 |
} |
| 1178 |
if ((options & WNOWAIT) == 0) { |
| 1179 |
PROC_LOCK(q); |
| 1180 |
sigqueue_take(p->p_ksi); |
| 1181 |
PROC_UNLOCK(q); |
| 1182 |
} |
| 927 |
|
1183 |
|
| 928 |
PROC_LOCK(q); |
|
|
| 929 |
sigqueue_take(p->p_ksi); |
| 930 |
PROC_UNLOCK(q); |
| 931 |
PROC_UNLOCK(p); |
1184 |
PROC_UNLOCK(p); |
|
|
1185 |
return (0); |
| 1186 |
} |
| 1187 |
if ((options & WUNTRACED) && |
| 1188 |
(p->p_flag & P_STOPPED_SIG) && |
| 1189 |
(p->p_suspcount == p->p_numthreads) && |
| 1190 |
((p->p_flag & P_WAITED) == 0)) { |
| 1191 |
PROC_SUNLOCK(p); |
| 1192 |
|
| 1193 |
if ((options & WNOWAIT) == 0) |
| 1194 |
p->p_flag |= P_WAITED; |
| 1195 |
|
| 1196 |
sx_xunlock(&proctree_lock); |
| 1197 |
td->td_retval[0] = p->p_pid; |
| 1198 |
|
| 1199 |
if (status) |
| 1200 |
*status = W_STOPCODE(p->p_xstat); |
| 1201 |
if (siginfo) { |
| 1202 |
siginfo->si_status = W_STOPCODE(p->p_xstat); |
| 1203 |
siginfo->si_code = CLD_STOPPED; |
| 1204 |
} |
| 1205 |
if ((options & WNOWAIT) == 0) { |
| 1206 |
PROC_LOCK(q); |
| 1207 |
sigqueue_take(p->p_ksi); |
| 1208 |
PROC_UNLOCK(q); |
| 1209 |
} |
| 932 |
|
1210 |
|
|
|
1211 |
PROC_UNLOCK(p); |
| 933 |
return (0); |
1212 |
return (0); |
| 934 |
} |
1213 |
} |
| 935 |
PROC_SUNLOCK(p); |
1214 |
PROC_SUNLOCK(p); |
| 936 |
if (options & WCONTINUED && (p->p_flag & P_CONTINUED)) { |
1215 |
if (options & WCONTINUED && (p->p_flag & P_CONTINUED)) { |
| 937 |
sx_xunlock(&proctree_lock); |
1216 |
sx_xunlock(&proctree_lock); |
| 938 |
td->td_retval[0] = p->p_pid; |
1217 |
td->td_retval[0] = p->p_pid; |
| 939 |
p->p_flag &= ~P_CONTINUED; |
|
|
| 940 |
|
1218 |
|
| 941 |
PROC_LOCK(q); |
1219 |
if ((options & WNOWAIT) == 0) { |
| 942 |
sigqueue_take(p->p_ksi); |
1220 |
p->p_flag &= ~P_CONTINUED; |
| 943 |
PROC_UNLOCK(q); |
1221 |
|
|
|
1222 |
PROC_LOCK(q); |
| 1223 |
sigqueue_take(p->p_ksi); |
| 1224 |
PROC_UNLOCK(q); |
| 1225 |
} |
| 1226 |
|
| 944 |
PROC_UNLOCK(p); |
1227 |
PROC_UNLOCK(p); |
| 945 |
|
1228 |
|
| 946 |
if (status) |
1229 |
if (status) |
| 947 |
*status = SIGCONT; |
1230 |
*status = SIGCONT; |
|
|
1231 |
if (siginfo) { |
| 1232 |
siginfo->si_status = SIGCONT; |
| 1233 |
siginfo->si_code = CLD_CONTINUED; |
| 1234 |
} |
| 1235 |
|
| 948 |
return (0); |
1236 |
return (0); |
| 949 |
} |
1237 |
} |
| 950 |
PROC_UNLOCK(p); |
1238 |
PROC_UNLOCK(p); |
|
Lines 963-969
Link Here
|
| 963 |
* to successfully wait until the child becomes a zombie. |
1251 |
* to successfully wait until the child becomes a zombie. |
| 964 |
*/ |
1252 |
*/ |
| 965 |
LIST_FOREACH(p, &q->p_orphans, p_orphan) { |
1253 |
LIST_FOREACH(p, &q->p_orphans, p_orphan) { |
| 966 |
ret = proc_to_reap(td, p, pid, status, options, rusage); |
1254 |
ret = proc_to_reap(td, p, idtype, id, |
|
|
1255 |
status, options, wrusage, siginfo); |
| 967 |
if (ret == 0) |
1256 |
if (ret == 0) |
| 968 |
continue; |
1257 |
continue; |
| 969 |
else if (ret == 1) |
1258 |
else if (ret == 1) |
|
Lines 977-982
Link Here
|
| 977 |
} |
1266 |
} |
| 978 |
if (options & WNOHANG) { |
1267 |
if (options & WNOHANG) { |
| 979 |
sx_xunlock(&proctree_lock); |
1268 |
sx_xunlock(&proctree_lock); |
|
|
1269 |
/* |
| 1270 |
* The only way for the caller of waitid() to know, |
| 1271 |
* whether a processes was found or not, is by checking |
| 1272 |
* the siginfo fields si_signo and si_pid. |
| 1273 |
* According to SUS waitid() shall return only 0, |
| 1274 |
* not the pid, when a process has changed state. |
| 1275 |
* Thus the 0 return value does not differentiate |
| 1276 |
* between found or not, but only whether there was |
| 1277 |
* an error or not. |
| 1278 |
* Because proc_to_reap() above may have modified |
| 1279 |
* siginfo we clear it now. |
| 1280 |
*/ |
| 1281 |
if (siginfo) |
| 1282 |
bzero (siginfo, sizeof (*siginfo)); |
| 980 |
td->td_retval[0] = 0; |
1283 |
td->td_retval[0] = 0; |
| 981 |
return (0); |
1284 |
return (0); |
| 982 |
} |
1285 |
} |