From patchwork Thu Apr 9 20:11:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 38798 Return-Path: X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from esa3.hgst.iphmx.com (esa3.hgst.iphmx.com [216.71.153.141]) by sourceware.org (Postfix) with ESMTPS id 04238385DC03 for ; Thu, 9 Apr 2020 20:19:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 04238385DC03 IronPort-SDR: ypTSRK0IX0xHhob4DT3E0IMggGi4lYRNv6R9XilRNoWHqKCTLndjVVyxu++7qrHOPIztZGCuAJ tCxkBzXf2aaUaWCt7oYztdGZREQp0oQcrM8/iTA66FP5vl422jkhBBv/b0Y2Uru89PXJZblXzB PfC3cNuUSK4l9IlLGfCe3/fkJ2NK1gt6ZPqVpBJo6jOkHmBcrhFfYEGOAz2qkjhjDON/zbknmg rykfssEPFPwBpcUyxwKP+iXpO+G0xuDBMFOaTR85ueEHqoRn2bPLgazn71R7PqWXhGLLlU9cvL dvM= X-IronPort-AV: E=Sophos;i="5.72,363,1580745600"; d="scan'208";a="139316536" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 10 Apr 2020 04:19:44 +0800 IronPort-SDR: 239OmDvyPE5e/52O+6/Y/QErwMB6xvckGNQ7+B/LSryPERo3iCZvxHLZr0DZ+5EC/6WGVN0ej2 b3lcCRl2xDDNLKL5VKp3rgqEDeZDr8Q8JCtDmWSyqY6g2KDyy7FbZ5cn/OFS6ApH1Bqkrc59du bPEq96+N5Vdp0rkjECdGZc4En5vvx6GGKpKFsoWKc1RRwkPCNxCnk2AUqmajHU/F2b+6GO23V8 9Y5PUifvi1FUkN7T4amLejN42H1P71s6n9Zt0J4T/UI5Z9YcDobi6xsvNp2hSpQYPWgIItPMUJ nrVZxj0COEDG4Yp7BNyNg7Z7 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Apr 2020 13:10:23 -0700 IronPort-SDR: tNAsPniOFCNyGuAwJLogfrdPyVt1V849159LC0icB8cTU9jSrC808CteU41bpxoNBQ+K+k4h4b oeecehMTaj1jIzrzezM3F8gpd3OLcThsN3KXPRHn+3I7Qh6Gt9B3QSr3G5+P0o19PLxcAyVvAk Xx/CP7mB450wfLheTNcalti2+uVt6icWtUiMoDQhaFFetPnYHDGK8H7HAxl4BKfiPb3k2bi3y5 jCVSjehHcDX/LYLwwUv5WZBmve6hN5iyPyt6sPgoXnxe9pKDWH+NyyqJOxcrvbz9kks0jLYIhN 1PE= WDCIronportException: Internal Received: from 5zs6pc2.ad.shared (HELO risc6-mainframe.hgst.com) ([10.86.55.151]) by uls-op-cesaip02.wdc.com with ESMTP; 09 Apr 2020 13:19:43 -0700 From: Alistair Francis To: libc-alpha@sourceware.org Cc: alistair23@gmail.com, Alistair Francis Subject: [PATCH v3 1/2] linux: wait4: Fix incorrect return value comparison Date: Thu, 9 Apr 2020 13:11:53 -0700 Message-Id: <20200409201154.3365671-1-alistair.francis@wdc.com> X-Mailer: git-send-email 2.26.0 MIME-Version: 1.0 X-Spam-Status: No, score=-25.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 09 Apr 2020 20:19:53 -0000 Patch 600f00b "linux: Use long time_t for wait4/getrusage" introduced two bugs: - The usage32 struct was set if the wait4 syscall had an error. - For 32-bit systems the usage struct was set even if it was specified as NULL. This patch fixes the two issues. --- sysdeps/unix/sysv/linux/wait4.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/sysdeps/unix/sysv/linux/wait4.c b/sysdeps/unix/sysv/linux/wait4.c index d14bd4da27..21eb154b72 100644 --- a/sysdeps/unix/sysv/linux/wait4.c +++ b/sysdeps/unix/sysv/linux/wait4.c @@ -29,14 +29,18 @@ __wait4_time64 (pid_t pid, int *stat_loc, int options, struct __rusage64 *usage) # if __KERNEL_OLD_TIMEVAL_MATCHES_TIMEVAL64 return SYSCALL_CANCEL (wait4, pid, stat_loc, options, usage); # else - struct __rusage32 usage32; - pid_t ret = SYSCALL_CANCEL (wait4, pid, stat_loc, options, &usage32); - - if (ret != 0) - return ret; + pid_t ret; if (usage != NULL) - rusage32_to_rusage64 (&usage32, usage); + { + struct __rusage32 usage32; + ret = SYSCALL_CANCEL (wait4, pid, stat_loc, options, &usage32); + + if (ret > 0) + rusage32_to_rusage64 (&usage32, usage); + } + else + ret = SYSCALL_CANCEL (wait4, pid, stat_loc, options, NULL); return ret; # endif @@ -114,15 +118,19 @@ libc_hidden_def (__wait4_time64) pid_t __wait4 (pid_t pid, int *stat_loc, int options, struct rusage *usage) { - pid_t ret ; - struct __rusage64 usage64; + pid_t ret; - ret = __wait4_time64 (pid, stat_loc, options, &usage64); + if (usage != NULL) + { + struct __rusage64 usage64; - if (ret != 0) - return ret; + ret = __wait4_time64 (pid, stat_loc, options, &usage64); - rusage64_to_rusage (&usage64, usage); + if (ret > 0) + rusage64_to_rusage (&usage64, usage); + } + else + ret = __wait4_time64 (pid, stat_loc, options, NULL); return ret; } From patchwork Thu Apr 9 20:11:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 38799 Return-Path: X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from esa3.hgst.iphmx.com (esa3.hgst.iphmx.com [216.71.153.141]) by sourceware.org (Postfix) with ESMTPS id 8B5F4385B835 for ; Thu, 9 Apr 2020 20:21:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 8B5F4385B835 IronPort-SDR: zeXnB0cFV2l5noeOpTc7ntYLdzyhWf2GcdKh3aUoc/wxclEjvtCIy2REPEf4qk8AHKOluRzRCe C8aybmdJ6tFwhR7CYpZMYfP/pmSpv0yGkjCM8OudWm4FCtXTZrZbqdQl2ruHFJZztashFUHa56 dXB41cacV/Q5+pANM5AlXJERMvX6DzbXEGeREr9ZlGgfDEp5dx8tcU2p9QZLsP4HsNV7XMHWPf Sl2tmQbpqp49RQChlzemppg3j8CXpWS9yCrPvlFsmdQBFJvfVIcx3CPLBjEyZRj26YhwHzKRFb 0fs= X-IronPort-AV: E=Sophos;i="5.72,363,1580745600"; d="scan'208";a="139316634" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 10 Apr 2020 04:21:10 +0800 IronPort-SDR: 9Smyp0CN5uHx4AvhsKRUROj4QOilLYY1vYMsSKHKekUgOhSqPjR+DR1bq7ULgok+ApNo0sZ+U0 GtDvDcswWDWdZRk7p/kdY+8kcoYuJ93q1s8gLNVU5Nq950wraIqqSABweZlUNEf+D7BruRhoy2 RSEs/DRW6iUGqUhqftaLaAvWLjKRA/EpWNgXTcCAWOE7ocWIZU/reG1zaBJYWuDkbAQ0i1qLyv R8CV6XtkksBB8Cso90TV1tGY3zxNUi4vO7C0S1Xf84XRX/oTD7raaXgaNLwal57tWhLiv934h8 hjQldEMK//Q7TcUpwIQNq1dM Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Apr 2020 13:11:49 -0700 IronPort-SDR: rzkaUNEEbIodycwZj4G5B2S/FHplL1ym+UM2TrgKCuVERDxD0rfzGt1emvdZUWZHaonNAJdb3I PJ8SJoia9jHJ2EJZ/zqjZVoj21l1QBJ68d6Lb81rFsRP17ghu0f4ATHW2XFD3jxMo3TNGqQSQ6 NX73BqcDINVPdfyjZjPpQ8HANBENuqzbo4VupLNgq5/aizhaOm8BR5xvgqgmgjJQKDe4pxQ4XU Oanqw8Ml1ARxsFiXwIlL2am6mgHSj0KouN3fuFR4z2gjzoLWlAt3w5+tzTfwwkVfaLemdHjcrQ +iY= WDCIronportException: Internal Received: from 5zs6pc2.ad.shared (HELO risc6-mainframe.hgst.com) ([10.86.55.151]) by uls-op-cesaip02.wdc.com with ESMTP; 09 Apr 2020 13:21:09 -0700 From: Alistair Francis To: libc-alpha@sourceware.org Cc: alistair23@gmail.com, Alistair Francis Subject: [PATCH v3 2/2] linux: Add wait4 test case Date: Thu, 9 Apr 2020 13:11:54 -0700 Message-Id: <20200409201154.3365671-2-alistair.francis@wdc.com> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200409201154.3365671-1-alistair.francis@wdc.com> References: <20200409201154.3365671-1-alistair.francis@wdc.com> MIME-Version: 1.0 X-Spam-Status: No, score=-25.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 09 Apr 2020 20:21:13 -0000 Add a simple test that checks if the wait4 syscall works without an rusage argument. This test would have caught the bugs introduced in commit 600f00b "linux: Use long time_t for wait4/getrusage". --- sysdeps/unix/sysv/linux/Makefile | 2 +- sysdeps/unix/sysv/linux/tst-wait4.c | 51 +++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 sysdeps/unix/sysv/linux/tst-wait4.c diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile index 60dc5cf9e5..d5fdb4369a 100644 --- a/sysdeps/unix/sysv/linux/Makefile +++ b/sysdeps/unix/sysv/linux/Makefile @@ -98,7 +98,7 @@ tests += tst-clone tst-clone2 tst-clone3 tst-fanotify tst-personality \ tst-quota tst-sync_file_range tst-sysconf-iov_max tst-ttyname \ test-errno-linux tst-memfd_create tst-mlock2 tst-pkey \ tst-rlimit-infinity tst-ofdlocks tst-gettid tst-gettid-kill \ - tst-tgkill + tst-tgkill tst-wait4 tests-internal += tst-ofdlocks-compat tst-sigcontext-get_pc CFLAGS-tst-sigcontext-get_pc.c = -fasynchronous-unwind-tables diff --git a/sysdeps/unix/sysv/linux/tst-wait4.c b/sysdeps/unix/sysv/linux/tst-wait4.c new file mode 100644 index 0000000000..44287797a7 --- /dev/null +++ b/sysdeps/unix/sysv/linux/tst-wait4.c @@ -0,0 +1,51 @@ +/* Smoke test for the wait4 system call. + Copyright (C) 2019-2020 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include +#include +#include +#include +#include + +/* Check that wait4 works with no rusage arg. */ +static void +test_wait4_no_usage (void) +{ + pid_t child = fork (); + + if (child == 0) + { + pause (); + exit (0); + } + + wait4 (child, &(int){0}, WNOHANG, NULL); + kill (child, SIGKILL); +} + +static int +do_test (void) +{ + test_wait4_no_usage(); + + return 0; +} + +#include