Commit bfd0e911 authored by Franksen, Benjamin's avatar Franksen, Benjamin
Browse files

scan: print errno message when system call fails

parent 64015b70
......@@ -226,7 +226,8 @@ static ssize_t ellsi_read(void *pvt, struct can_frame *frame) {
ntohl(state->msg.header.subcommand),
ntohl(state->msg.header.payloadLen));
if (nbytes < 0) {
fprintf(stderr, "ellsi_read: recv failed\n");
errbuf_t buf;
fprintf(stderr, "ellsi_read: recv failed (%s)\n", ERRNO_STR(buf));
return -1;
}
if (state->msg.header.magic != htonl(ELLSI_MAGIC)) {
......@@ -245,7 +246,8 @@ static ssize_t ellsi_read(void *pvt, struct can_frame *frame) {
assert(state->msg.header.payloadLen == 0);
nbytes = write(state->sock, &state->msg.header, sizeof(state->msg.header));
if (nbytes < sizeof(state->msg.header)) {
fprintf(stderr, "ellsi_read: reply to heartbeat failed\n");
errbuf_t buf;
fprintf(stderr, "ellsi_read: reply to heartbeat failed (%s)\n", ERRNO_STR(buf));
}
break;
#if 0
......@@ -335,7 +337,9 @@ static int ellsi_register(ellsi_state_t *state) {
ELLSI_MAGIC, ELLSI_CMD_REGISTER, ELLSI_SUBCMD_AUTOACK);
r = write(state->sock, &msg, sizeof(msg));
if (r < 0) {
fprintf(stderr, "ellsi_register: write failed\n"); return r;
errbuf_t buf;
fprintf(stderr, "ellsi_register: write failed (%s)\n", ERRNO_STR(buf));
return r;
}
return ellsi_check(state->sock);
}
......@@ -365,14 +369,18 @@ static int ellsi_set_baudrate(ellsi_state_t *state, int baudrate) {
ELLSI_MAGIC, ELLSI_CMD_CTRL, ELLSI_IOCTL_CAN_SET_BAUDRATE, code);
r = write(state->sock, &msg, sizeof(msg));
if (r < 0) {
fprintf(stderr, "ellsi_set_baudrate: write failed\n"); return r;
errbuf_t buf;
fprintf(stderr, "ellsi_set_baudrate: write failed (%s)\n", ERRNO_STR(buf));
return r;
}
msg.header.command = htonl(ELLSI_CMD_CTRL);
msg.header.subcommand = htonl(ELLSI_IOCTL_GET_LAST_STATE);
msg.header.payloadLen = htonl(sizeof(msg.payload));
r = write(state->sock, &msg, sizeof(msg));
if (r < 0) {
fprintf(stderr, "ellsi_set_baudrate: write failed\n"); return r;
errbuf_t buf;
fprintf(stderr, "ellsi_set_baudrate: write failed (%s)\n", ERRNO_STR(buf));
return r;
}
return ellsi_check(state->sock);
}
......@@ -395,14 +403,18 @@ static int ellsi_add_can_ids(ellsi_state_t *state) {
ELLSI_MAGIC, ELLSI_CMD_CTRL, ELLSI_IOCTL_CAN_ID_ADD);
r = write(state->sock, &msg, sizeof(msg));
if (r < 0) {
fprintf(stderr, "ellsi_add_can_ids: write failed\n"); return r;
errbuf_t buf;
fprintf(stderr, "ellsi_add_can_ids: write failed (%s)\n", ERRNO_STR(buf));
return r;
}
msg.header.command = htonl(ELLSI_CMD_CTRL);
msg.header.subcommand = htonl(ELLSI_IOCTL_GET_LAST_STATE);
msg.header.payloadLen = htonl(sizeof(msg.payload));
r = write(state->sock, &msg, sizeof(msg));
if (r < 0) {
fprintf(stderr, "ellsi_add_can_ids: write failed\n"); return r;
errbuf_t buf;
fprintf(stderr, "ellsi_add_can_ids: write failed (%s)\n", ERRNO_STR(buf));
return r;
}
return ellsi_check(state->sock);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment