ipc/server: Improve error messages

This commit is contained in:
Jakob Bornecrantz 2020-04-30 20:37:24 +01:00
parent 6d770336b7
commit a4dcdf1f0b
3 changed files with 21 additions and 11 deletions

View file

@ -373,7 +373,10 @@ client_loop(volatile struct ipc_client_state *cs)
// We use epoll here to be able to timeout.
int ret = epoll_wait(epoll_fd, &event, 1, half_a_second_ms);
if (ret < 0) {
fprintf(stderr, "ERROR: Failed epoll_wait '%i'\n", ret);
fprintf(stderr,
"ERROR: Failed epoll_wait '%i', disconnecting "
"client.\n",
ret);
break;
}
@ -384,13 +387,16 @@ client_loop(volatile struct ipc_client_state *cs)
// Detect clients disconnecting gracefully.
if (ret > 0 && (event.events & EPOLLHUP) != 0) {
fprintf(stderr, "SERVER: Client disconnected\n");
break;
}
// Finally get the data that is waiting for us.
ssize_t len = recv(cs->ipc_socket_fd, &buf, IPC_BUF_SIZE, 0);
if (len < 4) {
fprintf(stderr, "ERROR: Invalid packet received\n");
fprintf(stderr,
"ERROR: Invalid packet received, disconnecting "
"client.\n");
break;
}
@ -398,13 +404,13 @@ client_loop(volatile struct ipc_client_state *cs)
ipc_command_t *ipc_command = (uint32_t *)buf;
ret = ipc_dispatch(cs, ipc_command);
if (ret < 0) {
fprintf(stderr, "ERROR: Failed to dispatch packet\n");
fprintf(stderr,
"ERROR: During packet handling, disconnecting "
"client.\n");
break;
}
}
fprintf(stderr, "SERVER: Client disconnected\n");
close(epoll_fd);
epoll_fd = -1;

View file

@ -498,5 +498,7 @@ ipc_server_main(int argc, char **argv)
teardown_all(s);
free(s);
fprintf(stderr, "SERVER: Exiting! '%i'\n", ret);
return ret;
}

View file

@ -41,10 +41,10 @@ ipc_reply(int socket, void *data, size_t len)
ssize_t ret = sendmsg(socket, &msg, MSG_NOSIGNAL);
if (ret < 0) {
printf(
"sending plain message on socket %d failed with error: "
"%s\n",
socket, strerror(errno));
fprintf(stderr,
"ERROR: Sending plain message on socket %d failed with "
"error: '%i' '%s'\n",
socket, errno, strerror(errno));
}
return ret;
@ -77,8 +77,10 @@ ipc_reply_fds(int socket, void *data, size_t size, int *fds, uint32_t num_fds)
ssize_t ret = sendmsg(socket, &msg, MSG_NOSIGNAL);
if (ret < 0) {
printf("sending %d FDs on socket %d failed with error: %s\n",
num_fds, socket, strerror(errno));
fprintf(stderr,
"ERROR: sending %d FDs on socket %d failed with error: "
"'%i' '%s'\n",
num_fds, socket, errno, strerror(errno));
}
return ret;