lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <9be5f3fb3cf3493abf50e7acbab48d47@ustx2ex-dag1mb5.msg.corp.akamai.com>
Date:   Wed, 23 Oct 2019 16:06:53 +0000
From:   "Lubashev, Igor" <ilubashe@...mai.com>
To:     Jiri Olsa <jolsa@...hat.com>
CC:     Peter Zijlstra <peterz@...radead.org>,
        Ingo Molnar <mingo@...hat.com>,
        Arnaldo Carvalho de Melo <acme@...hat.com>,
        Jiri Olsa <jolsa@...nel.org>,
        Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
        Namhyung Kim <namhyung@...nel.org>,
        Mark Rutland <mark.rutland@....com>,
        "Linux Kernel Mailing List" <linux-kernel@...r.kernel.org>
Subject: RE: [PATCH 2/3] perf kvm: Allow running without stdin

> On Wed, Oct 23, 2019 at 6:43 AM Jiri Olsa <jolsa@...hat.com> wrote:
> 
> On Tue, Oct 22, 2019 at 09:54:52PM -0400, Igor Lubashev wrote:
> > Allow perf kvm --stdio to run without access to stdin.
> > This lets perf kvm to run in a batch mode until interrupted.
> >
> > The following now works as expected:
> >
> >   $ perf kvm top --stdio < /dev/null
> >
> > Signed-off-by: Igor Lubashev <ilubashe@...mai.com>
> > ---
> >  tools/perf/builtin-kvm.c | 33 ++++++++++++++++++++-------------
> >  1 file changed, 20 insertions(+), 13 deletions(-)
> >
> > diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index
> > 858da896b518..5217aa3596c7 100644
> > --- a/tools/perf/builtin-kvm.c
> > +++ b/tools/perf/builtin-kvm.c
> > @@ -930,18 +930,20 @@ static int fd_set_nonblock(int fd)
> >
> >  static int perf_kvm__handle_stdin(void)  {
> > -	int c;
> > -
> > -	c = getc(stdin);
> > -	if (c == 'q')
> > +	switch (getc(stdin)) {
> > +	case 'q':
> > +		done = 1;
> >  		return 1;
> > -
> > -	return 0;
> > +	case EOF:
> > +		return 0;
> > +	default:
> > +		return 1;
> > +	}
> >  }
> >
> >  static int kvm_events_live_report(struct perf_kvm_stat *kvm)  {
> > -	int nr_stdin, ret, err = -EINVAL;
> > +	int nr_stdin = -1, ret, err = -EINVAL;
> >  	struct termios save;
> >
> >  	/* live flag must be set first */
> > @@ -972,13 +974,16 @@ static int kvm_events_live_report(struct
> perf_kvm_stat *kvm)
> >  	if (evlist__add_pollfd(kvm->evlist, kvm->timerfd) < 0)
> >  		goto out;
> >
> > -	nr_stdin = evlist__add_pollfd(kvm->evlist, fileno(stdin));
> > -	if (nr_stdin < 0)
> > -		goto out;
> > -
> >  	if (fd_set_nonblock(fileno(stdin)) != 0)
> >  		goto out;
> >
> > +	/* add stdin, if it is connected */
> > +	if (getc(stdin) != EOF) {
> > +		nr_stdin = evlist__add_pollfd(kvm->evlist, fileno(stdin));
> > +		if (nr_stdin < 0)
> > +			goto out;
> > +	}
> > +
> >  	/* everything is good - enable the events and process */
> >  	evlist__enable(kvm->evlist);
> >
> > @@ -994,8 +999,10 @@ static int kvm_events_live_report(struct
> perf_kvm_stat *kvm)
> >  		if (err)
> >  			goto out;
> >
> > -		if (fda->entries[nr_stdin].revents & POLLIN)
> > -			done = perf_kvm__handle_stdin();
> > +		if (nr_stdin >= 0 && fda->entries[nr_stdin].revents & POLLIN)
> {
> > +			if (!perf_kvm__handle_stdin())
> 
> can this return 0 ? if stdin is EOF then nr_stdin stays -1
> 
> > +				fda->entries[nr_stdin].events = 0;
> 
> why do you need to set events to 0 in here?

Otherwise poll() would wakeup continually, since an EOF stdin is already ready for POLLIN.

- Igor

> thanks,
> jirka

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ