Skip to content
Snippets Groups Projects
Commit 11be7832 authored by Mark Harrison's avatar Mark Harrison
Browse files

Allow run_command to take a list instead of a string.

When it does this, commands are not executed via the shell, but are executed
directly. (See the documentation for 'exec' for an explanation of this).
Existing modules that pass a string are unaffected.

The rationale for this change is for the Pgrep (and similar) modules, where it
was picking up the 'sh -c pgrep' process and including it in the process
count. Executing pgrep directly prevents this.

git-svn-id: https://labs.omniti.com/resmon/branches/resmon2@309 8c0face9-b7db-6ec6-c4b3-d5f7145c7d55
parent d29cd189
No related branches found
No related tags found
No related merge requests found
......@@ -33,10 +33,10 @@ sub clean_up {
}
}
sub run_command($) {
sub run_command {
# Run a command just like `cmd`, but store the pid and stdout handles so
# they can be cleaned up later. For use with alarm().
my $cmd = shift;
my @cmd = @_;
pipe(my ($r, $w));
my $pid = fork();
if($pid) {
......@@ -50,7 +50,7 @@ sub run_command($) {
eval {
open(STDOUT, ">&", $w);
close($r);
exec($cmd);
exec(@cmd);
};
exit();
}
......
......@@ -46,12 +46,26 @@ our @EXPORT_OK = qw/cache_command run_command/;
sub cache_command($$) {
my $command = shift;
return `$command`;
run_command($command);
}
sub run_command($) {
my $command = shift;
return `$command`;
sub run_command {
my @cmd = @_;
pipe(my ($r, $w));
my $pid = fork();
if($pid) {
close($w);
my @lines = <$r>;
waitpid($pid, 0);
return join("", @lines);
} else {
eval {
open(STDOUT, ">&", $w);
close($r);
exec(@cmd);
};
exit();
}
}
1;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment