From nobody Fri Jun 17 19:38:42 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4E3D285B752; Fri, 17 Jun 2022 19:38:43 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4LPq8z1ZTcz3QSR; Fri, 17 Jun 2022 19:38:43 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1655494723; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Lv61cSX8XP3zO8tCyd2sXacQbhhaehOzPM8H6URIrbA=; b=iameLNRyrxAzWSy2rp8NhuIktMZ38rObjqQbT5HgVBfGHwh79wE0DZ3bnBZB34DizeGbXY 995/5m7NhYAMcLYbwNYfBgJXW4UNDfSUfWVYZeviXb0+0QeyGrEVvkjdCrvkTRdqHYSAib GZv/k85VKvwqax3T8c468B3PkwgzJmtIZWmTH7o9VsFL0P9vnEr/shnRUSX6i2WsmsM8n4 GqHdUNl4fGJxGZp5ULi3QyR4tLRPoNjJETQh74oMop9Pmlij9N3spoiljFsP84XMfJOTGG xeXX1nan1LHRiGOO82zpyqQsj/DzmSCjA2Fyy80ShlMNKTVlb9sMHWRA5TqGVQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 142DD259C3; Fri, 17 Jun 2022 19:38:43 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 25HJcgkB015055; Fri, 17 Jun 2022 19:38:42 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 25HJcg57015054; Fri, 17 Jun 2022 19:38:42 GMT (envelope-from git) Date: Fri, 17 Jun 2022 19:38:42 GMT Message-Id: <202206171938.25HJcg57015054@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Dmitry Chagin Subject: git: 721dcd87abe3 - stable/13 - linux(4): Consolidate wait* facility into linux_common_wait(). List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: dchagin X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 721dcd87abe32cd051c3dfdb64e59ca1ef03cb83 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1655494723; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Lv61cSX8XP3zO8tCyd2sXacQbhhaehOzPM8H6URIrbA=; b=yZFWdpQrgv68s47SxJrPIyah7C1OG6kh9MHChaRAgVfh1Um7xd42ZfKBYy39CcS2TqsEIO hud7etXL7xe3foXqgZcUqT9d3l3Vfig5BnXsviaGWqdZYMnxnq7VQUtVNhX3cBlYkLf7vg J53pigWe4lKuBJt0S5ICoGMoz5a0RAPdAt3SfFTkv+7NqN+Yas8Tfa9kVc4DsRBrLVYPsG kOoa2uuaeEygRHRVetyJGEzXJdMF0uVrMTpvI4HlcwOt76tOJsEnt9Hz+EI/X9asCT2Jdb 2X+1IXgu46u8Jh0eP3nlOZji/WjqLkEsRWaxNkx0Zqwk6IFi9+mmyVkpXI0zCw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1655494723; a=rsa-sha256; cv=none; b=Znac6yTFdFk6DozKKABF1nIlwastOtoXKGhHAsCWaKK7FwL7TfWtMwr/2WnLsRijkerv4Y LnmVY1npYSShsE5WnUCzfm3ZPOtqBdC9Ish6l3zwCpj9FTkD1TZxiQjb6Q+yqNzZ22MARr NllCgbq63ISO593CqLuHj/P8CaiZHly9Z8jZTiXGabhZkjZXQsLmYXVNbv5qNQtYtYXnav fMktfYmiTCzXA6k5KPi40qlFl+LtSHFN3P+SMGEkpTjAMO2ncCRYZKkM8GEVvkE9xy+b6i MbGM2s+f+QaFI6rTzX593C5fhMWyo8NT3I6GMxFBPt1P8jmj2N25LC9bYthoug== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by dchagin: URL: https://cgit.FreeBSD.org/src/commit/?id=721dcd87abe32cd051c3dfdb64e59ca1ef03cb83 commit 721dcd87abe32cd051c3dfdb64e59ca1ef03cb83 Author: Dmitry Chagin AuthorDate: 2022-03-31 17:40:22 +0000 Commit: Dmitry Chagin CommitDate: 2022-06-17 19:33:44 +0000 linux(4): Consolidate wait* facility into linux_common_wait(). Also fix bug in waitid() implementation, use wru_self not wru_children. Differential revision: https://reviews.freebsd.org/D31552 MFC after: 2 weeks (cherry picked from commit 0c6b1ff7de56ccaef9bb22bacfd69b07ab4aeb8a) --- sys/compat/linux/linux_misc.c | 107 ++++++++++++++++++------------------------ 1 file changed, 46 insertions(+), 61 deletions(-) diff --git a/sys/compat/linux/linux_misc.c b/sys/compat/linux/linux_misc.c index f4a2d3bbde4b..45e395acd6aa 100644 --- a/sys/compat/linux/linux_misc.c +++ b/sys/compat/linux/linux_misc.c @@ -988,35 +988,18 @@ linux_futimesat(struct thread *td, struct linux_futimesat_args *args) #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) { + l_siginfo_t lsi; 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; - } + 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); + error = kern_wait6(td, idtype, id, &status, options, + rup != NULL ? &wru : NULL, &siginfo); - if (statusp) { + if (error == 0 && statusp) { tmpstat = status & 0xffff; if (WIFSIGNALED(tmpstat)) { tmpstat = (tmpstat & 0xffffff80) | @@ -1035,6 +1018,13 @@ linux_common_wait(struct thread *td, int pid, int *statusp, } 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) { + sig = bsd_to_linux_signal(siginfo.si_signo); + siginfo_to_lsiginfo(&siginfo, &lsi, sig); + error = copyout(&lsi, infop, sizeof(lsi)); + } return (error); } @@ -1057,37 +1047,48 @@ linux_waitpid(struct thread *td, struct linux_waitpid_args *args) int linux_wait4(struct thread *td, struct linux_wait4_args *args) { - int error, options; - struct __wrusage wru, *wrup; + struct proc *p; + 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 if (args->pid == 0) { + idtype = P_PGID; + p = td->td_proc; + PROC_LOCK(p); + id = p->p_pgid; + PROC_UNLOCK(p); + } 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; - int error; + int error, options; options = 0; linux_to_bsd_waitopts(args->options, &options); @@ -1115,24 +1116,8 @@ linux_waitid(struct thread *td, struct linux_waitid_args *args) 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) { - 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);