From: Richard Jones Date: Mon, 22 Jun 2009 06:49:37 +0000 (+0100) Subject: Add 'sh' and 'sh-lines' commands. X-Git-Tag: 1.0.50~5 X-Git-Url: http://git.annexia.org/?a=commitdiff_plain;h=57d2dfab18ad3d987d9273bb7c1f42e73e0bbcb2;p=libguestfs.git Add 'sh' and 'sh-lines' commands. --- diff --git a/daemon/command.c b/daemon/command.c index 3254de5..b33f2db 100644 --- a/daemon/command.c +++ b/daemon/command.c @@ -101,3 +101,19 @@ do_command_lines (char **argv) return lines; /* Caller frees. */ } + +char * +do_sh (char *command) +{ + char *argv[] = { "/bin/sh", "-c", command, NULL }; + + return do_command (argv); +} + +char ** +do_sh_lines (char *command) +{ + char *argv[] = { "/bin/sh", "-c", command, NULL }; + + return do_command_lines (argv); +} diff --git a/src/generator.ml b/src/generator.ml index d8abfd6..64a8ab9 100755 --- a/src/generator.ml +++ b/src/generator.ml @@ -1370,7 +1370,9 @@ or compatible processor architecture). The single parameter is an argv-style list of arguments. The first element is the name of the program to run. Subsequent elements are parameters. The list must be -non-empty (ie. must contain a program name). +non-empty (ie. must contain a program name). Note that +the command runs directly, and is I invoked via +the shell (see C). The return value is anything printed to I by the command. @@ -1438,7 +1440,9 @@ locations."); "run a command, returning lines", "\ This is the same as C, but splits the -result into a list of lines."); +result into a list of lines. + +See also: C"); ("stat", (RStat "statbuf", [String "path"]), 52, [], [InitBasicFS, Always, TestOutputStruct ( @@ -2343,6 +2347,33 @@ The return value is an integer which C<0> if the operation would succeed, or some non-zero value documented in the L manual page."); + ("sh", (RString "output", [String "command"]), 111, [], + [], (* XXX needs tests *) + "run a command via the shell", + "\ +This call runs a command from the guest filesystem via the +guest's C. + +This is like C, but passes the command to: + + /bin/sh -c \"command\" + +Depending on the guest's shell, this usually results in +wildcards being expanded, shell expressions being interpolated +and so on. + +All the provisos about C apply to this call."); + + ("sh_lines", (RStringList "lines", [String "command"]), 112, [], + [], (* XXX needs tests *) + "run a command via the shell returning lines", + "\ +This is the same as C, but splits the result +into a list of lines. + +See also: C"); + + ] let all_functions = non_daemon_functions @ daemon_functions