pt-kill shouldn't check if STDIN is a tty when --daemonize is given

Bug #894255 reported by William Shallum
14
This bug affects 3 people
Affects Status Importance Assigned to Milestone
Percona Toolkit moved to https://jira.percona.com/projects/PT
Fix Released
Medium
Daniel Nichter

Bug Description

I'm trying to run pt-kill from monit. STDIN is not a tty then. The problem is that pt-kill assumes it is going to read processlist from STDIN and I can find no way of disabling that assumption.

I don't think anyone would actually pipe a processlist to a process that is going to be daemonized so wouldn't it be better to check the --daemonize flag first before checking that STDIN is a tty?

Percona Toolkit version: 1.0.1

Thanks,
William

tags: added: pt-kill
Revision history for this message
James Byers (jbyers) wrote :

I believe this also affects pt-kill when run from cron. I'd be happy to supply a patch, but I'm not sure which behavior is intended. The docs say that '-' specified as a file trigger reading STDIN, however the last usage example shows STDIN detection:

  mysql -e "SHOW PROCESSLIST" | pt-kill --busy-time 60 --print

My personal preference would be for pt-kill to require '-' when used in this way.

Revision history for this message
Daniel Nichter (daniel-nichter) wrote :

pt-kill really only reads files on the command line (or piped via STDIN) for testing purposes. Normally, it connects to MySQL directly to get the processlist. How are you running the tool? It should be something like: pt-kill <options> --host <host> --user <user> --password <pass>

Revision history for this message
Baron Schwartz (baron-xaprb) wrote :

This tool isn't very user-friendly and it's one that I've got on my list to re-spec for a future release. I've had the same problem as the OP did.

Revision history for this message
Daniel Nichter (daniel-nichter) wrote :

This problem came up elsewhere, which lead to a discussion, and short story: the reporter is correct. On my Mac, for example, cron apparently pipes something to STDIN which is *not* a TTY, so this code

   if ( !-t STDIN ) {
      PTDEBUG && _d("STDIN is piped");
      @ARGV = ('-');
   }

makes the tool read from STDIN, but there's nothing there, so it exits immediately even though --daemonize was given. Reading from STDIN was so that we could test matching like "cat proclist | pt-kill ...". This is unreliable though because, for another example, on Ubuntu, cron also pipes something to STDIN but Perl says it *is* a TTY so the tool thinks it's running "normally" and therefore connects to MySQL as expected.

In short, testing STDIN and testing via STDIN are problematic so we're removing this and adding the option --test-matching FILES to make it explicit when we (or the user perhaps) wants to read FILES to test matching.

tags: added: percona-21182
Changed in percona-toolkit:
status: New → Fix Committed
assignee: nobody → Daniel Nichter (daniel-nichter)
milestone: none → 2.0.3
importance: Undecided → Medium
Changed in percona-toolkit:
status: Fix Committed → Fix Released
Changed in percona-toolkit:
status: Fix Released → Fix Committed
milestone: 2.0.3 → 2.0.4
Revision history for this message
Daniel Nichter (daniel-nichter) wrote :

This bug was not released in 2.0.3 as originally planned because the branch wasn't merged. It will be released in 2.0.4.

summary: - pt-kill: when --daemonize is given, should not check that stdin is a tty
+ pt-kill shouldn't check if stdin is a tty when --daemonize is given
summary: - pt-kill shouldn't check if stdin is a tty when --daemonize is given
+ pt-kill shouldn't check if STDIN is a tty when --daemonize is given
Changed in percona-toolkit:
status: Fix Committed → Fix Released
Revision history for this message
Shahriyar Rzayev (rzayev-sehriyar) wrote :

Percona now uses JIRA for bug reports so this bug report is migrated to: https://jira.percona.com/browse/PT-437

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.