Re: [PATCH 05/24] perf daemon: Add client socket support

From: Jiri Olsa
Date: Thu Feb 04 2021 - 14:33:33 EST


On Wed, Feb 03, 2021 at 06:05:47PM -0300, Arnaldo Carvalho de Melo wrote:

SNIP

>
> close fd
>
> > + return -1;
> > + }
> > +
> > + return fd;
> > +}
> > +
> > static void daemon__free(struct daemon *daemon)
> > {
> > free(daemon->config_real);
> > @@ -211,6 +282,40 @@ static int __cmd_start(struct daemon *daemon, struct option parent_options[],
> > return err;
> > }
> >
> > +__maybe_unused
> > +static int send_cmd(struct daemon *daemon, union cmd *cmd)
> > +{
> > + char *line = NULL;
> > + size_t len = 0;
> > + ssize_t nread;
> > + FILE *in;
> > + int fd;
> > +
> > + if (setup_client_config(daemon))
> > + return -1;
> > +
> > + fd = setup_client_socket(daemon);
> > + if (fd < 0)
> > + return -1;
> > +
> > + if (sizeof(*cmd) != write(fd, cmd, sizeof(*cmd)))
>
> close fd
>
> > + return -1;
> > +
> > + in = fdopen(fd, "r");
> > + if (!in) {
> > + perror("failed: fdopen");
>
> close fd

ah right, thanks

jirka

>
> > + return -1;
> > + }
> > +
> > + while ((nread = getline(&line, &len, in)) != -1) {
> > + fwrite(line, nread, 1, stdout);
> > + fflush(stdout);
> > + }
> > +
> > + fclose(in);
> > + return 0;
> > +}
> > +
> > int cmd_daemon(int argc, const char **argv)
> > {
> > struct option daemon_options[] = {
> > --
> > 2.29.2
> >
>
> --
>
> - Arnaldo
>