X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=blobdiff_plain;f=daemon%2Fdebug.c;h=bca6b9f6abcd7994a1505a97143537c8e1869c60;hp=c0d87da9147375518bd4b1ccc1fb602360d5835b;hb=8c37961b455cbc72d4879da65c6aafd332857f05;hpb=a45302cb8a0ee3b4ffd0656b24a06ebdf7b50f38 diff --git a/daemon/debug.c b/daemon/debug.c index c0d87da..bca6b9f 100644 --- a/daemon/debug.c +++ b/daemon/debug.c @@ -38,22 +38,27 @@ * to find out what you can do. * * Commands always output a freeform string. + * + * Since libguestfs 1.5.7, the debug command has been enabled + * by default for all builds (previously you had to enable it + * in configure). This command is not part of the stable ABI + * and may change at any time. */ -#if ENABLE_DEBUG_COMMAND struct cmd { const char *cmd; char * (*f) (const char *subcmd, int argc, char *const *const argv); }; static char *debug_help (const char *subcmd, int argc, char *const *const argv); +static char *debug_core_pattern (const char *subcmd, int argc, char *const *const argv); static char *debug_env (const char *subcmd, int argc, char *const *const argv); static char *debug_fds (const char *subcmd, int argc, char *const *const argv); static char *debug_ls (const char *subcmd, int argc, char *const *const argv); static char *debug_ll (const char *subcmd, int argc, char *const *const argv); +static char *debug_progress (const char *subcmd, int argc, char *const *const argv); static char *debug_segv (const char *subcmd, int argc, char *const *const argv); static char *debug_sh (const char *subcmd, int argc, char *const *const argv); -static char *debug_core_pattern (const char *subcmd, int argc, char *const *const argv); static struct cmd cmds[] = { { "help", debug_help }, @@ -62,22 +67,15 @@ static struct cmd cmds[] = { { "fds", debug_fds }, { "ls", debug_ls }, { "ll", debug_ll }, + { "progress", debug_progress }, { "segv", debug_segv }, { "sh", debug_sh }, { NULL, NULL } }; -#endif - -#if ! ENABLE_DEBUG_COMMAND -# define MAYBE_UNUSED ATTRIBUTE_UNUSED -#else -# define MAYBE_UNUSED /* empty */ -#endif char * -do_debug (const char *subcmd MAYBE_UNUSED, char *const *argv MAYBE_UNUSED) +do_debug (const char *subcmd, char *const *argv) { -#if ENABLE_DEBUG_COMMAND int argc, i; for (i = argc = 0; argv[i] != NULL; ++i) @@ -90,13 +88,8 @@ do_debug (const char *subcmd MAYBE_UNUSED, char *const *argv MAYBE_UNUSED) reply_with_error ("use 'debug help' to list the supported commands"); return NULL; -#else - reply_with_error ("guestfsd was not configured with --enable-debug-command"); - return NULL; -#endif } -#if ENABLE_DEBUG_COMMAND static char * debug_help (const char *subcmd, int argc, char *const *const argv) { @@ -341,6 +334,37 @@ debug_ll (const char *subcmd, int argc, char *const *const argv) return out; } +/* Generate progress notification messages in order to test progress bars. */ +static char * +debug_progress (const char *subcmd, int argc, char *const *const argv) +{ + if (argc < 1) { + error: + reply_with_error ("progress: expecting arg (time in seconds as string)"); + return NULL; + } + + char *secs_str = argv[0]; + unsigned secs; + if (sscanf (secs_str, "%u", &secs) != 1 || secs == 0) + goto error; + + unsigned i; + unsigned tsecs = secs * 10; /* 1/10ths of seconds */ + for (i = 1; i <= tsecs; ++i) { + usleep (100000); + notify_progress ((uint64_t) i, (uint64_t) tsecs); + } + + char *ret = strdup ("ok"); + if (ret == NULL) { + reply_with_perror ("strdup"); + return NULL; + } + + return ret; +} + /* Enable core dumping to the given core pattern. * Note that this pattern is relative to any chroot of the process which * crashes. This means that if you want to write the core file to the guest's @@ -391,22 +415,17 @@ debug_core_pattern (const char *subcmd, int argc, char *const *const argv) return ret; } -#endif /* ENABLE_DEBUG_COMMAND */ - -#if ENABLE_DEBUG_COMMAND static int write_cb (void *fd_ptr, const void *buf, size_t len) { int fd = *(int *)fd_ptr; return xwrite (fd, buf, len); } -#endif /* Has one FileIn parameter. */ int -do_debug_upload (const char *filename MAYBE_UNUSED, int mode MAYBE_UNUSED) +do_debug_upload (const char *filename, int mode) { -#if ENABLE_DEBUG_COMMAND /* Not chrooted - this command lets you upload a file to anywhere * in the appliance. */ @@ -445,8 +464,4 @@ do_debug_upload (const char *filename MAYBE_UNUSED, int mode MAYBE_UNUSED) } return 0; -#else - reply_with_error ("guestfsd was not configured with --enable-debug-command"); - return NULL; -#endif }