[Libguestfs] [PATCH] Add echo_daemon command
Matthew Booth
mbooth at redhat.com
Fri Sep 11 16:49:20 UTC 2009
On 11/09/09 15:51, Richard W.M. Jones wrote:
> On Fri, Sep 11, 2009 at 02:39:24PM +0100, Matthew Booth wrote:
>> + /* Make the output buffer big enough for the string and its terminator */
>> + out = realloc (out, out_len + 1);
>
> In the daemon we have to check the return value from malloc/realloc
> very carefully. The reason is that the daemon runs in limited space.
Good catch.
>> + /* Prepend a space if required */
>> + if (add_space) {
>> + out[out_end++] = ' ';
>> + }
>> +
>> + /* Copy the argument to the output */
>> + memcpy(&out[out_end], *argv, arg_len);
>> +
>> + argv++;
>> + }
>> +
>> + /* NULL terminate the output */
>> + out[out_len] = '\0';
>> +
>> + return out;
>> +}
>> diff --git a/po/POTFILES.in b/po/POTFILES.in
>> index 1b2f82a..44e472b 100644
>> --- a/po/POTFILES.in
>> +++ b/po/POTFILES.in
>> @@ -12,6 +12,7 @@ daemon/dir.c
>> daemon/dmesg.c
>> daemon/dropcaches.c
>> daemon/du.c
>> +daemon/echo_daemon.c
>> daemon/ext2.c
>> daemon/fallocate.c
>> daemon/file.c
>> diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR
>> index 205a12b..6bb2f98 100644
>> --- a/src/MAX_PROC_NR
>> +++ b/src/MAX_PROC_NR
>> @@ -1 +1 @@
>> -194
>> +195
>> diff --git a/src/generator.ml b/src/generator.ml
>> index 439c9c4..f820e1f 100755
>> --- a/src/generator.ml
>> +++ b/src/generator.ml
>> @@ -3595,6 +3595,13 @@ This loads a kernel module in the appliance.
>> The kernel module must have been whitelisted when libguestfs
>> was built (see C<appliance/kmod.whitelist.in> in the source).");
>>
>> + ("echo_daemon", (RString "output", [StringList "words"]), 195, [],
>> + [InitNone, Always, TestRun [["echo_daemon"; "\"This is a test\""]]],
>
> This should test the return value using TestOutput. Also note that
> this is passing a list of length four. (Handling of lists in the test
> code is very hairy).
Ok.
>> + "echo arguments back to the client",
>> + "\
>> +This commands works much like the unix echo command. It returns its arguments as
>> +a string.");
>
> A better description:
>
> This command concatenates the list of C<words> passed with
> single spaces between them and returns the resulting string.
>
> You can use this to test the connection through to the daemon.
>
> See also C<guestfs_ping_daemon>.
Ok. Updated patch to follow.
Matt
--
Matthew Booth, RHCA, RHCSS
Red Hat Engineering, Virtualisation Team
M: +44 (0)7977 267231
GPG ID: D33C3490
GPG FPR: 3733 612D 2D05 5458 8A8A 1600 3441 EA19 D33C 3490
More information about the Libguestfs
mailing list