* Additionally, it’s even useful sometimes :-).
*
*/
+#include "libi3.h"
+
#include <stdio.h>
#include <stdbool.h>
#include <sys/types.h>
#include <xcb/xcb.h>
#include <xcb/xcb_aux.h>
-#include "libi3.h"
#include <i3/ipc.h>
static char *socket_path;
};
int main(int argc, char *argv[]) {
- socket_path = getenv("I3SOCK");
+#if defined(__OpenBSD__)
+ if (pledge("stdio rpath unix", NULL) == -1)
+ err(EXIT_FAILURE, "pledge");
+#endif
+ char *env_socket_path = getenv("I3SOCK");
+ if (env_socket_path)
+ socket_path = sstrdup(env_socket_path);
+ else
+ socket_path = NULL;
int o, option_index = 0;
uint32_t message_type = I3_IPC_MESSAGE_TYPE_COMMAND;
char *payload = NULL;
message_type = I3_IPC_MESSAGE_TYPE_GET_MARKS;
else if (strcasecmp(optarg, "get_bar_config") == 0)
message_type = I3_IPC_MESSAGE_TYPE_GET_BAR_CONFIG;
+ else if (strcasecmp(optarg, "get_binding_modes") == 0)
+ message_type = I3_IPC_MESSAGE_TYPE_GET_BINDING_MODES;
else if (strcasecmp(optarg, "get_version") == 0)
message_type = I3_IPC_MESSAGE_TYPE_GET_VERSION;
else {
printf("Unknown message type\n");
- printf("Known types: command, get_workspaces, get_outputs, get_tree, get_marks, get_bar_config, get_version\n");
+ printf("Known types: command, get_workspaces, get_outputs, get_tree, get_marks, get_bar_config, get_binding_modes, get_version\n");
exit(EXIT_FAILURE);
}
} else if (o == 'q') {
payload = sstrdup(argv[optind]);
} else {
char *both;
- if (asprintf(&both, "%s %s", payload, argv[optind]) == -1)
- err(EXIT_FAILURE, "asprintf");
+ sasprintf(&both, "%s %s", payload, argv[optind]);
free(payload);
payload = both;
}
}
if (!payload)
- payload = "";
+ payload = sstrdup("");
int sockfd = socket(AF_LOCAL, SOCK_STREAM, 0);
if (sockfd == -1)
if (ipc_send_message(sockfd, strlen(payload), message_type, (uint8_t *)payload) == -1)
err(EXIT_FAILURE, "IPC: write()");
+ free(payload);
if (quiet)
return 0;
/* For the reply of commands, have a look if that command was successful.
* If not, nicely format the error message. */
if (reply_type == I3_IPC_MESSAGE_TYPE_COMMAND) {
- yajl_handle handle;
- handle = yajl_alloc(&reply_callbacks, NULL, NULL);
+ yajl_handle handle = yajl_alloc(&reply_callbacks, NULL, NULL);
yajl_status state = yajl_parse(handle, (const unsigned char *)reply, reply_length);
+ yajl_free(handle);
+
switch (state) {
case yajl_status_ok:
break;