Skip to content

Commit

Permalink
Linux: fixed problems with braces in process names (#61946)
Browse files Browse the repository at this point in the history
  • Loading branch information
jwbargsten committed May 28, 2013
1 parent b043400 commit c4d07f8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion os/Linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ static bool get_proc_stat(char *pid, char *format_str, struct procstat* prs,
/* replace the first ')' with a '\0', the contents look like this:
* pid (program_name) state ...
* if we don't find ')' then it's incorrectly formated */
if ((paren = strchr(stat_text, ')')) == NULL) {
if ((paren = strrchr(stat_text, ')')) == NULL) {
read_ok = false;
goto done;
}
Expand Down
33 changes: 33 additions & 0 deletions t/bugfix-61946_odd_process_name.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use warnings;
use Test::More;
use Data::Dumper;

BEGIN {
if( $^O eq 'cygwin' ) {
plan skip_all => 'Test irrelevant on cygwin';
}

use_ok('Proc::ProcessTable');
}


$SIG{CHLD} = 'IGNORE';

my $pid = fork;
die "cannot fork" unless defined $pid;

if ( $pid == 0 ) {
#child
$0 = '(ib_fmr(mlx4_0))';
sleep 10000;
} else {
#main
sleep 1;
my $t = Proc::ProcessTable->new;
my $cmnd_quoted = quotemeta('(ib_fmr(mlx4_0))');
my ($p) = grep { $_->{pid} == $pid } @{ $t->table };
like( $p->{cmndline}, qr/$cmnd_quoted/, "odd process commandline bugfix" );
kill 9, $pid;
}
done_testing();

0 comments on commit c4d07f8

Please sign in to comment.