From 544c6c412a3e432cb88a4454d0ccfab2856fac8c Mon Sep 17 00:00:00 2001 From: "S. Christoffer Eliesen" Date: Thu, 22 Oct 2015 13:00:37 +0200 Subject: ipc: Return correct status in ipc reply. --- sway/ipc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sway/ipc.c') diff --git a/sway/ipc.c b/sway/ipc.c index e4deb4d4..1521e5cd 100644 --- a/sway/ipc.c +++ b/sway/ipc.c @@ -222,7 +222,7 @@ void ipc_client_handle_command(struct ipc_client *client) { case IPC_COMMAND: { buf[client->payload_length] = '\0'; - bool success = handle_command(buf); + bool success = (handle_command(buf) == CMD_SUCCESS); char reply[64]; int length = snprintf(reply, sizeof(reply), "{\"success\":%s}", success ? "true" : "false"); ipc_send_reply(client, reply, (uint32_t) length); -- cgit v1.2.3 From af30a1b67c22aa54dad4e1a0ee3aacb537c4ab92 Mon Sep 17 00:00:00 2001 From: "S. Christoffer Eliesen" Date: Thu, 22 Oct 2015 14:14:13 +0200 Subject: 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." --- sway/ipc.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'sway/ipc.c') diff --git a/sway/ipc.c b/sway/ipc.c index 1521e5cd..1134f1a2 100644 --- a/sway/ipc.c +++ b/sway/ipc.c @@ -222,10 +222,12 @@ void ipc_client_handle_command(struct ipc_client *client) { case IPC_COMMAND: { buf[client->payload_length] = '\0'; - bool success = (handle_command(buf) == CMD_SUCCESS); - char reply[64]; - int length = snprintf(reply, sizeof(reply), "{\"success\":%s}", success ? "true" : "false"); + struct cmd_results *results = handle_command(buf); + const char *json = cmd_results_to_json(results); + char reply[256]; + int length = snprintf(reply, sizeof(reply), "%s", json); ipc_send_reply(client, reply, (uint32_t) length); + free_cmd_results(results); break; } case IPC_GET_WORKSPACES: -- cgit v1.2.3