Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2127535pxb; Thu, 11 Feb 2021 05:13:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJzZynsN4mCYwHo9UDzENgexRX0HpsjS49Bodc/KGnoDJN4aFVabgZfzU1rUldyOMNl7ACQ8 X-Received: by 2002:a17:906:c1d9:: with SMTP id bw25mr8345308ejb.452.1613049232119; Thu, 11 Feb 2021 05:13:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613049232; cv=none; d=google.com; s=arc-20160816; b=gJPllRw+ym6a1GSquy1xYyIia1rAhhklIBXNxA9b0gXxagXvowDYOKyYLBkJnR1quV JjVJiZH1YaVxQDbhkBMNK4K+P2XTF2lTX+U+W7qmDE2hOPyPHTdniQohb62Oouon7Hfi ZerKA5teYmJxVDq9hwmSabctT6WSoCOpmPNkmVKH2z9u4M7QcyQlXzVcJHoH6TwBRFF8 kkcv9A/mXibTpEZIgUpqSz48SiOBOHAiUWOVoDi5YQ2lFGg2+uhlP7oDE4MKCh9QIqA3 C9vMWeWDbODt/LlxA/4UnhKqGYhhFPYY4a6enRFu3ToRv9ipk83l7xgw0YNMVf9myx3x Czuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=s99WNNenIaUeOOVOCCV/bxtXN4oqDrKcQyAhjoIB0d0=; b=P9Eu7kyJ5y3F0PgBBGMQSuwBx/Qamp8YHLvTul8uYpST8X2cOOSBlXbIo8aBTs7lx5 NtTdtR9cXhsJORMPwy7eIVxY5uBoGd/T0/efmW/rFoZcbypA8c1ALBlteE3DYnTNnabz 0TE1hJJefMV6GettPSInANaJxfMPe9GoMRlKX9V7xm1F+e/d7MqUeP4mLuKK+v+RGXJz nRp/hly+tB5D4+lKQdcEoEqCC/8H5NoQ7Ar05+Op33GTOOzeqndcR5c5xH3AYzkm7QE4 rWQGlvM5f2aN0t0UNuPl+h9b3FPmQbs5Sqpt+hsXryH9XtfWQCmpihcl7beIF6socN4a z5Mw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=PmdRJVmb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dk7si4007408ejb.223.2021.02.11.05.13.28; Thu, 11 Feb 2021 05:13:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=PmdRJVmb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231447AbhBKNM0 (ORCPT + 99 others); Thu, 11 Feb 2021 08:12:26 -0500 Received: from mail.kernel.org ([198.145.29.99]:56922 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231209AbhBKMwt (ORCPT ); Thu, 11 Feb 2021 07:52:49 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 22BD164E08; Thu, 11 Feb 2021 12:52:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1613047928; bh=0R3pW2EmjrX1ocLLRW7YVSQVF3AM5YQu4du6c2wq2Cw=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=PmdRJVmbDzuGBw+u/rzWf1P9+iKVbnK6Nj3+S1sARxrulssIcd2kYPxysRj0cHUOh ePGR4HEdllFuum1T/CCIBt37r3xQWX2WUov+YVEvFhdvA262YtIg4JwEZjOYJLFTiR +HwcwwYe5xVODEoJgyuAi+9+yxiEnvUwAXoT4ppj9VN65qFSiIwB5+kAxVNOrnC4sj mO+eQDBmpZ7DzEmh8erLxODifQB8iFDiDGB6gAOAntipjh/iORkF2utCgSyVnth5Dn 80vLeNoXQw68wQ7oJy2+tvpJharSY8VEltnxMonyIYGzVCvt7IZ6NwDSHzK/N8h6pg EevTyyG+jNDsw== Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id 6F9E240513; Thu, 11 Feb 2021 09:52:05 -0300 (-03) Date: Thu, 11 Feb 2021 09:52:05 -0300 From: Arnaldo Carvalho de Melo To: Jiri Olsa Cc: lkml , Peter Zijlstra , Ingo Molnar , Mark Rutland , Namhyung Kim , Alexander Shishkin , Michael Petlan , Ian Rogers , Alexei Budankov Subject: Re: [PATCH 05/24] perf daemon: Add client socket support Message-ID: <20210211125205.GA1131885@kernel.org> References: <20210208200908.1019149-1-jolsa@kernel.org> <20210208200908.1019149-6-jolsa@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210208200908.1019149-6-jolsa@kernel.org> X-Url: http://acmel.wordpress.com Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Em Mon, Feb 08, 2021 at 09:08:49PM +0100, Jiri Olsa escreveu: > +__maybe_unused > +static int send_cmd(struct daemon *daemon, union cmd *cmd) > +{ > + int ret = -1, fd; > + char *line = NULL; > + size_t len = 0; > + ssize_t nread; > + FILE *in = NULL; > + > + if (setup_client_config(daemon)) > + return -1; > + > + fd = setup_client_socket(daemon); > + if (fd < 0) > + return -1; > + > + if (sizeof(*cmd) != writen(fd, cmd, sizeof(*cmd))) { > + perror("failed: write"); > + goto out; > + } > + > + in = fdopen(fd, "r"); > + if (!in) { > + perror("failed: fdopen"); > + goto out; > + } > + > + while ((nread = getline(&line, &len, in)) != -1) { > + fwrite(line, nread, 1, stdout); > + fflush(stdout); > + } > + > + ret = 0; > + fclose(in); > +out: > + /* If in is defined, then fd is closed via fclose. */ > + if (!in) > + close(fd); > + return ret; > +} > + So I had to add the patch below to deal with this in some systems: cc1: warnings being treated as errors builtin-daemon.c: In function 'send_cmd': MKDIR /tmp/build/perf/bench/ builtin-daemon.c:1368: error: ignoring return value of 'fwrite', declared with attribute warn_unused_result MKDIR /tmp/build/perf/tests/ make[3]: *** [/tmp/build/perf/builtin-daemon.o] Error 1 And also to not leak the 'line' buffer allocated by getline(), since you initialized line to NULL and len to zero, man page says: If *lineptr is set to NULL and *n is set 0 before the call, then getline() will allocate a buffer for storing the line. This buffer should be freed by the user program even if getline() failed. diff --git a/tools/perf/builtin-daemon.c b/tools/perf/builtin-daemon.c index e0880c5ee39c89bd..0a282c4e23a9fd9a 100644 --- a/tools/perf/builtin-daemon.c +++ b/tools/perf/builtin-daemon.c @@ -344,12 +344,15 @@ static int send_cmd(struct daemon *daemon, union cmd *cmd) } while ((nread = getline(&line, &len, in)) != -1) { - fwrite(line, nread, 1, stdout); + if (fwrite(line, nread, 1, stdout) != 1) + goto out_fclose; fflush(stdout); } ret = 0; +out_fclose: fclose(in); + free(line); out: /* If in is defined, then fd is closed via fclose. */ if (!in)