Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1551690pxb; Thu, 4 Feb 2021 16:32:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJx99jOi4nvO4g3Fqh28WRgpKKJc+f0vz+N4tAFWZhGeqirB1uHoNi6V4ukuqNuFXnppfMdG X-Received: by 2002:a17:906:2e4f:: with SMTP id r15mr1564743eji.407.1612485143455; Thu, 04 Feb 2021 16:32:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612485143; cv=none; d=google.com; s=arc-20160816; b=0uDgVxlKLjn9nFrtKi5eXz7zGeVsOhVbC+PbJO96cr6NvlCzdBj9nCr5QXMwhVSDOe pAqcj9QVGfQPEKH+ShnCTwVngOasDaL2GUm194zNOo/puUQufstnZ5nHDWSuD8PvZtBZ 1euBlSW+RccdC6yb9G0Arzxo0xQ8YSVYMqYGSoXts/1YJ7dpjBA4ypUavEux7Pqj55jJ eXBHcf/mcC3e3mXX5aAwDfg7y6J16XLSvcUFmfaDSG6zNmJ5EJ8DnEPwagSEH6ubtoZR IfNKbhlwbosnpjHVCHjTK1XjGeA0LfDQwY7IfK7K06DWHHOglxoYgL4s2DLJtDr7w20g 1TVw== 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=akIDH/nqnd2l3Y4F6QpFR8EQh40BTc1icx5sAwOuZmM=; b=KwBaMlHMuuVlgmt/BnL7hoaxgYw12EAfGUZeTSR/0soZOLtGYeqdzmbl8m8VtyX8Vk uO4GLV8XuTsFgXCDTVWLqLtBe+8XMTC/Ig2xj/rEHKulHwYlFDptyhFtvvrbdEYQHZku 7TDGt2kEy2cIboTl+Yi1v/hWQZyO2s0iRqeGcC6EpqZY4VkGFBKLJ8U/xIg/5pEDNxXn +TEHAFJcMhpmY/dTIK5dve9wzBAalCT2QBLFjSXIOlpHqH6JYnrxFO1u2KEyK4ST+Yv4 TRG6i8PieMB9zx/LBrhdtUS7ERYmt3VmOnuoLXf6cK6lL7GBY77/kEFLl2Mth41CZ5sP BigQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Q86wbrCM; 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s18si4142601ejr.353.2021.02.04.16.31.59; Thu, 04 Feb 2021 16:32:23 -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=@redhat.com header.s=mimecast20190719 header.b=Q86wbrCM; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236794AbhBDOvm (ORCPT + 99 others); Thu, 4 Feb 2021 09:51:42 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:33623 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236610AbhBDOvM (ORCPT ); Thu, 4 Feb 2021 09:51:12 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612450184; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=akIDH/nqnd2l3Y4F6QpFR8EQh40BTc1icx5sAwOuZmM=; b=Q86wbrCM0GYleomLKHqpNGy5wZNNyjqiQsL28IGIPC6PkUZdvCtluMjB1FtponDR3HreVH NcsSDBF92UNum8lTl84jQfG1fSMaui/fs+pBnnLzGfUNP9FPwgSgsY1iv9GK7JazCYeQY+ BoxaFy1Rnh6r+RI8wcggGDRX+9Kf9Ws= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-2-pVjKX0D6MnW1y5ej6j6Erw-1; Thu, 04 Feb 2021 09:49:42 -0500 X-MC-Unique: pVjKX0D6MnW1y5ej6j6Erw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8277B1935780; Thu, 4 Feb 2021 14:49:40 +0000 (UTC) Received: from krava (unknown [10.40.194.33]) by smtp.corp.redhat.com (Postfix) with SMTP id ADF9C100AE2B; Thu, 4 Feb 2021 14:49:37 +0000 (UTC) Date: Thu, 4 Feb 2021 15:49:36 +0100 From: Jiri Olsa To: Arnaldo Carvalho de Melo Cc: Jiri Olsa , lkml , Peter Zijlstra , Ingo Molnar , Mark Rutland , Namhyung Kim , Alexander Shishkin , Michael Petlan , Ian Rogers , Stephane Eranian , Alexei Budankov Subject: Re: [PATCH 04/24] perf daemon: Add server socket support Message-ID: References: <20210129134855.195810-1-jolsa@redhat.com> <20210130234856.271282-1-jolsa@kernel.org> <20210130234856.271282-5-jolsa@kernel.org> <20210203210423.GQ854763@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210203210423.GQ854763@kernel.org> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 03, 2021 at 06:04:23PM -0300, Arnaldo Carvalho de Melo wrote: > Em Sun, Jan 31, 2021 at 12:48:36AM +0100, Jiri Olsa escreveu: > > Add support to create server socket that listens for client > > commands and process them. > > > > This patch adds only the core support, all commands using > > this functionality are coming in following patches. > > > > Signed-off-by: Jiri Olsa > > --- > > tools/perf/builtin-daemon.c | 101 +++++++++++++++++++++++++++++++++++- > > 1 file changed, 100 insertions(+), 1 deletion(-) > > > > diff --git a/tools/perf/builtin-daemon.c b/tools/perf/builtin-daemon.c > > index 8d0ac44ec808..756d60616d7d 100644 > > --- a/tools/perf/builtin-daemon.c > > +++ b/tools/perf/builtin-daemon.c > > @@ -1,5 +1,6 @@ > > // SPDX-License-Identifier: GPL-2.0 > > #include > > +#include > > #include > > #include > > #include > > @@ -7,6 +8,10 @@ > > #include > > #include > > #include > > +#include > > +#include > > +#include > > +#include > > #include "builtin.h" > > #include "perf.h" > > #include "debug.h" > > @@ -37,6 +42,78 @@ static void sig_handler(int sig __maybe_unused) > > done = true; > > } > > > > +static int setup_server_socket(struct daemon *daemon) > > +{ > > + struct sockaddr_un addr; > > + char path[100]; > > + int fd; > > + > > + fd = socket(AF_UNIX, SOCK_STREAM, 0); > > Minor, combine decl with use, since line isn't long and its one after > the other, i.e.: > > int fd = socket(AF_UNIX, SOCK_STREAM, 0); hum, sure, but I'm missing the point.. I think it's less readable > > > + if (fd < 0) { > > + fprintf(stderr, "socket: %s\n", strerror(errno)); > > + return -1; > > + } > > + > > + fcntl(fd, F_SETFD, FD_CLOEXEC); > > Don't we have to check its return? yep, will add > > > + > > + scnprintf(path, PATH_MAX, "%s/control", daemon->base); > > Humm the safe thing here is to use: > > scnprintf(path, sizeof(path), "%s/control", daemon->base); > > Using it like that would avoid the bug in your code, as path has only > 100 bytes, not PATH_MAX bytes ;-) right, will change > > > + > > + memset(&addr, 0, sizeof(addr)); > > + addr.sun_family = AF_UNIX; > > + > > + strncpy(addr.sun_path, path, sizeof(addr.sun_path) - 1); > > strncpy may end up not adding the final \0 see the NOTES in its man > page. Consider using strlcpy instead. See: > > bef0b8970f27da5c ("perf probe: Fix unchecked usage of strncpy()") hum, it's memset-ed to 0 for that an there's -1 in the size, so I'd think there's zero at the end, but we can use strlcpy to make it more obvious SNIP > > + fprintf(stderr, "accept: %s\n", strerror(errno)); > > + return -1; > > + } > > + > > + if (sizeof(cmd) != read(fd, &cmd, sizeof(cmd))) { > > + fprintf(stderr, "read: %s\n", strerror(errno)); > > close fd > > > + return -1; > > + } > > + > > + out = fdopen(fd, "w"); > > + if (!out) { > > + perror("failed: fdopen"); > > close fd > > I.e. goto out_close; > > > + return -1; > > + } > > + > > + switch (cmd.cmd) { > > + default: > > + break; > > + } > > + > > + fclose(out); > > out_close: > > > + close(fd); > > + return ret; ugh, I overlooked this one thanks jirka