From nobody Thu Mar 31 17:50:35 2022 X-Original-To: dev-commits-src-main@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 C7B1F1A56B47; Thu, 31 Mar 2022 17:50:35 +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 4KTrSC5JVXz4s60; Thu, 31 Mar 2022 17:50:35 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1648749035; 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=ffFt9uRuyg4c/q8jTTEexuI9FzxVP4aTh+TD7pOd+SY=; b=sksFwzOwBEbH366z2n5AxjCijbGTyOJ2t7o41EiY1Yz6rI0LvRs0wkBSYj2/BSPezBrtGc GTWE47ozlmHYzkaFGDnNxfWfMG3jhsodGSOHBmDKfVRuNF8ghxeyXA7bg7FFLdn0rk6LPK m7hIkkV4OTuRHh2D2JfLUD0/NylqtaMkho5vvrs91sjQa1GdR8v3H4UAVWpwqWD9Nwl264 EHkzlFz2pu8Q8lC0YV9WrdDnEIAG0mu/Hi5aHZkOBG16H3tzo36iPGQdsyS9WLALhjLO7N prHYHtjLqOzyzGVXqeoDhvuTIv0VtP1SrQcmmJ3XEyM6Kw4jp02NkxKtLkoGcQ== 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 969C42BEE7; Thu, 31 Mar 2022 17:50:35 +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 22VHoZBr038601; Thu, 31 Mar 2022 17:50:35 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 22VHoZfr038600; Thu, 31 Mar 2022 17:50:35 GMT (envelope-from git) Date: Thu, 31 Mar 2022 17:50:35 GMT Message-Id: <202203311750.22VHoZfr038600@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Dmitry Chagin Subject: git: 0c6b1ff7de56 - main - linux(4): Consolidate wait* facility into linux_common_wait(). List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: 0c6b1ff7de56ccaef9bb22bacfd69b07ab4aeb8a Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1648749035; 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=ffFt9uRuyg4c/q8jTTEexuI9FzxVP4aTh+TD7pOd+SY=; b=g4P3FL1NeUZ6pOoMnebLGGrX2yuqMyE5y4ferjh2uY9rucYBOaA/Ln7yBVzwCubgENbIOn 9bB6scLp+5fKAnDlPtgE76AtTC9fdHiCc6J+++tJyGS8j0nNWJtsPX2fX6Z3T1AvBrfjOl 04ZL5WVvp7KzUl8Fezm1YB1B7P/+S15A0gY9BYSYIGCwcxSHpgLX7UaJ5yM7j5kQUKtG94 7+7YGVWWzlym2eCwiSPlthB490PMoeNyKSCO682PVmvFCBMrB0MJYHfYb6crkyvI05G92e 8vQtbpLBaa2eLcIlYfWhJ7hMxT8SiuqUlS2ZgmxzRJhETR7gF/jZWobISpcV9g== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1648749035; a=rsa-sha256; cv=none; b=LM5jehpd8IORqKnbFmXRM77kpFyHOqPadzdHe6aKsOA9V0+3Z7NmR0qCBfRZrZEy6j/E2n U8orA0u73hWxxYclk9NMBok9nXzI19BPT4s5pUyYkyd8/njUT3UswXvczm4SD0ksgADzoU 3OPFFf2PZZSQnSGW8OodhSrjfRSSPanK+sq8xrEwRUSqklo2vccBE78q+j6FUpyp9tYms0 DKUqyf1wMhvzgdaepNss8ZOWJu6Lzs2HQmoMnyXfbqQf0UHSMVI3X/Z1c9qnnJirLtj8uJ yONrPBY0m9dTQGvZWqyjMi7pBNi0s7oY+kRlR6tCq8qpg4G0fd7QC20GvpOM4Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by dchagin: URL: https://cgit.FreeBSD.org/src/commit/?id=0c6b1ff7de56ccaef9bb22bacfd69b07ab4aeb8a commit 0c6b1ff7de56ccaef9bb22bacfd69b07ab4aeb8a Author: Dmitry Chagin AuthorDate: 2022-03-31 17:40:22 +0000 Commit: Dmitry Chagin CommitDate: 2022-03-31 17:40:22 +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 --- 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 a084e1e9992a..b5e72989ac0a 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);