Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1557135pxb; Thu, 4 Feb 2021 16:43:29 -0800 (PST) X-Google-Smtp-Source: ABdhPJwJVF4e8RhjocXUCnECLqkkwaLl+kiAFN4GkVeiqdB1fQ65CF4LiKRX4UMw/G7g0T2GvqlD X-Received: by 2002:aa7:c682:: with SMTP id n2mr1156894edq.27.1612485809678; Thu, 04 Feb 2021 16:43:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612485809; cv=none; d=google.com; s=arc-20160816; b=QxXEMjo0NNBdNvsGi0PFEiGHX+zizwblvoZfLU6MFNbFs/6k236tTEi0TFo9+T6thQ buKl5RTAqqaHJYQZ5pfgQnWlJ5TyEMcqKTxBFNd8HN3c+vJwK+CEQmjjAJfdMYwbnGPf NOab14qoyhZELUrCVmL5/lReRC9VYNX4bIPobICnnRvhc5zEh6sxFytMJtHvIsV237z7 kOCDaIH2X8HdDElyCxVrM51It/nHZXMET30EhY0kBShcO05ETVkdWx+MjVuIyOtdSxCf 9O54391TpbQfsZdnR4EY7KExWyg3DyYhz4Ja0dYQLQ/omwCxyLRehvBOabdEPd2VoaJG INaw== 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=TPzNrEWsn+M24PwS5ETMEy5ZMgF7btgTtrcFRzwGCWc=; b=wPy1clwLJeNCWQptwGWzi0dtGgnrzDKvfVpcgNV/sYZorhXJed/n+HqhR2p/h3jJ9w k679JzDGtwHH6arQffTuAjwobu9VGbqhT2JdH164jTYQAXwSvAMZDGk6UwZVzNUzF2p6 ljmS6Qfzmk7IKhwMfABIDPaljkAnHN3Z5Zj3QaCNM6UGGMb7ZhZqDAGsprgyg8los5XX nVNfTMvxF9YRNfjUmJMXSu86kx1DxZ0IaceMegYsqa9+gxcZeoRecHwWCQX+QpITBrAG lsxU5op5SWfYCWuELL9zVSWGXBgnQcrWQVMrOb5n39kGuglUiY8fSPT8kZVn5msSSFqe bDkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=fbDg9tqb; 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 m15si4069056eje.225.2021.02.04.16.43.05; Thu, 04 Feb 2021 16:43:29 -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=fbDg9tqb; 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 S237189AbhBDPM1 (ORCPT + 99 others); Thu, 4 Feb 2021 10:12:27 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:57786 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237180AbhBDPK1 (ORCPT ); Thu, 4 Feb 2021 10:10:27 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612451341; 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=TPzNrEWsn+M24PwS5ETMEy5ZMgF7btgTtrcFRzwGCWc=; b=fbDg9tqbDWeGAjsia2AtrQNcyvjzTpqT0gN6oNsuRB7MY1UXTNEn3XoOJaNn5rLhHNWk2O j/Y9/AnlGnwKKTwpAqiNWh5cbPDQgno63A9FrolB53+dIUrcvtcMkX4rXoSoUAns/jy+qU aVRcc7uk0DFg08uYLOOZqbgbycffoy8= 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-328-kLRdj8ddORKE-jrqw1rfOg-1; Thu, 04 Feb 2021 10:08:55 -0500 X-MC-Unique: kLRdj8ddORKE-jrqw1rfOg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B36826D4E6; Thu, 4 Feb 2021 15:08:53 +0000 (UTC) Received: from krava (unknown [10.40.194.33]) by smtp.corp.redhat.com (Postfix) with SMTP id 4E77019708; Thu, 4 Feb 2021 15:08:51 +0000 (UTC) Date: Thu, 4 Feb 2021 16:08:50 +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 06/24] perf daemon: Add config file support Message-ID: References: <20210129134855.195810-1-jolsa@redhat.com> <20210130234856.271282-1-jolsa@kernel.org> <20210130234856.271282-7-jolsa@kernel.org> <20210203211211.GS854763@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210203211211.GS854763@kernel.org> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 03, 2021 at 06:12:11PM -0300, Arnaldo Carvalho de Melo wrote: SNIP > > -static struct daemon __daemon = { }; > > +static struct daemon __daemon = { > > + .sessions = LIST_HEAD_INIT(__daemon.sessions), > > +}; > > > > static const char * const daemon_usage[] = { > > "perf daemon start []", > > @@ -43,6 +97,128 @@ static void sig_handler(int sig __maybe_unused) > > done = true; > > } > > > > +static struct session* > > +daemon__add_session(struct daemon *config, char *name) > > +{ > > + struct session *session; > > + > > + session = zalloc(sizeof(*session)); > > > struct session *session = zalloc(sizeof(*session)); > > > + if (!session) > > + return NULL; > > + > > + session->name = strdup(name); > > + if (!session->name) { > > + free(session); > > + return NULL; > > + } > > + > > + session->pid = -1; > > + list_add_tail(&session->list, &config->sessions); > > + return session; > > +} > > + > > +static struct session* > > add space after type name > > static struct session * > > And we could have it in the same line: > > static struct session *daemon__find_session(struct daemon *daemon, char *name) ok SNIP > > + /* > > + * Either new or changed run value is defined, > > + * trigger reconfig for the session. > > + */ > > + session->state = SESSION_STATE__RECONFIG; > > + } > > + } > > + > > + return 0; > > +} > > + > > +static int server_config(const char *var, const char *value, void *cb) > > +{ > > + struct daemon *daemon = cb; > > + > > + if (strstarts(var, "session-")) > > + return session_config(daemon, var, value); > > + else if (!strcmp(var, "daemon.base") && !daemon->base_user) { > > if else uses {}, if should too ok SNIP > > + > > +static void session__free(struct session *session) > > +{ > > + free(session->base); > > + free(session->name); > > + free(session->run); > > zfree() so that if there is some dangling pointer to session, we'll get > NULL derefs and won't be notified by crash about the error ;-) ok > > > + free(session); > > +} > > + > > +static void session__remove(struct session *session) > > +{ > > + list_del(&session->list); > > list_del_init > > > + session__free(session); > > +} > > + > > +static void daemon__kill(struct daemon *daemon) > > +{ > > + daemon__signal(daemon, SIGTERM); > > +} > > + > > static void daemon__free(struct daemon *daemon) > > { > > + struct session *session, *h; > > + > > + list_for_each_entry_safe(session, h, &daemon->sessions, list) > > + session__remove(session); > > Wouldn't be better to have: > > list_for_each_entry_safe(session, h, &daemon->sessions, list) { > list_del_init(&session->list); > session__free(session); > } > > Because naming that function "session__remove()" one thinks it is being > removed from some data structure, but not that it is being as well > deleted. > > Please rename session__free() to session__delete() to keep it consistent > with other places. ok > > > + > > free(daemon->config_real); > > free(daemon->base); > > } > > > > static void daemon__exit(struct daemon *daemon) > > { > > + daemon__kill(daemon); > > daemon__free(daemon); > > Ditto for daemon__free(): please rename it to daemon__delete() ok thanks, jirka