X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=blobdiff_plain;f=daemon%2Fdebug.c;h=bca6b9f6abcd7994a1505a97143537c8e1869c60;hp=c9a5d8b049a9d03d3dddd4f3c317853068686ba5;hb=43eed091129212dd29996838cf1d76af0f8fc135;hpb=83f381f5ccfb7e86bfaaeeade9d06c9e54ddb0cf diff --git a/daemon/debug.c b/daemon/debug.c index c9a5d8b..bca6b9f 100644 --- a/daemon/debug.c +++ b/daemon/debug.c @@ -51,13 +51,14 @@ struct cmd { }; 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 }, @@ -66,6 +67,7 @@ static struct cmd cmds[] = { { "fds", debug_fds }, { "ls", debug_ls }, { "ll", debug_ll }, + { "progress", debug_progress }, { "segv", debug_segv }, { "sh", debug_sh }, { NULL, NULL } @@ -332,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