From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751665AbdJXH0y (ORCPT ); Tue, 24 Oct 2017 03:26:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36832 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751451AbdJXH0v (ORCPT ); Tue, 24 Oct 2017 03:26:51 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 7748149039 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=jolsa@redhat.com Date: Tue, 24 Oct 2017 09:26:46 +0200 From: Jiri Olsa To: kan.liang@intel.com Cc: acme@kernel.org, mingo@redhat.com, linux-kernel@vger.kernel.org, peterz@infradead.org, jolsa@kernel.org, wangnan0@huawei.com, hekuang@huawei.com, namhyung@kernel.org, alexander.shishkin@linux.intel.com, adrian.hunter@intel.com, ak@linux.intel.com Subject: Re: [PATCH V3 4/6] perf tools: add perf_data_file__open_tmp Message-ID: <20171024072646.GD27972@krava> References: <1508529934-369393-1-git-send-email-kan.liang@intel.com> <1508529934-369393-5-git-send-email-kan.liang@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1508529934-369393-5-git-send-email-kan.liang@intel.com> User-Agent: Mutt/1.9.1 (2017-09-22) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 24 Oct 2017 07:26:51 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Oct 20, 2017 at 01:05:32PM -0700, kan.liang@intel.com wrote: > From: Kan Liang > > And an interface for perf_data_file to open tmp file. > Automatically generate the tmp file name if it's not assigned. The name > cannot be const char. Introduce char *tmp_path for it. > The tmp file will be deleted after close. > > It will be used as per-thread file to temporarily store event synthesizd > result in the following patch. > > Signed-off-by: Kan Liang > --- > tools/perf/util/data.c | 26 ++++++++++++++++++++++++++ > tools/perf/util/data.h | 2 ++ > 2 files changed, 28 insertions(+) > > diff --git a/tools/perf/util/data.c b/tools/perf/util/data.c > index 1123b30..cd6fdf9 100644 > --- a/tools/perf/util/data.c > +++ b/tools/perf/util/data.c > @@ -139,9 +139,35 @@ int perf_data_file__open(struct perf_data_file *file) > return open_file(file); > } > > +int perf_data_file__open_tmp(struct perf_data_file *file) > +{ > + int fd; > + > + if (!file->tmp_path && > + (asprintf(&file->tmp_path, "perf.tmp.XXXXXX") < 0)) > + goto err; > + > + fd = mkstemp(file->tmp_path); > + if (fd < 0) { > + free(file->tmp_path); > + goto err; > + } > + > + file->fd = fd; > + return 0; > +err: > + file->tmp_path = NULL; > + return -1; > +} > + > void perf_data_file__close(struct perf_data_file *file) > { > close(file->fd); > + if (file->tmp_path) { > + unlink(file->tmp_path); > + free(file->tmp_path); > + file->tmp_path = NULL; we have a zfree for that jirka