From 1b536d70cc3267474a97f0f0826e3ad2c36ac65a Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Wed, 9 May 2012 19:46:44 +0200 Subject: [PATCH] Improve the main error message of i3-dump-log --- i3-dump-log/main.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/i3-dump-log/main.c b/i3-dump-log/main.c index 30dd514f..6b500ea3 100644 --- a/i3-dump-log/main.c +++ b/i3-dump-log/main.c @@ -55,8 +55,35 @@ int main(int argc, char *argv[]) { } char *shmname = root_atom_contents("I3_SHMLOG_PATH"); - if (shmname == NULL) + if (shmname == NULL) { + /* Something failed. Let’s invest a little effort to find out what it + * is. This is hugely helpful for users who want to debug i3 but are + * not used to the procedure yet. */ + xcb_connection_t *conn; + int screen; + if ((conn = xcb_connect(NULL, &screen)) == NULL || + xcb_connection_has_error(conn)) { + fprintf(stderr, "i3-dump-log: ERROR: Cannot connect to X11.\n\n"); + if (getenv("DISPLAY") == NULL) { + fprintf(stderr, "Your DISPLAY environment variable is not set.\n"); + fprintf(stderr, "Are you running i3-dump-log via SSH or on a virtual console?\n"); + fprintf(stderr, "Try DISPLAY=:0 i3-dump-log\n"); + exit(1); + } + fprintf(stderr, "FYI: The DISPLAY environment variable is set to \"%s\".\n", getenv("DISPLAY")); + exit(1); + } + if (root_atom_contents("I3_CONFIG_PATH") != NULL) { + fprintf(stderr, "i3-dump-log: ERROR: i3 is running, but SHM logging is not enabled.\n\n"); + if (!is_debug_build()) { + fprintf(stderr, "You seem to be using a release version of i3:\n %s\n\n", I3_VERSION); + fprintf(stderr, "Release versions do not use SHM logging by default,\ntherefore i3-dump-log does not work.\n\n"); + fprintf(stderr, "Please follow this guide instead:\nhttp://i3wm.org/docs/debugging-release-version.html\n"); + exit(1); + } + } errx(EXIT_FAILURE, "Cannot get I3_SHMLOG_PATH atom contents. Is i3 running on this display?"); + } if (*shmname == '\0') errx(EXIT_FAILURE, "Cannot dump log: SHM logging is disabled in i3."); -- 2.39.5