From patchwork Thu Feb 20 17:58:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 183670 Delivered-To: patch@linaro.org Received: by 2002:a92:1f12:0:0:0:0:0 with SMTP id i18csp862956ile; Thu, 20 Feb 2020 09:58:59 -0800 (PST) X-Google-Smtp-Source: APXvYqxFwqNDwWCzrksI2k9NRyClC1XyUu8+okQyn0pAUaX5cmh/q808jv02FEIGD81Zw9L2ofSy X-Received: by 2002:aca:c68f:: with SMTP id w137mr3031939oif.179.1582221539467; Thu, 20 Feb 2020 09:58:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582221539; cv=none; d=google.com; s=arc-20160816; b=s37nN7YBP1TYFXRtHxJWQ2rijSXI1OzmnqG5b0YqZreSv3wO4YYRtG9e/ialZtGB9T BKnt2L6A0niS+vjNZx7FByVvx5Tl5hfBJK2SnzQuBYuMqmDn2n2410Ps3CJ+E9TDp5re HELdTlMrruMr32ITYegCeT1YH09hIBcvmWOV7QEsV587sIhQrwIB+cTML7bbrKQYgRud OiK2+sQz084Mq5b5NS+WXUVT+E/zilHvwRk/tsXbgpWJbXQAVyo7Z17MshhtUYZxh8N7 gHoXrN7BM0vEBpGRg4woO9jkJaCy2j1iHRNMvW2vbNN236vSPYtJoeW/Xy7IwzmEi8QL Eoiw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:to:from:dkim-signature:delivered-to:sender :list-help:list-post:list-archive:list-subscribe:list-unsubscribe :list-id:precedence:mailing-list:dkim-signature:domainkey-signature; bh=+MW7SY3nGKq3esxc3xNuJrpGe2F1Cb2UOEWs9wEIEto=; b=hA9ZYzyndh2uQvSnW86J2CY1SBdYzdvsfl78esiq0yPXNKTbwIuxhEywUvJFZQYxXt walOGKtaOYdTEhRU0+oFnd9UT9Oab2T8TiZo1YjFPlcsrrETkI3FwMDFpMZp9JsjP6Yq fjxI/xpCzLHyQdn5bsDDNS0nfyuJlyTpvrS+DGx4QC22loG2diA8Fl2eL3s+rkZIUJkY 4xfFiXqFNGtmpn2UG6Oo9EbSlTiyJVBnakEzVWw5KNyjvmCjTTaGZl5TALqyHxPZlW7R C4ZIb8Sayf1OXQSN8Yg+z3kxKes8lc9dTDUcA/Q58vo4kytdS/QGZfKIfnTHBWcersHF hxkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=iXFZW70n; dkim=pass header.i=@linaro.org header.s=google header.b=yg8qn9oe; spf=pass (google.com: domain of libc-alpha-return-109987-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="libc-alpha-return-109987-patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id a28si63653otd.257.2020.02.20.09.58.59 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Feb 2020 09:58:59 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-return-109987-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=iXFZW70n; dkim=pass header.i=@linaro.org header.s=google header.b=yg8qn9oe; spf=pass (google.com: domain of libc-alpha-return-109987-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="libc-alpha-return-109987-patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id; q=dns; s= default; b=jsoax/yLArOadi9D1drCat+X3dTS9RL1n/g+Hah7XZWomXBwpyTpe lKAPcnRYN1kY/EVdZYo/27jd5wX2nyM02pgfMJuFivSuAZXWdsDSo70/dkEWKe/g utZxuXF83eIKADH/Cdze0xJ7NpuoA3RN6quAONDrsvWwoYri1J0H38= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id; s=default; bh=GIgOWyyy8XUcHEn6xQtUOnp2GpQ=; b=iXFZW70nN/uU5cejK7rdZuw/C+VB 2BtK2hU9P3wLq+fFKAi/DD4/6qVkaKldOaOJ3v72JN8fJSiTtWjWY63OwkX9jmW2 iIXp/u38a2EVmo3Acza1VcowSwTZFVfCJzo+/bE5uuhb5qeCbLiS4v25rl15OBt/ jIiYBk+sm+KFXDs= Received: (qmail 119974 invoked by alias); 20 Feb 2020 17:58:50 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 119961 invoked by uid 89); 20 Feb 2020 17:58:50 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.2 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=1229 X-HELO: mail-qk1-f194.google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id; bh=+MW7SY3nGKq3esxc3xNuJrpGe2F1Cb2UOEWs9wEIEto=; b=yg8qn9oecu0Kyw3LM+KfTFNdB/cP570mTC8azTlj827lad2xHaiHmQLOGgMTGGPpfb LJ2Zyok04ofdtDb97jYRK9MRQ7FCJplzBa9jpy77eR6rnQcO+Ic+3JJRy2f4JCkcT2dR cCESU2kIYDfAegFtgMgTK9C98U3B7ytlnhI4yKxCKwcmBhTAKA21YzfJDemfTou5l/CN qH2ES1nK2aCvjAPRetHBMTvCPDpgpM+GixnwOakruQkHvDPW+Z1IQ9OARjWUxc2FJTEt Lh84mKWSHEDDup9i4oHRqxai5UrrxKH3B5/ykyoTkdb5+L4nJHCj3CIBCuLtd6NJ03sr ufrw== Return-Path: From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH] malloc/tst-mallocfork2: Kill lingering process for unexpected failures Date: Thu, 20 Feb 2020 14:58:40 -0300 Message-Id: <20200220175840.25246-1-adhemerval.zanella@linaro.org> If the test fails due some unexpected failure after the children creation, either in the signal handler by calling abort or in the main loop; the created children might not be killed properly. This patches fixes it by: * Avoid aborting in the signal handler by setting a flag that an error has occured and add a check in the main loop. * Add a atfork handler to handle kill the signal sending processes. Checked on x86_64-linux-gnu. --- malloc/tst-mallocfork2.c | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) -- 2.17.1 diff --git a/malloc/tst-mallocfork2.c b/malloc/tst-mallocfork2.c index 0602a94895..4caf61489f 100644 --- a/malloc/tst-mallocfork2.c +++ b/malloc/tst-mallocfork2.c @@ -62,6 +62,9 @@ static volatile sig_atomic_t sigusr1_received; progress. Checked by liveness_signal_handler. */ static volatile sig_atomic_t progress_indicator = 1; +/* Set to 1 if an error occurs in the signal handler. */ +static volatile sig_atomic_t error_indicator = 0; + static void sigusr1_handler (int signo) { @@ -72,7 +75,8 @@ sigusr1_handler (int signo) if (pid == -1) { write_message ("error: fork\n"); - abort (); + error_indicator = 1; + return; } if (pid == 0) _exit (0); @@ -81,12 +85,14 @@ sigusr1_handler (int signo) if (ret < 0) { write_message ("error: waitpid\n"); - abort (); + error_indicator = 1; + return; } if (status != 0) { write_message ("error: unexpected exit status from subprocess\n"); - abort (); + error_indicator = 1; + return; } } @@ -122,9 +128,25 @@ signal_sender (int signo, bool sleep) } } +/* Children processes. */ +static pid_t sigusr1_sender_pids[5] = { -1 }; +static pid_t sigusr2_sender_pid = -1; + +static void +kill_children (void) +{ + for (size_t i = 0; i < array_length (sigusr1_sender_pids); ++i) + if (sigusr1_sender_pids[i] != -1) + kill (sigusr1_sender_pids[i], SIGKILL); + if (sigusr2_sender_pid != -1) + kill (sigusr2_sender_pid, SIGKILL); +} + static int do_test (void) { + atexit (kill_children); + /* shared->barrier is intialized along with sigusr1_sender_pids below. */ shared = support_shared_allocate (sizeof (*shared)); @@ -148,14 +170,13 @@ do_test (void) return 1; } - pid_t sigusr2_sender_pid = xfork (); + sigusr2_sender_pid = xfork (); if (sigusr2_sender_pid == 0) signal_sender (SIGUSR2, true); /* Send SIGUSR1 signals from several processes. Hopefully, one signal will hit one of the ciritical functions. Use a barrier to avoid sending signals while not running fork/free/malloc. */ - pid_t sigusr1_sender_pids[5]; { pthread_barrierattr_t attr; xpthread_barrierattr_init (&attr); @@ -166,7 +187,7 @@ do_test (void) } for (size_t i = 0; i < array_length (sigusr1_sender_pids); ++i) { - sigusr1_sender_pids[i] = fork (); + sigusr1_sender_pids[i] = xfork (); if (sigusr1_sender_pids[i] == 0) signal_sender (SIGUSR1, false); } @@ -211,7 +232,7 @@ do_test (void) ++malloc_signals; xpthread_barrier_wait (&shared->barrier); - if (objects[slot] == NULL) + if (objects[slot] == NULL || error_indicator != 0) { printf ("error: malloc: %m\n"); for (size_t i = 0; i < array_length (sigusr1_sender_pids); ++i) @@ -225,10 +246,6 @@ do_test (void) for (int slot = 0; slot < malloc_objects; ++slot) free (objects[slot]); - for (size_t i = 0; i < array_length (sigusr1_sender_pids); ++i) - kill (sigusr1_sender_pids[i], SIGKILL); - kill (sigusr2_sender_pid, SIGKILL); - printf ("info: signals received during fork: %u\n", fork_signals); printf ("info: signals received during free: %u\n", free_signals); printf ("info: signals received during malloc: %u\n", malloc_signals);