40#define KEY_MATCHES(x) (stringlen == strlen(x) && strncmp((const char *)stringval, x, strlen(x)) == 0)
58 printf(
" %s (%s)", path, role);
59 if (stat(path, &sb) == -1) {
61 ELOG(
"Cannot stat config file \"%s\"\n", path);
63 strftime(mtime,
sizeof(mtime),
"%c", localtime(&(sb.st_mtime)));
65 printf(
" (last modified: %s, %.f seconds ago)\n", mtime, difftime(now, sb.st_mtime));
82 if (getenv(
"DISPLAY") == NULL) {
83 fprintf(stderr,
"\nYour DISPLAY environment variable is not set.\n");
84 fprintf(stderr,
"Are you running i3 via SSH or on a virtual console?\n");
85 fprintf(stderr,
"Try DISPLAY=:0 i3 --moreversion\n");
90 if (pid_from_atom == NULL) {
92 printf(
"\nRunning version: < 4.2-200\n");
98 printf(
"(Getting version from running i3, press ctrl-c to abort…)");
103 (uint8_t *)
"") == -1) {
104 err(EXIT_FAILURE,
"IPC: write()");
107 uint32_t reply_length;
111 if ((ret =
ipc_recv_message(sockfd, &reply_type, &reply_length, &reply)) != 0) {
113 err(EXIT_FAILURE,
"IPC: read()");
118 if (reply_type != I3_IPC_MESSAGE_TYPE_GET_VERSION) {
119 errx(EXIT_FAILURE,
"Got reply type %d, but expected %d (GET_VERSION)", reply_type, I3_IPC_MESSAGE_TYPE_GET_VERSION);
124 yajl_status
state = yajl_parse(handle, (
const unsigned char *)reply, (
int)reply_length);
125 if (
state != yajl_status_ok) {
126 errx(EXIT_FAILURE,
"Could not parse my own reply. That's weird. reply is %.*s", (
int)reply_length, reply);
133 printf(
"Loaded i3 config:\n");
142 size_t destpath_size = 1024;
145 char *destpath =
smalloc(destpath_size);
147 sasprintf(&exepath,
"/proc/%d/exe", getpid());
149 while ((linksize = readlink(exepath, destpath, destpath_size)) == (ssize_t)destpath_size) {
150 destpath_size = destpath_size * 2;
151 destpath =
srealloc(destpath, destpath_size);
153 if (linksize == -1) {
154 err(EXIT_FAILURE,
"readlink(%s)", exepath);
158 destpath[linksize] =
'\0';
161 printf(
"The i3 binary you just called: %s\n", destpath);
164 sasprintf(&exepath,
"/proc/%s/exe", pid_from_atom);
166 while ((linksize = readlink(exepath, destpath, destpath_size)) == (ssize_t)destpath_size) {
167 destpath_size = destpath_size * 2;
168 destpath =
srealloc(destpath, destpath_size);
170 if (linksize == -1) {
171 err(EXIT_FAILURE,
"readlink(%s)", exepath);
175 destpath[linksize] =
'\0';
179 if (strstr(destpath,
"(deleted)") != NULL) {
180 printf(
"RUNNING BINARY DIFFERENT FROM BINARY ON DISK!\n");
187 sasprintf(&exepath,
"/proc/%s/cmdline", pid_from_atom);
190 if ((fd = open(exepath, O_RDONLY)) == -1) {
191 err(EXIT_FAILURE,
"open(%s)", exepath);
193 if (read(fd, destpath,
sizeof(destpath)) == -1) {
194 err(EXIT_FAILURE,
"read(%s)", exepath);
198 printf(
"The i3 binary you are running: %s\n", destpath);
struct includedfiles_head included_files
static yajl_callbacks version_callbacks
static bool included_config_file_names
static void print_config_path(const char *path, const char *role)
static char * loaded_config_file_name
static int version_map_key(void *ctx, const unsigned char *stringval, size_t stringlen)
static int version_string(void *ctx, const unsigned char *val, size_t len)
static bool human_readable_key
static char * human_readable_version
static bool loaded_config_file_name_key
void display_running_version(void)
Connects to i3 to find out the currently running version.
static xcb_cursor_context_t * ctx
xcb_connection_t * conn
XCB connection and root screen.
int ipc_recv_message(int sockfd, uint32_t *message_type, uint32_t *reply_length, uint8_t **reply)
Reads a message from the given socket file descriptor and stores its length (reply_length) as well as...
void * scalloc(size_t num, size_t size)
Safe-wrapper around calloc which exits if malloc returns NULL (meaning that there is no more memory a...
int sasprintf(char **strp, const char *fmt,...)
Safe-wrapper around asprintf which exits if it returns -1 (meaning that there is no more memory avail...
void * srealloc(void *ptr, size_t size)
Safe-wrapper around realloc which exits if realloc returns NULL (meaning that there is no more memory...
char * root_atom_contents(const char *atomname, xcb_connection_t *provided_conn, int screen)
Try to get the contents of the given atom (for example I3_SOCKET_PATH) from the X11 root window and r...
int ipc_connect(const char *socket_path)
Connects to the i3 IPC socket and returns the file descriptor for the socket.
int ipc_send_message(int sockfd, const uint32_t message_size, const uint32_t message_type, const uint8_t *payload)
Formats a message (payload) of the given size and type and sends it to i3 via the given socket file d...
void * smalloc(size_t size)
Safe-wrapper around malloc which exits if malloc returns NULL (meaning that there is no more memory a...
#define TAILQ_FOREACH(var, head, field)
#define TAILQ_INSERT_TAIL(head, elm, field)
List entry struct for an included file.