From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753948AbcFPIcK (ORCPT ); Thu, 16 Jun 2016 04:32:10 -0400 Received: from terminus.zytor.com ([198.137.202.10]:32952 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751931AbcFPIcG (ORCPT ); Thu, 16 Jun 2016 04:32:06 -0400 Date: Thu, 16 Jun 2016 01:31:34 -0700 From: tip-bot for Masami Hiramatsu Message-ID: Cc: acme@redhat.com, tglx@linutronix.de, linux-kernel@vger.kernel.org, peterz@infradead.org, namhyung@kernel.org, hemant@linux.vnet.ibm.com, hpa@zytor.com, ananth@linux.vnet.ibm.com, mingo@kernel.org, brendan.d.gregg@gmail.com, mhiramat@kernel.org Reply-To: ananth@linux.vnet.ibm.com, hpa@zytor.com, hemant@linux.vnet.ibm.com, namhyung@kernel.org, linux-kernel@vger.kernel.org, peterz@infradead.org, acme@redhat.com, tglx@linutronix.de, mhiramat@kernel.org, brendan.d.gregg@gmail.com, mingo@kernel.org In-Reply-To: <20160608092911.3116.90929.stgit@devbox> References: <20160608092911.3116.90929.stgit@devbox> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] perf tools: Fix rm_rf() to handle non-regular files correctly Git-Commit-ID: 2a1ef032cfccd8c92f32b86615a0b0151a7cd86f X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 2a1ef032cfccd8c92f32b86615a0b0151a7cd86f Gitweb: http://git.kernel.org/tip/2a1ef032cfccd8c92f32b86615a0b0151a7cd86f Author: Masami Hiramatsu AuthorDate: Wed, 8 Jun 2016 18:29:11 +0900 Committer: Arnaldo Carvalho de Melo CommitDate: Tue, 14 Jun 2016 09:29:54 -0300 perf tools: Fix rm_rf() to handle non-regular files correctly Fix rm_rf() to handle non-regular files correctly. This fix includes two changes; - Fix to use lstat(3) instead of stat(3) since if the target file is a symbolic link, rm_rf() should unlink the symbolic link itself, not the file which pointed by the symlink. - Fix to unlink non-regular files (except for directory), including symlink. Even though the first one fixes to stat symlink itself, without second fix, it still failed because the symlink is not a regular file. Signed-off-by: Masami Hiramatsu Cc: Ananth N Mavinakayanahalli Cc: Brendan Gregg Cc: Hemant Kumar Cc: Namhyung Kim Cc: Peter Zijlstra Link: http://lkml.kernel.org/r/20160608092911.3116.90929.stgit@devbox Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/util.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c index 23504ad..e08b9a0 100644 --- a/tools/perf/util/util.c +++ b/tools/perf/util/util.c @@ -97,20 +97,17 @@ int rm_rf(char *path) scnprintf(namebuf, sizeof(namebuf), "%s/%s", path, d->d_name); - ret = stat(namebuf, &statbuf); + /* We have to check symbolic link itself */ + ret = lstat(namebuf, &statbuf); if (ret < 0) { pr_debug("stat failed: %s\n", namebuf); break; } - if (S_ISREG(statbuf.st_mode)) - ret = unlink(namebuf); - else if (S_ISDIR(statbuf.st_mode)) + if (S_ISDIR(statbuf.st_mode)) ret = rm_rf(namebuf); - else { - pr_debug("unknown file: %s\n", namebuf); - ret = -1; - } + else + ret = unlink(namebuf); } closedir(dir);