diff --git a/bin/pt-archiver b/bin/pt-archiver index 35fe3f21..2053c2bc 100755 --- a/bin/pt-archiver +++ b/bin/pt-archiver @@ -3394,6 +3394,7 @@ sub new { force_log_file => $args{force_log_file}, parent_exit => $args{parent_exit}, pid_file_owner => 0, + utf8 => $args{utf8} // 0, }; return bless $self, $class; } @@ -3406,6 +3407,7 @@ sub run { my $log_file = $self->{log_file}; my $force_log_file = $self->{force_log_file}; my $parent_exit = $self->{parent_exit}; + my $utf8 = $self->{utf8}; PTDEBUG && _d('Starting daemon'); @@ -3452,10 +3454,19 @@ sub run { close STDOUT; open STDOUT, '>>', $log_file or die "Cannot open log file $log_file: $OS_ERROR"; + if ( $utf8 ) { + binmode(STDOUT, ':utf8') + or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR"; + } + close STDERR; open STDERR, ">&STDOUT" or die "Cannot dupe STDERR to STDOUT: $OS_ERROR"; + if ( $utf8 ) { + binmode(STDERR, ':utf8') + or die "Can't binmode(STDERR, ':utf8'): $OS_ERROR"; + } } else { if ( -t STDOUT ) { diff --git a/bin/pt-config-diff b/bin/pt-config-diff index 2d655476..3588dc50 100755 --- a/bin/pt-config-diff +++ b/bin/pt-config-diff @@ -2607,6 +2607,7 @@ sub new { force_log_file => $args{force_log_file}, parent_exit => $args{parent_exit}, pid_file_owner => 0, + utf8 => $args{utf8} // 0, }; return bless $self, $class; } @@ -2619,6 +2620,7 @@ sub run { my $log_file = $self->{log_file}; my $force_log_file = $self->{force_log_file}; my $parent_exit = $self->{parent_exit}; + my $utf8 = $self->{utf8}; PTDEBUG && _d('Starting daemon'); @@ -2665,10 +2667,19 @@ sub run { close STDOUT; open STDOUT, '>>', $log_file or die "Cannot open log file $log_file: $OS_ERROR"; + if ( $utf8 ) { + binmode(STDOUT, ':utf8') + or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR"; + } + close STDERR; open STDERR, ">&STDOUT" or die "Cannot dupe STDERR to STDOUT: $OS_ERROR"; + if ( $utf8 ) { + binmode(STDERR, ':utf8') + or die "Can't binmode(STDERR, ':utf8'): $OS_ERROR"; + } } else { if ( -t STDOUT ) { diff --git a/bin/pt-deadlock-logger b/bin/pt-deadlock-logger index 02e4cee5..b9324708 100755 --- a/bin/pt-deadlock-logger +++ b/bin/pt-deadlock-logger @@ -2951,6 +2951,7 @@ sub new { force_log_file => $args{force_log_file}, parent_exit => $args{parent_exit}, pid_file_owner => 0, + utf8 => $args{utf8} // 0, }; return bless $self, $class; } @@ -2963,6 +2964,7 @@ sub run { my $log_file = $self->{log_file}; my $force_log_file = $self->{force_log_file}; my $parent_exit = $self->{parent_exit}; + my $utf8 = $self->{utf8}; PTDEBUG && _d('Starting daemon'); @@ -3009,10 +3011,19 @@ sub run { close STDOUT; open STDOUT, '>>', $log_file or die "Cannot open log file $log_file: $OS_ERROR"; + if ( $utf8 ) { + binmode(STDOUT, ':utf8') + or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR"; + } + close STDERR; open STDERR, ">&STDOUT" or die "Cannot dupe STDERR to STDOUT: $OS_ERROR"; + if ( $utf8 ) { + binmode(STDERR, ':utf8') + or die "Can't binmode(STDERR, ':utf8'): $OS_ERROR"; + } } else { if ( -t STDOUT ) { diff --git a/bin/pt-duplicate-key-checker b/bin/pt-duplicate-key-checker index 8ef691b4..118550cb 100755 --- a/bin/pt-duplicate-key-checker +++ b/bin/pt-duplicate-key-checker @@ -2835,6 +2835,7 @@ sub new { force_log_file => $args{force_log_file}, parent_exit => $args{parent_exit}, pid_file_owner => 0, + utf8 => $args{utf8} // 0, }; return bless $self, $class; } @@ -2847,6 +2848,7 @@ sub run { my $log_file = $self->{log_file}; my $force_log_file = $self->{force_log_file}; my $parent_exit = $self->{parent_exit}; + my $utf8 = $self->{utf8}; PTDEBUG && _d('Starting daemon'); @@ -2893,10 +2895,19 @@ sub run { close STDOUT; open STDOUT, '>>', $log_file or die "Cannot open log file $log_file: $OS_ERROR"; + if ( $utf8 ) { + binmode(STDOUT, ':utf8') + or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR"; + } + close STDERR; open STDERR, ">&STDOUT" or die "Cannot dupe STDERR to STDOUT: $OS_ERROR"; + if ( $utf8 ) { + binmode(STDERR, ':utf8') + or die "Can't binmode(STDERR, ':utf8'): $OS_ERROR"; + } } else { if ( -t STDOUT ) { diff --git a/bin/pt-fifo-split b/bin/pt-fifo-split index 5ad1ec28..65a73467 100755 --- a/bin/pt-fifo-split +++ b/bin/pt-fifo-split @@ -1158,6 +1158,7 @@ sub new { force_log_file => $args{force_log_file}, parent_exit => $args{parent_exit}, pid_file_owner => 0, + utf8 => $args{utf8} // 0, }; return bless $self, $class; } @@ -1170,6 +1171,7 @@ sub run { my $log_file = $self->{log_file}; my $force_log_file = $self->{force_log_file}; my $parent_exit = $self->{parent_exit}; + my $utf8 = $self->{utf8}; PTDEBUG && _d('Starting daemon'); @@ -1216,10 +1218,19 @@ sub run { close STDOUT; open STDOUT, '>>', $log_file or die "Cannot open log file $log_file: $OS_ERROR"; + if ( $utf8 ) { + binmode(STDOUT, ':utf8') + or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR"; + } + close STDERR; open STDERR, ">&STDOUT" or die "Cannot dupe STDERR to STDOUT: $OS_ERROR"; + if ( $utf8 ) { + binmode(STDERR, ':utf8') + or die "Can't binmode(STDERR, ':utf8'): $OS_ERROR"; + } } else { if ( -t STDOUT ) { diff --git a/bin/pt-find b/bin/pt-find index edee4639..19b45a37 100755 --- a/bin/pt-find +++ b/bin/pt-find @@ -2277,6 +2277,7 @@ sub new { force_log_file => $args{force_log_file}, parent_exit => $args{parent_exit}, pid_file_owner => 0, + utf8 => $args{utf8} // 0, }; return bless $self, $class; } @@ -2289,6 +2290,7 @@ sub run { my $log_file = $self->{log_file}; my $force_log_file = $self->{force_log_file}; my $parent_exit = $self->{parent_exit}; + my $utf8 = $self->{utf8}; PTDEBUG && _d('Starting daemon'); @@ -2335,10 +2337,19 @@ sub run { close STDOUT; open STDOUT, '>>', $log_file or die "Cannot open log file $log_file: $OS_ERROR"; + if ( $utf8 ) { + binmode(STDOUT, ':utf8') + or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR"; + } + close STDERR; open STDERR, ">&STDOUT" or die "Cannot dupe STDERR to STDOUT: $OS_ERROR"; + if ( $utf8 ) { + binmode(STDERR, ':utf8') + or die "Can't binmode(STDERR, ':utf8'): $OS_ERROR"; + } } else { if ( -t STDOUT ) { diff --git a/bin/pt-fk-error-logger b/bin/pt-fk-error-logger index a9d218d8..56e0c1fc 100755 --- a/bin/pt-fk-error-logger +++ b/bin/pt-fk-error-logger @@ -2105,6 +2105,7 @@ sub new { force_log_file => $args{force_log_file}, parent_exit => $args{parent_exit}, pid_file_owner => 0, + utf8 => $args{utf8} // 0, }; return bless $self, $class; } @@ -2117,6 +2118,7 @@ sub run { my $log_file = $self->{log_file}; my $force_log_file = $self->{force_log_file}; my $parent_exit = $self->{parent_exit}; + my $utf8 = $self->{utf8}; PTDEBUG && _d('Starting daemon'); @@ -2163,10 +2165,19 @@ sub run { close STDOUT; open STDOUT, '>>', $log_file or die "Cannot open log file $log_file: $OS_ERROR"; + if ( $utf8 ) { + binmode(STDOUT, ':utf8') + or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR"; + } + close STDERR; open STDERR, ">&STDOUT" or die "Cannot dupe STDERR to STDOUT: $OS_ERROR"; + if ( $utf8 ) { + binmode(STDERR, ':utf8') + or die "Can't binmode(STDERR, ':utf8'): $OS_ERROR"; + } } else { if ( -t STDOUT ) { diff --git a/bin/pt-heartbeat b/bin/pt-heartbeat index a32c092c..443bee8e 100755 --- a/bin/pt-heartbeat +++ b/bin/pt-heartbeat @@ -3208,6 +3208,7 @@ sub new { force_log_file => $args{force_log_file}, parent_exit => $args{parent_exit}, pid_file_owner => 0, + utf8 => $args{utf8} // 0, }; return bless $self, $class; } @@ -3220,6 +3221,7 @@ sub run { my $log_file = $self->{log_file}; my $force_log_file = $self->{force_log_file}; my $parent_exit = $self->{parent_exit}; + my $utf8 = $self->{utf8}; PTDEBUG && _d('Starting daemon'); @@ -3266,10 +3268,19 @@ sub run { close STDOUT; open STDOUT, '>>', $log_file or die "Cannot open log file $log_file: $OS_ERROR"; + if ( $utf8 ) { + binmode(STDOUT, ':utf8') + or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR"; + } + close STDERR; open STDERR, ">&STDOUT" or die "Cannot dupe STDERR to STDOUT: $OS_ERROR"; + if ( $utf8 ) { + binmode(STDERR, ':utf8') + or die "Can't binmode(STDERR, ':utf8'): $OS_ERROR"; + } } else { if ( -t STDOUT ) { diff --git a/bin/pt-kill b/bin/pt-kill index 2f1a8518..6e9448c6 100755 --- a/bin/pt-kill +++ b/bin/pt-kill @@ -2333,6 +2333,7 @@ sub new { force_log_file => $args{force_log_file}, parent_exit => $args{parent_exit}, pid_file_owner => 0, + utf8 => $args{utf8} // 0, }; return bless $self, $class; } @@ -2345,6 +2346,7 @@ sub run { my $log_file = $self->{log_file}; my $force_log_file = $self->{force_log_file}; my $parent_exit = $self->{parent_exit}; + my $utf8 = $self->{utf8}; PTDEBUG && _d('Starting daemon'); @@ -2391,10 +2393,19 @@ sub run { close STDOUT; open STDOUT, '>>', $log_file or die "Cannot open log file $log_file: $OS_ERROR"; + if ( $utf8 ) { + binmode(STDOUT, ':utf8') + or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR"; + } + close STDERR; open STDERR, ">&STDOUT" or die "Cannot dupe STDERR to STDOUT: $OS_ERROR"; + if ( $utf8 ) { + binmode(STDERR, ':utf8') + or die "Can't binmode(STDERR, ':utf8'): $OS_ERROR"; + } } else { if ( -t STDOUT ) { @@ -7340,11 +7351,16 @@ sub main { # we're not daemoninzing, it just handles PID stuff. # ######################################################################## my $daemon; + my $utf8 = 0; + if ( $dbh && $dbh->{mysql_enable_utf8} ) { + $utf8 = 1; + } if ( $o->get('daemonize') || $o->get('pid')) { $daemon = new Daemon( - log_file => $o->get('log'), - pid_file => $o->get('pid'), + log_file => $o->get('log'), + pid_file => $o->get('pid'), daemonize => $o->get('daemonize'), + utf8 => $utf8, ); $daemon->run(); PTDEBUG && $o->get('daemonize') && _d('I am a daemon now'); diff --git a/bin/pt-online-schema-change b/bin/pt-online-schema-change index 4b532ea5..06bd7022 100755 --- a/bin/pt-online-schema-change +++ b/bin/pt-online-schema-change @@ -2583,6 +2583,7 @@ sub new { force_log_file => $args{force_log_file}, parent_exit => $args{parent_exit}, pid_file_owner => 0, + utf8 => $args{utf8} // 0, }; return bless $self, $class; } @@ -2595,6 +2596,7 @@ sub run { my $log_file = $self->{log_file}; my $force_log_file = $self->{force_log_file}; my $parent_exit = $self->{parent_exit}; + my $utf8 = $self->{utf8}; PTDEBUG && _d('Starting daemon'); @@ -2641,10 +2643,19 @@ sub run { close STDOUT; open STDOUT, '>>', $log_file or die "Cannot open log file $log_file: $OS_ERROR"; + if ( $utf8 ) { + binmode(STDOUT, ':utf8') + or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR"; + } + close STDERR; open STDERR, ">&STDOUT" or die "Cannot dupe STDERR to STDOUT: $OS_ERROR"; + if ( $utf8 ) { + binmode(STDERR, ':utf8') + or die "Can't binmode(STDERR, ':utf8'): $OS_ERROR"; + } } else { if ( -t STDOUT ) { diff --git a/bin/pt-query-digest b/bin/pt-query-digest index ccf58de4..402f8de8 100755 --- a/bin/pt-query-digest +++ b/bin/pt-query-digest @@ -9508,6 +9508,7 @@ sub new { force_log_file => $args{force_log_file}, parent_exit => $args{parent_exit}, pid_file_owner => 0, + utf8 => $args{utf8} // 0, }; return bless $self, $class; } @@ -9520,6 +9521,7 @@ sub run { my $log_file = $self->{log_file}; my $force_log_file = $self->{force_log_file}; my $parent_exit = $self->{parent_exit}; + my $utf8 = $self->{utf8}; PTDEBUG && _d('Starting daemon'); @@ -9566,10 +9568,19 @@ sub run { close STDOUT; open STDOUT, '>>', $log_file or die "Cannot open log file $log_file: $OS_ERROR"; + if ( $utf8 ) { + binmode(STDOUT, ':utf8') + or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR"; + } + close STDERR; open STDERR, ">&STDOUT" or die "Cannot dupe STDERR to STDOUT: $OS_ERROR"; + if ( $utf8 ) { + binmode(STDERR, ':utf8') + or die "Can't binmode(STDERR, ':utf8'): $OS_ERROR"; + } } else { if ( -t STDOUT ) { diff --git a/bin/pt-show-grants b/bin/pt-show-grants index 34d4d0e3..245e4738 100755 --- a/bin/pt-show-grants +++ b/bin/pt-show-grants @@ -1605,6 +1605,7 @@ sub new { force_log_file => $args{force_log_file}, parent_exit => $args{parent_exit}, pid_file_owner => 0, + utf8 => $args{utf8} // 0, }; return bless $self, $class; } @@ -1617,6 +1618,7 @@ sub run { my $log_file = $self->{log_file}; my $force_log_file = $self->{force_log_file}; my $parent_exit = $self->{parent_exit}; + my $utf8 = $self->{utf8}; PTDEBUG && _d('Starting daemon'); @@ -1663,10 +1665,19 @@ sub run { close STDOUT; open STDOUT, '>>', $log_file or die "Cannot open log file $log_file: $OS_ERROR"; + if ( $utf8 ) { + binmode(STDOUT, ':utf8') + or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR"; + } + close STDERR; open STDERR, ">&STDOUT" or die "Cannot dupe STDERR to STDOUT: $OS_ERROR"; + if ( $utf8 ) { + binmode(STDERR, ':utf8') + or die "Can't binmode(STDERR, ':utf8'): $OS_ERROR"; + } } else { if ( -t STDOUT ) { diff --git a/bin/pt-slave-delay b/bin/pt-slave-delay index 6a8cf73f..0ebfd448 100755 --- a/bin/pt-slave-delay +++ b/bin/pt-slave-delay @@ -2326,6 +2326,7 @@ sub new { force_log_file => $args{force_log_file}, parent_exit => $args{parent_exit}, pid_file_owner => 0, + utf8 => $args{utf8} // 0, }; return bless $self, $class; } @@ -2338,6 +2339,7 @@ sub run { my $log_file = $self->{log_file}; my $force_log_file = $self->{force_log_file}; my $parent_exit = $self->{parent_exit}; + my $utf8 = $self->{utf8}; PTDEBUG && _d('Starting daemon'); @@ -2384,10 +2386,19 @@ sub run { close STDOUT; open STDOUT, '>>', $log_file or die "Cannot open log file $log_file: $OS_ERROR"; + if ( $utf8 ) { + binmode(STDOUT, ':utf8') + or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR"; + } + close STDERR; open STDERR, ">&STDOUT" or die "Cannot dupe STDERR to STDOUT: $OS_ERROR"; + if ( $utf8 ) { + binmode(STDERR, ':utf8') + or die "Can't binmode(STDERR, ':utf8'): $OS_ERROR"; + } } else { if ( -t STDOUT ) { diff --git a/bin/pt-slave-find b/bin/pt-slave-find index 73e0446e..70c6a1d0 100755 --- a/bin/pt-slave-find +++ b/bin/pt-slave-find @@ -3139,6 +3139,7 @@ sub new { force_log_file => $args{force_log_file}, parent_exit => $args{parent_exit}, pid_file_owner => 0, + utf8 => $args{utf8} // 0, }; return bless $self, $class; } @@ -3151,6 +3152,7 @@ sub run { my $log_file = $self->{log_file}; my $force_log_file = $self->{force_log_file}; my $parent_exit = $self->{parent_exit}; + my $utf8 = $self->{utf8}; PTDEBUG && _d('Starting daemon'); @@ -3197,10 +3199,19 @@ sub run { close STDOUT; open STDOUT, '>>', $log_file or die "Cannot open log file $log_file: $OS_ERROR"; + if ( $utf8 ) { + binmode(STDOUT, ':utf8') + or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR"; + } + close STDERR; open STDERR, ">&STDOUT" or die "Cannot dupe STDERR to STDOUT: $OS_ERROR"; + if ( $utf8 ) { + binmode(STDERR, ':utf8') + or die "Can't binmode(STDERR, ':utf8'): $OS_ERROR"; + } } else { if ( -t STDOUT ) { diff --git a/bin/pt-slave-restart b/bin/pt-slave-restart index 3c49f9d8..9e49ceeb 100755 --- a/bin/pt-slave-restart +++ b/bin/pt-slave-restart @@ -3550,6 +3550,7 @@ sub new { force_log_file => $args{force_log_file}, parent_exit => $args{parent_exit}, pid_file_owner => 0, + utf8 => $args{utf8} // 0, }; return bless $self, $class; } @@ -3562,6 +3563,7 @@ sub run { my $log_file = $self->{log_file}; my $force_log_file = $self->{force_log_file}; my $parent_exit = $self->{parent_exit}; + my $utf8 = $self->{utf8}; PTDEBUG && _d('Starting daemon'); @@ -3608,10 +3610,19 @@ sub run { close STDOUT; open STDOUT, '>>', $log_file or die "Cannot open log file $log_file: $OS_ERROR"; + if ( $utf8 ) { + binmode(STDOUT, ':utf8') + or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR"; + } + close STDERR; open STDERR, ">&STDOUT" or die "Cannot dupe STDERR to STDOUT: $OS_ERROR"; + if ( $utf8 ) { + binmode(STDERR, ':utf8') + or die "Can't binmode(STDERR, ':utf8'): $OS_ERROR"; + } } else { if ( -t STDOUT ) { diff --git a/bin/pt-table-checksum b/bin/pt-table-checksum index 9e6bb62f..9f6041fc 100755 --- a/bin/pt-table-checksum +++ b/bin/pt-table-checksum @@ -7450,6 +7450,7 @@ sub new { force_log_file => $args{force_log_file}, parent_exit => $args{parent_exit}, pid_file_owner => 0, + utf8 => $args{utf8} // 0, }; return bless $self, $class; } @@ -7462,6 +7463,7 @@ sub run { my $log_file = $self->{log_file}; my $force_log_file = $self->{force_log_file}; my $parent_exit = $self->{parent_exit}; + my $utf8 = $self->{utf8}; PTDEBUG && _d('Starting daemon'); @@ -7508,10 +7510,19 @@ sub run { close STDOUT; open STDOUT, '>>', $log_file or die "Cannot open log file $log_file: $OS_ERROR"; + if ( $utf8 ) { + binmode(STDOUT, ':utf8') + or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR"; + } + close STDERR; open STDERR, ">&STDOUT" or die "Cannot dupe STDERR to STDOUT: $OS_ERROR"; + if ( $utf8 ) { + binmode(STDERR, ':utf8') + or die "Can't binmode(STDERR, ':utf8'): $OS_ERROR"; + } } else { if ( -t STDOUT ) { diff --git a/bin/pt-table-sync b/bin/pt-table-sync index 7660cfe4..35ca5e11 100755 --- a/bin/pt-table-sync +++ b/bin/pt-table-sync @@ -7568,6 +7568,7 @@ sub new { force_log_file => $args{force_log_file}, parent_exit => $args{parent_exit}, pid_file_owner => 0, + utf8 => $args{utf8} // 0, }; return bless $self, $class; } @@ -7580,6 +7581,7 @@ sub run { my $log_file = $self->{log_file}; my $force_log_file = $self->{force_log_file}; my $parent_exit = $self->{parent_exit}; + my $utf8 = $self->{utf8}; PTDEBUG && _d('Starting daemon'); @@ -7626,10 +7628,19 @@ sub run { close STDOUT; open STDOUT, '>>', $log_file or die "Cannot open log file $log_file: $OS_ERROR"; + if ( $utf8 ) { + binmode(STDOUT, ':utf8') + or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR"; + } + close STDERR; open STDERR, ">&STDOUT" or die "Cannot dupe STDERR to STDOUT: $OS_ERROR"; + if ( $utf8 ) { + binmode(STDERR, ':utf8') + or die "Can't binmode(STDERR, ':utf8'): $OS_ERROR"; + } } else { if ( -t STDOUT ) { diff --git a/bin/pt-upgrade b/bin/pt-upgrade index a3dee5d2..aab75680 100755 --- a/bin/pt-upgrade +++ b/bin/pt-upgrade @@ -3131,6 +3131,7 @@ sub new { force_log_file => $args{force_log_file}, parent_exit => $args{parent_exit}, pid_file_owner => 0, + utf8 => $args{utf8} // 0, }; return bless $self, $class; } @@ -3143,6 +3144,7 @@ sub run { my $log_file = $self->{log_file}; my $force_log_file = $self->{force_log_file}; my $parent_exit = $self->{parent_exit}; + my $utf8 = $self->{utf8}; PTDEBUG && _d('Starting daemon'); @@ -3189,10 +3191,19 @@ sub run { close STDOUT; open STDOUT, '>>', $log_file or die "Cannot open log file $log_file: $OS_ERROR"; + if ( $utf8 ) { + binmode(STDOUT, ':utf8') + or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR"; + } + close STDERR; open STDERR, ">&STDOUT" or die "Cannot dupe STDERR to STDOUT: $OS_ERROR"; + if ( $utf8 ) { + binmode(STDERR, ':utf8') + or die "Can't binmode(STDERR, ':utf8'): $OS_ERROR"; + } } else { if ( -t STDOUT ) { diff --git a/bin/pt-variable-advisor b/bin/pt-variable-advisor index 9589c163..04515830 100755 --- a/bin/pt-variable-advisor +++ b/bin/pt-variable-advisor @@ -2522,6 +2522,7 @@ sub new { force_log_file => $args{force_log_file}, parent_exit => $args{parent_exit}, pid_file_owner => 0, + utf8 => $args{utf8} // 0, }; return bless $self, $class; } @@ -2534,6 +2535,7 @@ sub run { my $log_file = $self->{log_file}; my $force_log_file = $self->{force_log_file}; my $parent_exit = $self->{parent_exit}; + my $utf8 = $self->{utf8}; PTDEBUG && _d('Starting daemon'); @@ -2580,10 +2582,19 @@ sub run { close STDOUT; open STDOUT, '>>', $log_file or die "Cannot open log file $log_file: $OS_ERROR"; + if ( $utf8 ) { + binmode(STDOUT, ':utf8') + or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR"; + } + close STDERR; open STDERR, ">&STDOUT" or die "Cannot dupe STDERR to STDOUT: $OS_ERROR"; + if ( $utf8 ) { + binmode(STDERR, ':utf8') + or die "Can't binmode(STDERR, ':utf8'): $OS_ERROR"; + } } else { if ( -t STDOUT ) { diff --git a/lib/Daemon.pm b/lib/Daemon.pm index 3040051e..3cf857f8 100644 --- a/lib/Daemon.pm +++ b/lib/Daemon.pm @@ -37,6 +37,7 @@ sub new { force_log_file => $args{force_log_file}, parent_exit => $args{parent_exit}, pid_file_owner => 0, + utf8 => $args{utf8} // 0, }; return bless $self, $class; } @@ -50,6 +51,7 @@ sub run { my $log_file = $self->{log_file}; my $force_log_file = $self->{force_log_file}; my $parent_exit = $self->{parent_exit}; + my $utf8 = $self->{utf8}; PTDEBUG && _d('Starting daemon'); @@ -116,6 +118,11 @@ sub run { close STDOUT; open STDOUT, '>>', $log_file or die "Cannot open log file $log_file: $OS_ERROR"; + if ( $utf8 ) { + binmode(STDOUT, ':utf8') + or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR"; + } + # If we don't close STDERR explicitly, then prove Daemon.t fails # because STDERR gets written before STDOUT even though we print @@ -124,6 +131,10 @@ sub run { close STDERR; open STDERR, ">&STDOUT" or die "Cannot dupe STDERR to STDOUT: $OS_ERROR"; + if ( $utf8 ) { + binmode(STDERR, ':utf8') + or die "Can't binmode(STDERR, ':utf8'): $OS_ERROR"; + } } else { if ( -t STDOUT ) { diff --git a/t/pt-kill/pt-2284.t b/t/pt-kill/pt-2284.t new file mode 100644 index 00000000..d15a314a --- /dev/null +++ b/t/pt-kill/pt-2284.t @@ -0,0 +1,72 @@ +#!/usr/bin/env perl + +BEGIN { + die "The PERCONA_TOOLKIT_BRANCH environment variable is not set.\n" + unless $ENV{PERCONA_TOOLKIT_BRANCH} && -d $ENV{PERCONA_TOOLKIT_BRANCH}; + unshift @INC, "$ENV{PERCONA_TOOLKIT_BRANCH}/lib"; +}; + +use strict; +use warnings FATAL => 'all'; +use English qw(-no_match_vars); +use Test::More tests => 6; + +use PerconaTest; +use Sandbox; +require "$trunk/bin/pt-kill"; + +my $dp = new DSNParser(opts=>$dsn_opts); +my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp); +my $master_dbh = $sb->get_dbh_for('master'); + +my $output; +my $cnf='/tmp/12345/my.sandbox.cnf'; +my $cmd = "$trunk/bin/pt-kill -F $cnf -h 127.1"; + +if ( !$master_dbh ) { + plan skip_all => 'Cannot connect to sandbox master'; +} + +`$cmd --print --interval 1s --run-time 20 --pid /tmp/pt-kill.pid --log /tmp/pt-kill.log --daemonize --busy-time 5 --kill-query --victims all --charset utf8mb4`; +$output = `ps -eaf | grep 'pt-kill \-F'`; + +ok( + -f '/tmp/pt-kill.pid', + 'PID file created' +); + +ok( + -f '/tmp/pt-kill.log', + 'Log file created' +); + +$master_dbh->do("select '柏木', sleep(20);"); + +wait_until(sub { return !-f '/tmp/pt-kill.pid' }); +ok( + !-f '/tmp/pt-kill.pid', + 'PID file removed' +); + +$output = `cat /tmp/pt-kill.log`; + +unlike( + $output, + qr/Wide character in printf/, + 'Error "Wide character in printf" not printed' +) or diag($output); + +like( + $output, + qr/柏木/, + 'Hieroglif printed' +) or diag($output); + +diag(`rm -rf /tmp/pt-kill.log 2>/dev/null`); + +# ############################################################################# +# Done. +# ############################################################################# +$sb->wipe_clean($master_dbh) if $master_dbh; +ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox"); +exit;