+ char *shmname = root_atom_contents("I3_SHMLOG_PATH", NULL, 0);
+ 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", conn, screen) != NULL) {
+ fprintf(stderr, "i3-dump-log: ERROR: i3 is running, but SHM logging is not enabled. Enabling SHM log until cancelled\n\n");
+ ipcfd = ipc_connect(NULL);
+ const char *enablecmd = "debuglog on; shmlog 5242880";
+ if (ipc_send_message(ipcfd, strlen(enablecmd),
+ I3_IPC_MESSAGE_TYPE_COMMAND, (uint8_t *)enablecmd) != 0)
+ err(EXIT_FAILURE, "IPC send");
+ /* By the time we receive a reply, I3_SHMLOG_PATH is set: */
+ uint32_t reply_length = 0;
+ uint8_t *reply = NULL;
+ if (ipc_recv_message(ipcfd, I3_IPC_REPLY_TYPE_COMMAND,
+ &reply_length, &reply) != 0) {
+ err(EXIT_FAILURE, "IPC recv");
+ }
+ free(reply);
+
+ atexit(disable_shmlog);
+
+ /* Retry: */
+ shmname = root_atom_contents("I3_SHMLOG_PATH", NULL, 0);
+ if (shmname == NULL && !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:\nhttps://i3wm.org/docs/debugging-release-version.html\n");
+ exit(1);
+ }
+ }
+ if (shmname == NULL) {
+ errx(EXIT_FAILURE, "Cannot get I3_SHMLOG_PATH atom contents. Is i3 running on this display?");
+ }
+ }