Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1867920pxb; Fri, 5 Feb 2021 03:34:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJz+z4WZUQAKvcrtW5+wxuv9eM2STfL4kVcB2Q6LPwW6O/ZArDyjp8JYUOec7b38SCAVKRAk X-Received: by 2002:a17:906:7a42:: with SMTP id i2mr3717454ejo.27.1612524883884; Fri, 05 Feb 2021 03:34:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612524883; cv=none; d=google.com; s=arc-20160816; b=QGouOKUE0ceOkwpqnqBrdKaOnernqFFjd1wagRvZchjw+JNcAwjmJ6tMd0OE83v/QM W86/iH+KtdsjtQvqlBOXiikD/ez7+561WBR4zNsk1Q1Fqmhz+PZ26sGH4SY60ZylSDD8 sDMChlJaGZSVnTwLb8m49xraz8Y/4sMqqGJEaAon6hRI64A1q6DawD3yN3Oakv/gggLW f0Bi8t3bQV3K6I2ZG+JF60uN1jdRVjk9V1PPVHHbNB6SeMbGbj/SK8tfMngJIyq1ptE2 ZDwZg8Rim865J2nKrlqWRTeMCZ8B3lu4RkCOiUOysFXX03BzcSkEE1StzLwseHByOBzl daMg== 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=ublMmZblhO/5gA9bZNTFro6gynn7H+4IfrYhBFsMl88=; b=pXwnp4zEmuVfamZk0wYo6LuBJ/9I6gnmGKEHy1yoil8JCqbwbbWZKohLtnyLp09MrA mU+1ru/1u90gnCG8q3zbd7SlM7yW5WiDEGpFUaIwb14mzT+VOemZUC1zNYXrisER4/Ll Hh+wbi0VKlI3zqrF3dtOneBc8T5YEBXJh+VQ/oqpKXcpwk2K8gyR7e6yzBfBIblbZFbQ rtLbgLVWMB4tD1hB98OL5i2poZCVcqpZMSeLIDZ/+FqZ7SJ+ZWUqdA1cSsX8YHyipfo0 eQJMfyyH0mIAAGCVc75c+AwFZDBltR0swjl3LJhj2k9UJFLQOEOKxT/ptNVIy/r+xJtg tDiA== 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 a23si1999138eje.595.2021.02.05.03.34.18; Fri, 05 Feb 2021 03:34:43 -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 S231264AbhBELdl (ORCPT + 99 others); Fri, 5 Feb 2021 06:33:41 -0500 Received: from mail-lj1-f174.google.com ([209.85.208.174]:35186 "EHLO mail-lj1-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231563AbhBELbE (ORCPT ); Fri, 5 Feb 2021 06:31:04 -0500 Received: by mail-lj1-f174.google.com with SMTP id a17so7347296ljq.2 for ; Fri, 05 Feb 2021 03:30:48 -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=ublMmZblhO/5gA9bZNTFro6gynn7H+4IfrYhBFsMl88=; b=rSZg5vbws5WtyxfyvZw7wX8lFVW7k0Zymd7HlXurltfVPnFIBREXHk58HUqB9mKScq 5wYW3j+IPCf2n8S+FVtKNrisCn6GHfzNkdGiWk5tXKUwp0Zz+uHKCNtkRPhvLSuq0eV7 1RYY5ledNhH+tDHZQiMKO+RRZZ17cvUPf3/ro3j4zUe9SJOcS8FzZhyQEpl0Fd0SU3Ce xQ5vq2fJVM2L+4aqOiOCR7+PsHz9o4nl6rP+/mmXUAGYPbusEwhiYkudKbz9KuSl5Efg nfsWbkFNkOjXqQFGsOgccGNLZWmD5QJnZbVtinibVMrmdsI7a+1Zwgdd4BcJlgPd7Iep 7OIQ== X-Gm-Message-State: AOAM532agMJ+x/HcntnITJx94EMYUByPmdEevp3+J/U+qkeB0x+iBhGY A4uw5zuRqrJuyEErJG4QtpeV8axqlZlKFB5AftA= X-Received: by 2002:a2e:9949:: with SMTP id r9mr2264737ljj.393.1612524621893; Fri, 05 Feb 2021 03:30:21 -0800 (PST) MIME-Version: 1.0 References: <20210129134855.195810-1-jolsa@redhat.com> <20210130234856.271282-1-jolsa@kernel.org> <20210130234856.271282-5-jolsa@kernel.org> In-Reply-To: <20210130234856.271282-5-jolsa@kernel.org> From: Namhyung Kim Date: Fri, 5 Feb 2021 20:30:10 +0900 Message-ID: Subject: Re: [PATCH 04/24] perf daemon: Add server 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: > > 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); > + if (fd < 0) { > + fprintf(stderr, "socket: %s\n", strerror(errno)); > + return -1; > + } > + > + fcntl(fd, F_SETFD, FD_CLOEXEC); > + > + scnprintf(path, PATH_MAX, "%s/control", daemon->base); I couldn't find where the default value of daemon->base is set. Also 100 bytes seem not enough for the path name. Thanks, Namhyung > + > + memset(&addr, 0, sizeof(addr)); > + addr.sun_family = AF_UNIX; > + > + strncpy(addr.sun_path, path, sizeof(addr.sun_path) - 1); > + unlink(path); > + > + if (bind(fd, (struct sockaddr *)&addr, sizeof(addr)) == -1) { > + perror("failed: bind"); > + return -1; > + } > + > + if (listen(fd, 1) == -1) { > + perror("failed: listen"); > + return -1; > + } > + > + return fd; > +}