lkml.org 
[lkml]   [2021]   [Feb]   [4]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [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

\
 
 \ /
  Last update: 2021-02-04 16:14    [W:0.174 / U:0.380 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site