Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3331486imu; Sun, 11 Nov 2018 12:32:42 -0800 (PST) X-Google-Smtp-Source: AJdET5dn4Xvm3EpLCIjsli3MmP6yKjLcW/bzeYkhcn1y2E4OYK/SUgeVzM2tRjbpQUExFeUgtMC1 X-Received: by 2002:a17:902:5a09:: with SMTP id q9-v6mr17523054pli.186.1541968362249; Sun, 11 Nov 2018 12:32:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541968362; cv=none; d=google.com; s=arc-20160816; b=et+4qlTyIt9EY4guKzPNc5E6KEP0rVtG4Moc2UGK2ZDqOvPP6tNm/uzSnO1jBi+HMI bSJkwEKvJEXCEZ3xtQFyT4A3tKL5v1ENpS2nk9Wg32wjJZ7ygVR6qD5pcUW6HsPWvuFR MfK/wDQmmXi3vkDHwn6DpsiAJzn74P5tlGS2J19uDLiUwFb6F6vZyPqUgRiOCFLnndsV FmoGYnHpB1aUYuNViTiFFzmL950sbLIc7sLYXNqmDW8Zj31i790tymxU90YJWrebvLsv as5tMfL6/R99fA12bfkKl3Nk3O49c0vE/EFleMaBvhTZYr8kECXUTQeAks29eB+zW+ph j78Q== 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=Th6azC+hFkCR5zTAVybN0taGj1Z/3cZzXfR6LgNLHm0=; b=yIZu5lnJkM9zbW0PvBwJl7Rj0k+QHve06e/J2qcO5B1x9K/VRU7U2w+70+mfFftGYT q/DRHDI4UNB217fkFlpgJIUdszD//r835G/uXyGpoOOWG6WuO3I2LBw+rFamrEDQA9eF FBaFT7acORgK3+S8xATkdI10+MNy6gy/qkAiOuajo3o89DJB94tdv6QRVngHvEYz97s7 XhIFeWcNTN+klvXHp4BsRq0MYWeX50Og5tQ9tgv4PpLymT2KFZiQ+Njrn3+m4HCeK5yL C/+SMyjf9z6ctNm4WFlOg5I/IcIXxbDfEoJQe0uVld06WIECrOS+TOgMZYlXOrGTc3nd SO9A== 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 v1-v6si14867179plo.134.2018.11.11.12.32.26; Sun, 11 Nov 2018 12:32:42 -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 S1730558AbeKLGUQ (ORCPT + 99 others); Mon, 12 Nov 2018 01:20:16 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:50416 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730410AbeKLFsU (ORCPT ); Mon, 12 Nov 2018 00:48:20 -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-0000l8-G7; Sun, 11 Nov 2018 19:58:49 +0000 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1gLvsa-0001tB-Q1; 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, "Namhyung Kim" , "David Ahern" , "Arnaldo Carvalho de Melo" , "Jiri Olsa" , "Adrian Hunter" , "Wang Nan" Date: Sun, 11 Nov 2018 19:49:05 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 356/366] perf tools: 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 7093b4c963cc4e344e490c774924a180602a7092 upstream. The readdir() function is thread safe as long as just one thread uses a DIR, which is the case when synthesizing events for pre-existing threads by traversing /proc, 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 /tmp/build/perf/util/event.o util/event.c: In function '__event__synthesize_thread': util/event.c:466:2: error: 'readdir_r' is deprecated [-Werror=deprecated-declarations] while (!readdir_r(tasks, &dirent, &next) && next) { ^~~~~ In file included from /usr/include/features.h:368:0, from /usr/include/stdint.h:25, from /usr/lib/gcc/x86_64-redhat-linux/6.0.0/include/stdint.h:9, from /git/linux/tools/include/linux/types.h:6, from util/event.c:1: /usr/include/dirent.h:189:12: note: declared here Cc: Adrian Hunter Cc: David Ahern Cc: Jiri Olsa Cc: Namhyung Kim Cc: Wang Nan Link: http://lkml.kernel.org/n/tip-i1vj7nyjp2p750rirxgrfd3c@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/event.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) --- a/tools/perf/util/event.c +++ b/tools/perf/util/event.c @@ -331,7 +331,7 @@ static int __event__synthesize_thread(un { char filename[PATH_MAX]; DIR *tasks; - struct dirent dirent, *next; + struct dirent *dirent; pid_t tgid; /* special case: only send one comm event using passed in pid */ @@ -358,12 +358,12 @@ static int __event__synthesize_thread(un return 0; } - while (!readdir_r(tasks, &dirent, &next) && next) { + while ((dirent = readdir(tasks)) != NULL) { char *end; int rc = 0; pid_t _pid; - _pid = strtol(dirent.d_name, &end, 10); + _pid = strtol(dirent->d_name, &end, 10); if (*end) continue; @@ -464,7 +464,7 @@ int perf_event__synthesize_threads(struc { DIR *proc; char proc_path[PATH_MAX]; - struct dirent dirent, *next; + struct dirent *dirent; union perf_event *comm_event, *mmap_event, *fork_event; int err = -1; @@ -489,9 +489,9 @@ int perf_event__synthesize_threads(struc if (proc == NULL) goto out_free_fork; - while (!readdir_r(proc, &dirent, &next) && next) { + while ((dirent = readdir(proc)) != NULL) { char *end; - 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;