1 /* libguestfs - the guestfsd daemon
2 * Copyright (C) 2009 Red Hat Inc.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #include "../src/guestfs_protocol.h"
30 /* This command exposes debugging information, internals and
31 * status. There is no comprehensive documentation for this
32 * command. You have to look at the source code in this file
33 * to find out what you can do.
35 * Commands always output a freeform string.
38 #if ENABLE_DEBUG_COMMAND
41 char * (*f) (const char *subcmd, int argc, char *const *const argv);
44 static char *debug_help (const char *subcmd, int argc, char *const *const argv);
46 static char *debug_fds (const char *subcmd, int argc, char *const *const argv);
47 static char *debug_free (const char *subcmd, int argc, char *const *const argv);
48 static char *debug_mem (const char *subcmd, int argc, char *const *const argv);
49 static char *debug_ps (const char *subcmd, int argc, char *const *const argv);
52 static struct cmd cmds[] = {
53 { "help", debug_help },
56 { "free", debug_free },
65 do_debug (const char *subcmd, char *const *const argv)
67 #if ENABLE_DEBUG_COMMAND
70 for (i = argc = 0; argv[i] != NULL; ++i)
73 for (i = 0; cmds[i].cmd != NULL; ++i) {
74 if (strcasecmp (subcmd, cmds[i].cmd) == 0)
75 return cmds[i].f (subcmd, argc, argv);
78 reply_with_error ("use 'debug help' to list the supported commands");
81 reply_with_error ("guestfsd was not configured with --enable-debug-command");
86 #if ENABLE_DEBUG_COMMAND
88 debug_help (const char *subcmd, int argc, char *const *const argv)
93 r = strdup ("Commands supported:");
95 reply_with_perror ("strdup");
100 for (i = 0; cmds[i].cmd != NULL; ++i) {
101 len += strlen (cmds[i].cmd) + 1; /* space + new command */
102 p = realloc (r, len + 1); /* +1 for the final NUL */
104 reply_with_perror ("realloc");
111 strcat (r, cmds[i].cmd);
119 debug_fds (const char *subcmd, int argc, char *const *const argv)
124 debug_free (const char *subcmd, int argc, char *const *const argv)
129 debug_mem (const char *subcmd, int argc, char *const *const argv)
134 debug_ps (const char *subcmd, int argc, char *const *const argv)
138 #endif /* ENABLE_DEBUG_COMMAND */