From 98a80884da100eaee283447a0380c761b15266c7 Mon Sep 17 00:00:00 2001 From: wm4 Date: Wed, 24 Dec 2014 13:18:00 +0100 Subject: ipc: report some user errors better Using the IPC with a program, it's not often obvious that a newline must be sent to terminate a command. Print a warning if the connection is closed while there is still uninterpreted data in the buffer. Print the OS reported error if reading/writing the socket fails. Print an erro if JSON parsing fails. I considered silencing write errors if the write end is closed (EPIPE), because a client might send a bunch of commands, and then close the socket without wanting to read the reply. But then, mpv disconnects without reading further commands that might still be buffered, so it's probably a good idea to always print the error. --- input/ipc.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/input/ipc.c b/input/ipc.c index 7d15ac84d0..4fd9cf17e1 100644 --- a/input/ipc.c +++ b/input/ipc.c @@ -243,6 +243,7 @@ static char *json_execute_command(struct client_arg *arg, void *ta_parent, rc = json_parse(ta_parent, &msg_node, &src, 3); if (rc < 0) { + MP_ERR(arg, "malformed JSON received\n"); rc = MPV_ERROR_INVALID_PARAMETER; goto error; } @@ -546,7 +547,7 @@ static void *client_thread(void *p) if (errno == EAGAIN) break; - MP_ERR(arg, "Read error\n"); + MP_ERR(arg, "Read error (%s)\n", mp_strerror(errno)); goto done; } @@ -582,7 +583,7 @@ static void *client_thread(void *p) rc = ipc_write(arg->client_fd, reply_msg, strlen(reply_msg)); if (rc < 0) { - MP_ERR(arg, "Write error\n"); + MP_ERR(arg, "Write error (%s)\n", mp_strerror(errno)); talloc_free(tmp); goto done; } @@ -595,6 +596,8 @@ static void *client_thread(void *p) } done: + if (client_msg.len > 0) + MP_WARN(arg, "Ignoring unterminated command on disconnect.\n"); talloc_free(client_msg.start); if (arg->close_client_fd) close(arg->client_fd); -- cgit v1.2.3