[pve-devel] run_command and shellquote

Michael Rasmussen mir at datanom.net
Tue Nov 4 17:47:25 CET 2014


On Tue, 4 Nov 2014 06:08:57 +0000
Dietmar Maurer <dietmar at proxmox.com> wrote:

> 
> Beside, we do not quote anything. The $cmd array is directly passed top open3():
> 
>     $pid = open3($writer, $reader, $error, @$cmd) || die $!;
> 
> So I cannot reproduce what you talk about.
> 
From PVE::Tools

sub shellquote {
    my $str = shift;

    return String::ShellQuote::shell_quote($str);
}

sub cmd2string {
    my ($cmd) = @_;

    die "no arguments" if !$cmd;

    return $cmd if !ref($cmd);

    my @qa = ();
    foreach my $arg (@$cmd) { push @qa, shellquote($arg); }

    return join (' ', @qa);
}

sub run_command {
    my ($cmd, %param) = @_;

    my $old_umask;
    my $cmdstr;

    if (!ref($cmd)) {
        $cmdstr = $cmd;
        if ($cmd =~ m/|/) {
            # see 'man bash' for option pipefail
            $cmd = [ '/bin/bash', '-c', "set -o pipefail && $cmd" ];
        } else {
            $cmd = [ $cmd ];
        }
    } else {
        $cmdstr = cmd2string($cmd);
    }


-- 
Hilsen/Regards
Michael Rasmussen

Get my public GnuPG keys:
michael <at> rasmussen <dot> cc
http://pgp.mit.edu:11371/pks/lookup?op=get&search=0xD3C9A00E
mir <at> datanom <dot> net
http://pgp.mit.edu:11371/pks/lookup?op=get&search=0xE501F51C
mir <at> miras <dot> org
http://pgp.mit.edu:11371/pks/lookup?op=get&search=0xE3E80917
--------------------------------------------------------------
/usr/games/fortune -es says:
Do what thou wilt shall be the whole of the Law.
		-- Aleister Crowley
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 181 bytes
Desc: OpenPGP digital signature
URL: <http://lists.proxmox.com/pipermail/pve-devel/attachments/20141104/9cb89937/attachment.sig>


More information about the pve-devel mailing list