aboutsummaryrefslogtreecommitdiff
path: root/lib/init
diff options
context:
space:
mode:
authorDavid Oberhollenzer <goliath@infraroot.at>2019-03-29 11:02:22 +0100
committerDavid Oberhollenzer <goliath@infraroot.at>2019-03-29 21:00:53 +0100
commitbe066419049587e1349ada03306d004c30c18da6 (patch)
treed7262525f81370c865ef473f3c8e5649cc306611 /lib/init
parentc3d14cbfa863ea3af8aaa253f1d7d3909adf1547 (diff)
cleanup: init socket wire format
Replace array adhockery with structs and make use of the handy endianness conversion macros. Signed-off-by: David Oberhollenzer <goliath@infraroot.at>
Diffstat (limited to 'lib/init')
-rw-r--r--lib/init/init_socket_recv_status.c22
1 files changed, 9 insertions, 13 deletions
diff --git a/lib/init/init_socket_recv_status.c b/lib/init/init_socket_recv_status.c
index d5ca2e6..996f8de 100644
--- a/lib/init/init_socket_recv_status.c
+++ b/lib/init/init_socket_recv_status.c
@@ -31,18 +31,17 @@ retry:
static char *read_string(int fd)
{
- uint8_t size_raw[2];
+ uint16_t len;
char *buffer;
- size_t len;
int ret;
- ret = read_retry(fd, size_raw, 2);
+ ret = read_retry(fd, &len, sizeof(len));
if (ret <= 0)
return NULL;
- len = (((size_t)size_raw[0]) << 8) | (size_t)size_raw[1];
+ len = be16toh(len);
- buffer = malloc(len + 1);
+ buffer = calloc(1, len + 1);
if (buffer == NULL)
return NULL;
@@ -57,24 +56,21 @@ static char *read_string(int fd)
}
}
- buffer[len] = '\0';
return buffer;
}
int init_socket_recv_status(int fd, init_status_t *resp)
{
- uint8_t info[8];
+ init_response_status_t info;
memset(resp, 0, sizeof(*resp));
- if (read_retry(fd, info, sizeof(info)) <= 0)
+ if (read_retry(fd, &info, sizeof(info)) <= 0)
return -1;
- resp->state = info[0];
- resp->exit_status = info[1];
-
- resp->id = ((int)info[4] << 24) | ((int)info[5] << 16) |
- ((int)info[6] << 8) | (int)info[7];
+ resp->state = info.state;
+ resp->exit_status = info.exit_status;
+ resp->id = be32toh(info.id);
if (resp->state == ESS_NONE)
return 0;