summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Booth <mbooth@redhat.com>2009-09-11 14:27:54 +0100
committerMatthew Booth <mbooth@redhat.com>2009-09-14 10:13:03 +0100
commit13432f02ca29eecaa61c8d66c7c52f9b70b2b3be (patch)
tree59cf8f442aaed9679788e519d96ac6e82bb1cd44
parent02ae70474d418b202b6a8411daa54f8dfc790206 (diff)
downloadlibguestfs-13432f02ca29eecaa61c8d66c7c52f9b70b2b3be.tar.gz
libguestfs-13432f02ca29eecaa61c8d66c7c52f9b70b2b3be.tar.xz
libguestfs-13432f02ca29eecaa61c8d66c7c52f9b70b2b3be.zip
Add echo_daemon command
echo_daemon is a simple echo which can be used to test connectivity between the client and daemon.
-rw-r--r--daemon/Makefile.am1
-rw-r--r--daemon/echo_daemon.c73
-rw-r--r--po/POTFILES.in1
-rw-r--r--src/MAX_PROC_NR2
-rwxr-xr-xsrc/generator.ml13
5 files changed, 89 insertions, 1 deletions
diff --git a/daemon/Makefile.am b/daemon/Makefile.am
index 83ee408c..ae746998 100644
--- a/daemon/Makefile.am
+++ b/daemon/Makefile.am
@@ -36,6 +36,7 @@ guestfsd_SOURCES = \
dmesg.c \
dropcaches.c \
du.c \
+ echo_daemon.c \
ext2.c \
fallocate.c \
file.c \
diff --git a/daemon/echo_daemon.c b/daemon/echo_daemon.c
new file mode 100644
index 00000000..658974b6
--- /dev/null
+++ b/daemon/echo_daemon.c
@@ -0,0 +1,73 @@
+/* libguestfs - the guestfsd daemon
+ * Copyright (C) 2009 Red Hat Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <config.h>
+
+#include <string.h>
+
+#include "actions.h"
+#include "daemon.h"
+
+char *
+do_echo_daemon (char *const *argv)
+{
+ char *out = NULL;
+ size_t out_len = 0;
+
+ /* Iterate over argv entries until reaching the NULL terminator */
+ while (*argv) {
+ char add_space = 0;
+
+ /* Store the end of current output */
+ size_t out_end = out_len;
+
+ /* Calculate the new output size */
+ size_t arg_len = strlen(*argv);
+ out_len += arg_len;
+
+ /* We will prepend a space if this isn't the first argument added */
+ if (NULL != out) {
+ out_len++;
+ add_space = 1;
+ }
+
+ /* Make the output buffer big enough for the string and its terminator */
+ char *out_new = realloc (out, out_len + 1);
+ if (NULL == out_new) {
+ reply_with_perror ("realloc");
+ free(out);
+ return 0;
+ }
+ out = out_new;
+
+ /* 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 1b2f82ad..44e472b9 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 205a12b5..6bb2f98f 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 433c60ad..32537df7 100755
--- a/src/generator.ml
+++ b/src/generator.ml
@@ -3569,6 +3569,19 @@ 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, TestOutput (
+ [["echo_daemon"; "This is a test"]], "This is a test"
+ )],
+ "echo arguments back to the client",
+ "\
+This command concatenate the list of C<words> passed with single spaces between
+them and returns the resulting string.
+
+You can use this command to test the connection through to the daemon.
+
+See also C<guestfs_ping_daemon>.");
+
]
let all_functions = non_daemon_functions @ daemon_functions