diff options
author | S. Christoffer Eliesen <christoffer@eliesen.no> | 2015-10-22 14:14:13 +0200 |
---|---|---|
committer | S. Christoffer Eliesen <christoffer@eliesen.no> | 2015-10-22 23:36:24 +0200 |
commit | af30a1b67c22aa54dad4e1a0ee3aacb537c4ab92 (patch) | |
tree | 013c1860550bb3c190095fd0633c08aca16838d1 /sway/ipc.c | |
parent | ipc: Return correct status in ipc reply. (diff) | |
download | sway-af30a1b67c22aa54dad4e1a0ee3aacb537c4ab92.tar.gz sway-af30a1b67c22aa54dad4e1a0ee3aacb537c4ab92.tar.zst sway-af30a1b67c22aa54dad4e1a0ee3aacb537c4ab92.zip |
ipc,commands,config: Replace cmd_status enum with cmd_results struct.
In i3 the ipc reply will contain a human readable error message, and
this patch replicates that behaviour.
However, that error message is also useful for logging, which this
patch takes advantage of.
E.g. instead of logging errors directly in commands.c/checkargs, it is
fed back to the caller which eventually ends up logging everything with
maximum context available (config.c/read_config).
So instead of logging e.g. "Error on line 'exit'" it will now log:
"Error on line 'exit': Can't execute from config."
Diffstat (limited to 'sway/ipc.c')
-rw-r--r-- | sway/ipc.c | 8 |
1 files changed, 5 insertions, 3 deletions
@@ -222,10 +222,12 @@ void ipc_client_handle_command(struct ipc_client *client) { | |||
222 | case IPC_COMMAND: | 222 | case IPC_COMMAND: |
223 | { | 223 | { |
224 | buf[client->payload_length] = '\0'; | 224 | buf[client->payload_length] = '\0'; |
225 | bool success = (handle_command(buf) == CMD_SUCCESS); | 225 | struct cmd_results *results = handle_command(buf); |
226 | char reply[64]; | 226 | const char *json = cmd_results_to_json(results); |
227 | int length = snprintf(reply, sizeof(reply), "{\"success\":%s}", success ? "true" : "false"); | 227 | char reply[256]; |
228 | int length = snprintf(reply, sizeof(reply), "%s", json); | ||
228 | ipc_send_reply(client, reply, (uint32_t) length); | 229 | ipc_send_reply(client, reply, (uint32_t) length); |
230 | free_cmd_results(results); | ||
229 | break; | 231 | break; |
230 | } | 232 | } |
231 | case IPC_GET_WORKSPACES: | 233 | case IPC_GET_WORKSPACES: |