]> git.sur5r.net Git - i3/i3/blobdiff - i3-msg/main.c
Merge pull request #2507 from stapelberg/autotools
[i3/i3] / i3-msg / main.c
index 354e8af90d61b0b939cbb7d241a0ac8a53cd2ebe..5161245970d848ddbdd0579b2ab59228500e811a 100644 (file)
@@ -2,7 +2,7 @@
  * vim:ts=4:sw=4:expandtab
  *
  * i3 - an improved dynamic tiling window manager
- * © 2009-2012 Michael Stapelberg and contributors (see also: LICENSE)
+ * © 2009 Michael Stapelberg and contributors (see also: LICENSE)
  *
  * i3-msg/main.c: Utility which sends messages to a running i3-instance using
  * IPC via UNIX domain sockets.
@@ -14,6 +14,8 @@
  * Additionally, it’s even useful sometimes :-).
  *
  */
+#include "libi3.h"
+
 #include <stdio.h>
 #include <stdbool.h>
 #include <sys/types.h>
@@ -34,7 +36,6 @@
 #include <xcb/xcb.h>
 #include <xcb/xcb_aux.h>
 
-#include "libi3.h"
 #include <i3/ipc.h>
 
 static char *socket_path;
@@ -77,7 +78,7 @@ static int reply_boolean_cb(void *params, int val) {
 }
 
 static int reply_string_cb(void *params, const unsigned char *val, size_t len) {
-    char *str = scalloc(len + 1);
+    char *str = scalloc(len + 1, 1);
     strncpy(str, (const char *)val, len);
     if (strcmp(last_key, "error") == 0)
         last_reply.error = str;
@@ -105,7 +106,7 @@ static int reply_end_map_cb(void *params) {
 
 static int reply_map_key_cb(void *params, const unsigned char *keyVal, size_t keyLen) {
     free(last_key);
-    last_key = scalloc(keyLen + 1);
+    last_key = scalloc(keyLen + 1, 1);
     strncpy(last_key, (const char *)keyVal, keyLen);
     return 1;
 }
@@ -119,7 +120,15 @@ static yajl_callbacks reply_callbacks = {
 };
 
 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;
@@ -153,11 +162,13 @@ int main(int argc, char *argv[]) {
                 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') {
@@ -187,8 +198,7 @@ int main(int argc, char *argv[]) {
             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;
         }