Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3329218imu; Sun, 11 Nov 2018 12:30:04 -0800 (PST) X-Google-Smtp-Source: AJdET5ckGIg24hdUetqikote072y+AIn1T00Po0Jz0dKlCOqnSC8cz0sfLbAEZFOQdnOdkl5+CZG X-Received: by 2002:aa7:804e:: with SMTP id y14-v6mr17110784pfm.73.1541968204727; Sun, 11 Nov 2018 12:30:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541968204; cv=none; d=google.com; s=arc-20160816; b=xLeRT3BC92t6NO/Qg1KQ8rclSSwgTwCLe9Mw2A6k5wxznRSpDXCZ8raiTKDTm/qzke oUf06U7t8WVVV7P3GmxGyAa0HUGHB15Hr+7QbtjYUx3FTiUekDyJRGVTnwJ4IxJSyCZ6 cK0k45bg+57dzGU9Bs0MxDtcyctfqVddru4vZiJuoWveVsrGncRud3gfRQC2bh4IkXYm lC/BDOWIlEBQd3daWeUoyKXHNQK90cEMK/9AvZjNyS4DUs1fUCOCc+q8AP4Y2wpxFcHC h53XiZirPsHcWpAiXRQ51qKuuW5XzVPBBZKliq9qC+cLRYri9E50RYlEQpiastRss7jI qWvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=Dxr71o6GyboEgQQ1GRp+fWe5O3cpnWh14HSTb3RA17Q=; b=g/di5U8N8aSZoeKX6VTPW69kt2TnVjmndGn+1z6ogB/AGapfpuQ+qvTkRo6cdWz5Z4 gPZPZbbHBqGk793lvTKLqhrlA94NJCq4/S14PLkOSkQ5aN5fWZnm2gez9EqRMIKWwYVr CtLBCjCt3b82iCZdGn5lcL8MDGOEJtEd23tEmhFBbkuQJ1Foy4OraAPsbHntTWUVcNKl PKeFErY56Jz/VZhnTAXi5e4bLmQCZQ3LrbYoAYNy3R2S/32hCEBCbonfEgWAjkohz1uL NKFNpyPSA6Ge42DouahF1HhGGJcdtaW/8gd58TRjKbip4pw+BW96qjMd/9zJof83bwsx EAgg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d16-v6si14294073pgd.555.2018.11.11.12.29.49; Sun, 11 Nov 2018 12:30:04 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730500AbeKLFsW (ORCPT + 99 others); Mon, 12 Nov 2018 00:48:22 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:50332 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730392AbeKLFsT (ORCPT ); Mon, 12 Nov 2018 00:48:19 -0500 Received: from [192.168.4.242] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gLvsf-0000lJ-9w; Sun, 11 Nov 2018 19:58:49 +0000 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1gLvsa-0001t6-OI; Sun, 11 Nov 2018 19:58:44 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Wang Nan" , "Adrian Hunter" , "David Ahern" , "Arnaldo Carvalho de Melo" , "Jiri Olsa" , "Namhyung Kim" Date: Sun, 11 Nov 2018 19:49:05 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 355/366] perf thread_map: Use readdir() instead of deprecated readdir_r() In-Reply-To: X-SA-Exim-Connect-IP: 192.168.4.242 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.61-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Arnaldo Carvalho de Melo commit 3354cf71104de49326d19d2f9bdb1f66eea52ef4 upstream. The readdir() function is thread safe as long as just one thread uses a DIR, which is the case in thread_map, so, to avoid breaking the build with glibc-2.23.90 (upcoming 2.24), use it instead of readdir_r(). See: http://man7.org/linux/man-pages/man3/readdir.3.html "However, in modern implementations (including the glibc implementation), concurrent calls to readdir() that specify different directory streams are thread-safe. In cases where multiple threads must read from the same directory stream, using readdir() with external synchronization is still preferable to the use of the deprecated readdir_r(3) function." Noticed while building on a Fedora Rawhide docker container. Cc: Adrian Hunter Cc: David Ahern Cc: Jiri Olsa Cc: Namhyung Kim Cc: Wang Nan Link: http://lkml.kernel.org/n/tip-del8h2a0f40z75j4r42l96l0@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo [bwh: Backported to 3.16: adjust context] Signed-off-by: Ben Hutchings --- tools/perf/util/thread_map.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) --- a/tools/perf/util/thread_map.c +++ b/tools/perf/util/thread_map.c @@ -64,7 +64,7 @@ struct thread_map *thread_map__new_by_ui DIR *proc; int max_threads = 32, items, i; char path[256]; - struct dirent dirent, *next, **namelist = NULL; + struct dirent *dirent, **namelist = NULL; struct thread_map *threads = malloc(sizeof(*threads) + max_threads * sizeof(pid_t)); if (threads == NULL) @@ -76,16 +76,16 @@ struct thread_map *thread_map__new_by_ui threads->nr = 0; - while (!readdir_r(proc, &dirent, &next) && next) { + while ((dirent = readdir(proc)) != NULL) { char *end; bool grow = false; struct stat st; - pid_t pid = strtol(dirent.d_name, &end, 10); + pid_t pid = strtol(dirent->d_name, &end, 10); if (*end) /* only interested in proper numerical dirents */ continue; - snprintf(path, sizeof(path), "/proc/%s", dirent.d_name); + snprintf(path, sizeof(path), "/proc/%s", dirent->d_name); if (stat(path, &st) != 0) continue;