static void produce_message(const char * type, const char *fmt, va_list args)
{
	char *dialog_msg;
	char buf[1024];
	(void) vsnprintf(buf, sizeof(buf), fmt, args);
	if (asprintf(&dialog_msg, "%s: %s: %s (error type: %s)",
		 program_invocation_short_name, type, buf, strerror(errno)) < 0) {
		fprintf(stderr, "Failed to allocate memory for error message :(\n");
		return;
	}
	fprintf(stderr, "%s\n", dialog_msg);
	switch (fork()) {
	case -1:
		exit(1);	//what else
	case 0:
		if (geteuid() == 0)
			if (setuid(getuid()) != 0)
				perror("setuid failed, calling kdialog/zenity as root");
		fix_display();
#ifdef USE_KDIALOG
		execlp("/usr/bin/kdialog", "kdialog", "--sorry", dialog_msg, NULL);
#else

		execlp("/usr/bin/zenity", "zenity", "--error",  "--text", dialog_msg, NULL);
#endif
		exit(1);
	default:;
	}
	free(dialog_msg);
}
void
ebml_chapters_converter_c::fix_atom(KaxChapterAtom &atom)
  const {
  for (auto element : atom)
    if (dynamic_cast<KaxChapterAtom *>(element))
      fix_atom(*static_cast<KaxChapterAtom *>(element));

  if (!FindChild<KaxChapterTimeStart>(atom))
    throw conversion_x{Y("<ChapterAtom> is missing the <ChapterTimeStart> child.")};

  if (!FindChild<KaxChapterUID>(atom)) {
    KaxChapterUID *cuid                = new KaxChapterUID;
    *static_cast<EbmlUInteger *>(cuid) = create_unique_number(UNIQUE_CHAPTER_IDS);
    atom.PushElement(*cuid);
  }

  KaxChapterTrack *ctrack = FindChild<KaxChapterTrack>(atom);
  if (ctrack && !FindChild<KaxChapterTrackNumber>(ctrack))
    throw conversion_x{Y("<ChapterTrack> is missing the <ChapterTrackNumber> child.")};

  KaxChapterDisplay *cdisplay = FindChild<KaxChapterDisplay>(atom);
  if (cdisplay)
    fix_display(*cdisplay);
}