summaryrefslogtreecommitdiffstats
path: root/daemon/debug.c
diff options
context:
space:
mode:
authorOlaf Hering <olaf@aepfle.de>2012-08-30 20:51:27 +0200
committerRichard W.M. Jones <rjones@redhat.com>2012-08-30 20:57:07 +0100
commit0306c98d319d189281af3c15101c8d343e400f13 (patch)
tree7781024c541a56152405582ece9c3c0ee2edc49d /daemon/debug.c
parent4aa1464d42c62e8cbff4669f01f53f0425c287e3 (diff)
downloadlibguestfs-0306c98d319d189281af3c15101c8d343e400f13.tar.gz
libguestfs-0306c98d319d189281af3c15101c8d343e400f13.tar.xz
libguestfs-0306c98d319d189281af3c15101c8d343e400f13.zip
daemon: collect list of called external commands
guestfsd calls many different tools. Keeping track of all of them is error prone. This patch introduces a new helper macro to put the command string into its own ELF section: GUESTFSD_EXT_CMD(C_variable, command_name); This syntax makes it still possible to grep for used command names. The actual usage of the collected list could be like this: objcopy -j .guestfsd_ext_cmds -O binary daemon/guestfsd /dev/stdout | tr '\0' '\n' | sort -u The resulting output will be used to tell mkinitrd which programs to copy into the initrd. Signed-off-by: Olaf Hering <olaf@aepfle.de> RWMJ: - Move str_vgchange at request of author. - Fix snprintf call in daemon/debug.c
Diffstat (limited to 'daemon/debug.c')
-rw-r--r--daemon/debug.c29
1 files changed, 20 insertions, 9 deletions
diff --git a/daemon/debug.c b/daemon/debug.c
index 97d21f03..41bae38b 100644
--- a/daemon/debug.c
+++ b/daemon/debug.c
@@ -32,6 +32,15 @@
#include "daemon.h"
#include "actions.h"
+GUESTFSD_EXT_CMD(str_printenv, printenv);
+GUESTFSD_EXT_CMD(str_ldd, ldd);
+GUESTFSD_EXT_CMD(str_ls, ls);
+GUESTFSD_EXT_CMD(str_find, find);
+GUESTFSD_EXT_CMD(str_xargs, xargs);
+GUESTFSD_EXT_CMD(str_file, file);
+GUESTFSD_EXT_CMD(str_grep, grep);
+GUESTFSD_EXT_CMD(str_gawk, gawk);
+
/* This command exposes debugging information, internals and
* status. There is no comprehensive documentation for this
* command. You have to look at the source code in this file
@@ -275,7 +284,7 @@ debug_env (const char *subcmd, size_t argc, char *const *const argv)
int r;
char *out, *err;
- r = command (&out, &err, "printenv", NULL);
+ r = command (&out, &err, str_printenv, NULL);
if (r == -1) {
reply_with_error ("printenv: %s", err);
free (out);
@@ -318,12 +327,14 @@ debug_binaries (const char *subcmd, size_t argc, char *const *const argv)
{
int r;
char *out, *err;
+ char cmd[256];
- const char cmd[] =
- "find / -xdev -type f -executable "
- "| xargs file -i "
- "| grep application/x-executable "
- "| gawk -F: '{print $1}'";
+ snprintf (cmd, sizeof (cmd),
+ "%s / -xdev -type f -executable "
+ "| %s %s -i "
+ "| %s application/x-executable "
+ "| %s -F: '{print $1}'",
+ str_find, str_xargs, str_file, str_grep, str_gawk);
r = command (&out, &err, "sh", "-c", cmd, NULL);
if (r == -1) {
@@ -358,7 +369,7 @@ debug_ldd (const char *subcmd, size_t argc, char *const *const argv)
* Also 'ldd' randomly sends messages to stderr and errors to stdout
* depending on the phase of the moon.
*/
- r = command (&out, &err, "ldd", "-r", argv[0], NULL);
+ r = command (&out, &err, str_ldd, "-r", argv[0], NULL);
if (r == -1) {
reply_with_error ("ldd: %s: %s", argv[0], err);
free (out);
@@ -389,7 +400,7 @@ debug_ls (const char *subcmd, size_t argc, char *const *const argv)
const char *cargv[len+3];
size_t i;
- cargv[0] = "ls";
+ cargv[0] = str_ls;
cargv[1] = "-a";
for (i = 0; i < len; ++i)
cargv[2+i] = argv[i];
@@ -419,7 +430,7 @@ debug_ll (const char *subcmd, size_t argc, char *const *const argv)
const char *cargv[len+3];
size_t i;
- cargv[0] = "ls";
+ cargv[0] = str_ls;
cargv[1] = "-la";
for (i = 0; i < len; ++i)
cargv[2+i] = argv[i];