Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2366887pxb; Fri, 5 Feb 2021 16:35:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJwfJvItZKgXyYfL3Wf5egI1GXNZUNl7bNLeo8uHLg8OedDg2U8PMJhayWRb7StHP46tTWVc X-Received: by 2002:a05:6402:1bc7:: with SMTP id ch7mr6282665edb.124.1612571739990; Fri, 05 Feb 2021 16:35:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612571739; cv=none; d=google.com; s=arc-20160816; b=DJuD1X2TDQ/efB16bJh1wn/jPoJwObZqTq0VUjFcpqKoHmlYX2fSy3Y7dlYN2kIXeg 53zABbJjZWh2bfyRY4ZZFDStYw9dZhDQHHVTbaTslM5Mk1qzsfhQE2yqAjdjWXH9xFpS BC31iTNAMygwNdXFY8IFGl5zruqHPDIGFgHAYjHT2FAuqYLaeoSeUxEGMVY3WrX8xcbE 7e2eVDUQgPoF9tiwqRo2Byo5AwzKqw+Lb/8Sy6D+R1CvwfEzlpcLXK6HT7E/6yh17XDw pXK0N99qz+bJZVlQitRWuDwAIBOhOIdMYCN31osP32hVrv9CxkolaLz4SAFMwEenr0BC aQ6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version; bh=es/CMOpBNmEyuPK38vfc/xXnUQ3gwpJqjdelmm/M8tM=; b=IuuR1aoV6gyaZtMiPRnFL+ZCJMpliDxC+nhnjOPrvj+UhPivGYajaIPs+SqViclOPC iQ48SYIQzlkr2gy9xKwYvaj0gTdDPjONBf6pFalv03lEECKoTp0HSgp1JGw/XpuYuC60 irJgpUhM3smPcgwCH2K+CQJO2YkswaPx9A7swbj3hk2Q+xGbmt2i0/guS3qaVZFskuHD Lit8pxEPH8qEDAbEctvfM7BIfBjTXS7gb8oMsvmifRWVYJ+fVqTZUBL89MFZOSayPuoB FVqrg2UWIdpkRZEmo0qfgHjMs85XpPkZLj6bA/pvy0eNr7/IyqExQeJf5j51NU+R12s0 kD7A== ARC-Authentication-Results: i=1; mx.google.com; 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 c21si5734937eja.329.2021.02.05.16.35.16; Fri, 05 Feb 2021 16:35:39 -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; 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 S230469AbhBFAbt (ORCPT + 99 others); Fri, 5 Feb 2021 19:31:49 -0500 Received: from mail-lf1-f50.google.com ([209.85.167.50]:45990 "EHLO mail-lf1-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231453AbhBELkr (ORCPT ); Fri, 5 Feb 2021 06:40:47 -0500 Received: by mail-lf1-f50.google.com with SMTP id q12so9370043lfo.12 for ; Fri, 05 Feb 2021 03:40:31 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=es/CMOpBNmEyuPK38vfc/xXnUQ3gwpJqjdelmm/M8tM=; b=YHQYT+/fxl6XkYtWUsgOHoktJHQ3K5Z6ivixvoBdW39u2qVzZmX0WrvZuDsoULhZ8F etiQ7+VrTVJIQ3XCcapqZyXBOdtIMXKuuhpgOU75KWo7KxRMe4XKxaqiLPUxiGGdBT/I +cJ6w7TH5Y3fSVE9fXPnEKGnD9L7A7+ASLWbTABHoE56aWMzht20jTzP0et2s12n/JoS dZZcBefdLHiJ13UL6LeAOkbJ/htzGKdHN7ybvMo64G9/rGiPHlS1QEa4rWEg+bRaT8ny qfm/gHqieypgeVy2lgUX4CqxwUWNTaRxr4usQRUGynnCoaO7Gz6XVHkbVZTvWB0gjXGc V+hA== X-Gm-Message-State: AOAM530tBoRzuN2lPNzX4/nwJAZfRe0dnlo6XCXdzHPDP23uBdBg0VO1 whw8vUzow1lYKDoRiL2eF7XlzVSnWAlkBcIrwEM= X-Received: by 2002:a05:6512:2342:: with SMTP id p2mr2333999lfu.509.1612525203821; Fri, 05 Feb 2021 03:40:03 -0800 (PST) MIME-Version: 1.0 References: <20210129134855.195810-1-jolsa@redhat.com> <20210130234856.271282-1-jolsa@kernel.org> <20210130234856.271282-6-jolsa@kernel.org> In-Reply-To: <20210130234856.271282-6-jolsa@kernel.org> From: Namhyung Kim Date: Fri, 5 Feb 2021 20:39:52 +0900 Message-ID: Subject: Re: [PATCH 05/24] perf daemon: Add client socket support To: Jiri Olsa Cc: Arnaldo Carvalho de Melo , lkml , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Michael Petlan , Ian Rogers , Stephane Eranian , Alexei Budankov Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Jan 31, 2021 at 8:49 AM Jiri Olsa wrote: > > Adding support for client socket side that will be used > to send commands to daemon server socket. > > 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 | 105 ++++++++++++++++++++++++++++++++++++ > 1 file changed, 105 insertions(+) > > diff --git a/tools/perf/builtin-daemon.c b/tools/perf/builtin-daemon.c > index 756d60616d7d..eada3ceb9b0c 100644 > --- a/tools/perf/builtin-daemon.c > +++ b/tools/perf/builtin-daemon.c > @@ -11,6 +11,7 @@ > #include > #include > #include > +#include > #include > #include "builtin.h" > #include "perf.h" > @@ -42,6 +43,50 @@ static void sig_handler(int sig __maybe_unused) > done = true; > } > > +static int client_config(const char *var, const char *value, void *cb) > +{ > + struct daemon *daemon = cb; > + > + if (!strcmp(var, "daemon.base") && !daemon->base_user) { > + daemon->base = strdup(value); > + if (!daemon->base) > + return -ENOMEM; > + } > + > + return 0; > +} > + > +static int check_base(struct daemon *daemon) > +{ > + struct stat st; > + > + if (!daemon->base) { > + pr_err("failed: base not defined\n"); > + return -EINVAL; > + } > + > + if (stat(daemon->base, &st)) { > + pr_err("failed: base '%s' does not exists\n", daemon->base); Well, it could be a permission error or something.. > + return -EINVAL; > + } You may also check whether it's a directory. > + > + return 0; > +} > + > +static int setup_client_config(struct daemon *daemon) > +{ > + struct perf_config_set *set; > + int err = -ENOMEM; > + > + set = perf_config_set__load_file(daemon->config_real); > + if (set) { > + err = perf_config_set(set, client_config, daemon); > + perf_config_set__delete(set); > + } > + > + return err ?: check_base(daemon); > +} > + > static int setup_server_socket(struct daemon *daemon) > { > struct sockaddr_un addr; > @@ -114,6 +159,32 @@ static int handle_server_socket(struct daemon *daemon __maybe_unused, int sock_f > return ret; > } > > +static int setup_client_socket(struct daemon *daemon) > +{ > + struct sockaddr_un addr; > + char path[100]; > + int fd; > + > + fd = socket(AF_UNIX, SOCK_STREAM, 0); > + if (fd == -1) { > + perror("failed: socket"); > + return -1; > + } > + > + scnprintf(path, PATH_MAX, "%s/control", daemon->base); Same as the previous patch. The path is 100 bytes.. Thanks, Namhyung > + > + memset(&addr, 0, sizeof(addr)); > + addr.sun_family = AF_UNIX; > + strncpy(addr.sun_path, path, sizeof(addr.sun_path) - 1); > + > + if (connect(fd, (struct sockaddr *) &addr, sizeof(addr)) == -1) { > + perror("failed: connect"); > + return -1; > + } > + > + return fd; > +}