}
static yajl_callbacks version_callbacks = {
- NULL, /* null */
- NULL, /* boolean */
- NULL, /* integer */
- NULL, /* double */
- NULL, /* number */
- &version_string,
- NULL, /* start_map */
- &version_map_key,
- NULL, /* end_map */
- NULL, /* start_array */
- NULL /* end_array */
+ .yajl_string = version_string,
+ .yajl_map_key = version_map_key,
};
/*
*
*/
void display_running_version(void) {
- char *socket_path = root_atom_contents("I3_SOCKET_PATH");
+ char *socket_path = root_atom_contents("I3_SOCKET_PATH", conn, conn_screen);
if (socket_path == NULL)
exit(EXIT_SUCCESS);
- char *pid_from_atom = root_atom_contents("I3_PID");
+ char *pid_from_atom = root_atom_contents("I3_PID", conn, conn_screen);
if (pid_from_atom == NULL) {
/* If I3_PID is not set, the running version is older than 4.2-200. */
printf("\nRunning version: < 4.2-200\n");
err(EXIT_FAILURE, "IPC: write()");
uint32_t reply_length;
+ uint32_t reply_type;
uint8_t *reply;
int ret;
- if ((ret = ipc_recv_message(sockfd, I3_IPC_MESSAGE_TYPE_GET_VERSION,
- &reply_length, &reply)) != 0) {
+ if ((ret = ipc_recv_message(sockfd, &reply_type, &reply_length, &reply)) != 0) {
if (ret == -1)
err(EXIT_FAILURE, "IPC: read()");
exit(EXIT_FAILURE);
}
+ if (reply_type != I3_IPC_MESSAGE_TYPE_GET_VERSION)
+ errx(EXIT_FAILURE, "Got reply type %d, but expected %d (GET_VERSION)", reply_type, I3_IPC_MESSAGE_TYPE_GET_VERSION);
+
#if YAJL_MAJOR >= 2
yajl_handle handle = yajl_alloc(&version_callbacks, NULL, NULL);
#else
printf("\rRunning i3 version: %s (pid %s)\n", human_readable_version, pid_from_atom);
#ifdef __linux__
- char exepath[PATH_MAX],
- destpath[PATH_MAX];
+ size_t destpath_size = 1024;
ssize_t linksize;
+ char *exepath;
+ char *destpath = smalloc(destpath_size);
- snprintf(exepath, sizeof(exepath), "/proc/%d/exe", getpid());
+ sasprintf(&exepath, "/proc/%d/exe", getpid());
- if ((linksize = readlink(exepath, destpath, sizeof(destpath))) == -1)
+ while ((linksize = readlink(exepath, destpath, destpath_size)) == (ssize_t)destpath_size) {
+ destpath_size = destpath_size * 2;
+ destpath = srealloc(destpath, destpath_size);
+ }
+ if (linksize == -1)
err(EXIT_FAILURE, "readlink(%s)", exepath);
/* readlink() does not NULL-terminate strings, so we have to. */
printf("\n");
printf("The i3 binary you just called: %s\n", destpath);
- snprintf(exepath, sizeof(exepath), "/proc/%s/exe", pid_from_atom);
+ free(exepath);
+ sasprintf(&exepath, "/proc/%s/exe", pid_from_atom);
- if ((linksize = readlink(exepath, destpath, sizeof(destpath))) == -1)
+ while ((linksize = readlink(exepath, destpath, destpath_size)) == (ssize_t)destpath_size) {
+ destpath_size = destpath_size * 2;
+ destpath = srealloc(destpath, destpath_size);
+ }
+ if (linksize == -1)
err(EXIT_FAILURE, "readlink(%s)", exepath);
/* readlink() does not NULL-terminate strings, so we have to. */
/* Since readlink() might put a "(deleted)" somewhere in the buffer and
* stripping that out seems hackish and ugly, we read the process’s argv[0]
* instead. */
- snprintf(exepath, sizeof(exepath), "/proc/%s/cmdline", pid_from_atom);
+ free(exepath);
+ sasprintf(&exepath, "/proc/%s/cmdline", pid_from_atom);
int fd;
if ((fd = open(exepath, O_RDONLY)) == -1)
close(fd);
printf("The i3 binary you are running: %s\n", destpath);
+
+ free(exepath);
+ free(destpath);
#endif
yajl_free(handle);