Page MenuHomeFreeBSD

D31552.id93777.diff
No OneTemporary

D31552.id93777.diff

Index: sys/compat/linux/linux_misc.c
===================================================================
--- sys/compat/linux/linux_misc.c
+++ sys/compat/linux/linux_misc.c
@@ -988,35 +988,21 @@
#endif
static int
-linux_common_wait(struct thread *td, int pid, int *statusp,
- int options, struct __wrusage *wrup)
+linux_common_wait(struct thread *td, idtype_t idtype, int id, int *statusp,
+ int options, void *rup, l_siginfo_t *infop)
{
- siginfo_t siginfo;
- idtype_t idtype;
- id_t id;
- int error, status, tmpstat;
-
- if (pid == WAIT_ANY) {
- idtype = P_ALL;
- id = 0;
- } else if (pid < 0) {
- idtype = P_PGID;
- id = (id_t)-pid;
- } else {
- idtype = P_PID;
- id = (id_t)pid;
- }
+ l_siginfo_t *lsi;
+ siginfo_t *info;
+ struct __wrusage *wru;
+ int error, status, tmpstat, sig;
- /*
- * For backward compatibility we implicitly add flags WEXITED
- * and WTRAPPED here.
- */
- options |= WEXITED | WTRAPPED;
- error = kern_wait6(td, idtype, id, &status, options, wrup, &siginfo);
- if (error)
- return (error);
+ if (rup != NULL)
+ wru = malloc(sizeof(*wru), M_LINUX, M_WAITOK | M_ZERO);
+ info = malloc(sizeof(*info), M_LINUX, M_WAITOK | M_ZERO);
+ error = kern_wait6(td, idtype, id,
+ &status, options, rup != NULL ? wru : NULL, info);
- if (statusp) {
+ if (error == 0 && statusp) {
tmpstat = status & 0xffff;
if (WIFSIGNALED(tmpstat)) {
tmpstat = (tmpstat & 0xffffff80) |
@@ -1027,7 +1013,7 @@
#if defined(__amd64__) && !defined(COMPAT_LINUX32)
if (WSTOPSIG(status) == SIGTRAP) {
tmpstat = linux_ptrace_status(td,
- siginfo.si_pid, tmpstat);
+ info->si_pid, tmpstat);
}
#endif
} else if (WIFCONTINUED(tmpstat)) {
@@ -1035,7 +1021,19 @@
}
error = copyout(&tmpstat, statusp, sizeof(int));
}
+ if (error == 0 && rup != NULL)
+ error = linux_copyout_rusage(&wru->wru_self, rup);
+ if (error == 0 && infop != NULL && td->td_retval[0] != 0) {
+ lsi = malloc(sizeof(*lsi), M_LINUX, M_WAITOK | M_ZERO);
+ sig = bsd_to_linux_signal(info->si_signo);
+ siginfo_to_lsiginfo(info, lsi, sig);
+ error = copyout(lsi, infop, sizeof(*lsi));
+ free(lsi, M_LINUX);
+ }
+ if (rup != NULL)
+ free(wru, M_LINUX);
+ free(info, M_LINUX);
return (error);
}
@@ -1057,38 +1055,41 @@
int
linux_wait4(struct thread *td, struct linux_wait4_args *args)
{
- int error, options;
- struct __wrusage wru, *wrup;
+ int options, id, idtype;
if (args->options & ~(LINUX_WUNTRACED | LINUX_WNOHANG |
LINUX_WCONTINUED | __WCLONE | __WNOTHREAD | __WALL))
return (EINVAL);
- options = WEXITED;
+ options = 0;
linux_to_bsd_waitopts(args->options, &options);
- if (args->rusage != NULL)
- wrup = &wru;
- else
- wrup = NULL;
- error = linux_common_wait(td, args->pid, args->status, options, wrup);
- if (error != 0)
- return (error);
- if (args->rusage != NULL)
- error = linux_copyout_rusage(&wru.wru_self, args->rusage);
- return (error);
+ /*
+ * For backward compatibility we implicitly add flags WEXITED
+ * and WTRAPPED here.
+ */
+ options |= WEXITED | WTRAPPED;
+
+ if (args->pid == WAIT_ANY) {
+ idtype = P_ALL;
+ id = 0;
+ } else if (args->pid < 0) {
+ idtype = P_PGID;
+ id = (id_t)-args->pid;
+ } else {
+ idtype = P_PID;
+ id = (id_t)args->pid;
+ }
+
+ return (linux_common_wait(td, idtype, id, args->status, options,
+ args->rusage, NULL));
}
int
linux_waitid(struct thread *td, struct linux_waitid_args *args)
{
- int status, options, sig;
- struct __wrusage wru;
- siginfo_t siginfo;
- l_siginfo_t lsi;
idtype_t idtype;
- struct proc *p;
- int error;
+ int error, options;
options = 0;
linux_to_bsd_waitopts(args->options, &options);
@@ -1116,25 +1117,8 @@
return (EINVAL);
}
- error = kern_wait6(td, idtype, args->id, &status, options,
- &wru, &siginfo);
- if (error != 0)
- return (error);
- if (args->rusage != NULL) {
- error = linux_copyout_rusage(&wru.wru_children,
- args->rusage);
- if (error != 0)
- return (error);
- }
- if (args->info != NULL) {
- p = td->td_proc;
- bzero(&lsi, sizeof(lsi));
- if (td->td_retval[0] != 0) {
- sig = bsd_to_linux_signal(siginfo.si_signo);
- siginfo_to_lsiginfo(&siginfo, &lsi, sig);
- }
- error = copyout(&lsi, args->info, sizeof(lsi));
- }
+ error = linux_common_wait(td, idtype, args->id, NULL, options,
+ args->rusage, args->info);
td->td_retval[0] = 0;
return (error);

File Metadata

Mime Type
text/plain
Expires
Mon, May 25, 11:16 AM (11 h, 10 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
33508320
Default Alt Text
D31552.id93777.diff (4 KB)

Event Timeline