From 39d476f80ca29571189cd57ed81ccde9cf91b058 Mon Sep 17 00:00:00 2001 From: Ikey Doherty Date: Fri, 27 May 2016 01:48:23 +0100 Subject: [PATCH] Add user-facing error reporting Signed-off-by: Ikey Doherty --- src/shim/lsi.c | 37 +++++++++++++++++++++++++++++++++++++ src/shim/lsi.h | 6 ++++++ src/shim/shim.c | 4 +++- 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/src/shim/lsi.c b/src/shim/lsi.c index 788e931..6fba02d 100644 --- a/src/shim/lsi.c +++ b/src/shim/lsi.c @@ -12,7 +12,9 @@ #define _GNU_SOURCE #include +#include #include +#include #include #include #include @@ -184,6 +186,41 @@ const char *lsi_preload_list() return "/usr/$LIB/libX11.so.6:/usr/$LIB/libstdc++.so.6"; } +void lsi_report_failure(const char *s, ...) +{ + autofree(char) *report = NULL; + autofree(char) *emit = NULL; + va_list va; + va_start(va, s); + if (vasprintf(&report, s, va) < 0) { + fputs("Critical internal error\n", stderr); + return; + } + va_end(va); + + /* Display not set, just go ahead and stderr it */ + if (!getenv("DISPLAY")) { + goto stderr_log; + } + + if (asprintf(&emit, + "zenity --title \"%s\" --icon-name='steam' --error --text='%s'", + PACKAGE_NAME, + report) < 0) { + goto stderr_log; + } + + if (system(emit) != 0) { + fprintf(stderr, "%s: Failed to launch Zenity: %s\n", PACKAGE_NAME, strerror(errno)); + goto stderr_log; + } + return; + +stderr_log: + fputs(PACKAGE_NAME " failure: \n\t", stderr); + fprintf(stderr, "%s\n", report); +} + /* * Editor modelines - https://www.wireshark.org/tools/modelines.html * diff --git a/src/shim/lsi.h b/src/shim/lsi.h index d356dcb..9b76a85 100644 --- a/src/shim/lsi.h +++ b/src/shim/lsi.h @@ -75,6 +75,12 @@ const char *lsi_preload_list(void); */ bool lsi_system_requires_preload(void); +/** + * Report a failure to the user. In the instance that DISPLAY is set, we'll + * attempt to make use of zenity + */ +void lsi_report_failure(const char *s, ...); + /* * Editor modelines - https://www.wireshark.org/tools/modelines.html * diff --git a/src/shim/shim.c b/src/shim/shim.c index 1b8ef87..46d8de4 100644 --- a/src/shim/shim.c +++ b/src/shim/shim.c @@ -76,7 +76,9 @@ int main(int argc, char **argv) /* Go execute steam. */ if (execv(exec_command, (char **)n_argv) < 0) { /* TODO: Use Zenity when we have a UI */ - fprintf(stderr, "Failed to launch Steam: %s [%s]\n", strerror(errno), STEAM_BINARY); + lsi_report_failure("Failed to launch Steam: %s [%s]", + strerror(errno), + STEAM_BINARY); return EXIT_FAILURE; } }