Skip to content

Commit

Permalink
gui-fatal: don't not output GUI notification on PROGRESS_TYPE!=gui
Browse files Browse the repository at this point in the history
  • Loading branch information
fepitre committed Feb 15, 2022
1 parent 60f967a commit b5c151e
Showing 1 changed file with 26 additions and 18 deletions.
44 changes: 26 additions & 18 deletions qubes-rpc/gui-fatal.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,40 @@ static void fix_display(void)
setenv("DISPLAY", ":0", 1);
}

static void produce_message(const char * type, const char *fmt, va_list args)
static void produce_message(const char *type, const char *fmt, va_list args)
{
char *dialog_msg;
const char *progress_type = getenv("PROGRESS_TYPE");
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) {
(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();

if (progress_type && !strcmp(progress_type, "gui"))
{
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);
execlp("/usr/bin/kdialog", "kdialog", "--sorry", dialog_msg, NULL);
#else

execlp("/usr/bin/zenity", "zenity", "--error", "--text", dialog_msg, NULL);
execlp("/usr/bin/zenity", "zenity", "--error", "--text", dialog_msg, NULL);
#endif
exit(1);
default:;
exit(1);
default:;
}
}
free(dialog_msg);
}
Expand All @@ -53,7 +60,8 @@ void gui_fatal(const char *fmt, ...)
exit(1);
}

void qfile_gui_fatal(const char *fmt, va_list args) {
void qfile_gui_fatal(const char *fmt, va_list args)
{
produce_message("Fatal error", fmt, args);
exit(1);
}
Expand Down

0 comments on commit b5c151e

Please sign in to comment.