summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-12-24 13:18:00 +0100
committerDiogo Franco (Kovensky) <diogomfranco@gmail.com>2015-01-25 17:00:14 +0900
commit37210f0cbc1c00a06a4e84dfabb55e1046e6182c (patch)
tree8cf9a8d5177aafb0b8f500a2d0885da52f1fd313
parentf24b8cbd47a9e75c635b1537aff16de18d350021 (diff)
downloadmpv-37210f0cbc1c00a06a4e84dfabb55e1046e6182c.tar.bz2
mpv-37210f0cbc1c00a06a4e84dfabb55e1046e6182c.tar.xz
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.
-rw-r--r--input/ipc.c7
1 files 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);