[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <YBwOAvk0v2o2w5j9@krava>
Date: Thu, 4 Feb 2021 16:08:50 +0100
From: Jiri Olsa <jolsa@...hat.com>
To: Arnaldo Carvalho de Melo <acme@...nel.org>
Cc: Jiri Olsa <jolsa@...nel.org>, lkml <linux-kernel@...r.kernel.org>,
Peter Zijlstra <a.p.zijlstra@...llo.nl>,
Ingo Molnar <mingo@...nel.org>,
Mark Rutland <mark.rutland@....com>,
Namhyung Kim <namhyung@...nel.org>,
Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
Michael Petlan <mpetlan@...hat.com>,
Ian Rogers <irogers@...gle.com>,
Stephane Eranian <eranian@...gle.com>,
Alexei Budankov <abudankov@...wei.com>
Subject: Re: [PATCH 06/24] perf daemon: Add config file support
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 [<options>]",
> > @@ -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
Powered by blists - more mailing lists