+/* 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
+ * storage the pattern must start with /sysroot only if the command which
+ * crashes doesn't chroot.
+ */
+static char *
+debug_core_pattern (const char *subcmd, int argc, char *const *const argv)
+{
+ if (argc < 1) {
+ reply_with_error ("core_pattern: expecting a core pattern");
+ return NULL;
+ }
+
+ const char *pattern = argv[0];
+ const size_t pattern_len = strlen(pattern);
+
+#define CORE_PATTERN "/proc/sys/kernel/core_pattern"
+ int fd = open (CORE_PATTERN, O_WRONLY);
+ if (fd == -1) {
+ reply_with_perror ("open: " CORE_PATTERN);
+ return NULL;
+ }
+ if (write (fd, pattern, pattern_len) < (ssize_t) pattern_len) {
+ reply_with_perror ("write: " CORE_PATTERN);
+ return NULL;
+ }
+ if (close (fd) == -1) {
+ reply_with_perror ("close: " CORE_PATTERN);
+ return NULL;
+ }
+
+ struct rlimit limit = {
+ .rlim_cur = RLIM_INFINITY,
+ .rlim_max = RLIM_INFINITY
+ };
+ if (setrlimit (RLIMIT_CORE, &limit) == -1) {
+ reply_with_perror ("setrlimit (RLIMIT_CORE)");
+ return NULL;
+ }
+
+ char *ret = strdup ("ok");
+ if (NULL == ret) {
+ reply_with_perror ("strdup");
+ return NULL;
+ }
+
+ return ret;
+}