summaryrefslogtreecommitdiffstats
path: root/src/daemon/proto_stdio.c
diff options
context:
space:
mode:
authorGravatar Gediminas Jakutis <gediminas@varciai.lt> 2019-06-09 23:08:36 +0300
committerGravatar Gediminas Jakutis <gediminas@varciai.lt> 2019-06-09 23:08:36 +0300
commit7c5042af3c606081d3f4b917ef667f6ed05780a8 (patch)
treed6f7adcaca6cb22ca44002b41dba43e069ffbebd /src/daemon/proto_stdio.c
parent613622e8cb3c1d32c50e19d7f446d0c00c91250e (diff)
downloadusurpation-7c5042af3c606081d3f4b917ef667f6ed05780a8.tar.gz
usurpation-7c5042af3c606081d3f4b917ef667f6ed05780a8.tar.bz2
usurpation-7c5042af3c606081d3f4b917ef667f6ed05780a8.zip
hook various previously unused modules together.
This now allows us to send messages to the device and such. Yay? Yay. Signed-off-by: Gediminas Jakutis <gediminas@varciai.lt>
Diffstat (limited to 'src/daemon/proto_stdio.c')
-rw-r--r--src/daemon/proto_stdio.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/daemon/proto_stdio.c b/src/daemon/proto_stdio.c
index 9aecdf0..6735746 100644
--- a/src/daemon/proto_stdio.c
+++ b/src/daemon/proto_stdio.c
@@ -23,7 +23,6 @@
#include "proto_stdio.h"
#include "proto_stdio_private.h"
-
void message_receive(char *arg)
{
int cancelstate;
@@ -37,19 +36,25 @@ void message_receive(char *arg)
nanosleep(&respite, NULL);
}
-char *message_send(void)
+struct tlv *message_send(struct tlv *in)
{
- char *ret = NULL;
+ struct tlv *ret = in;
int cancelstate;
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cancelstate);
pthread_mutex_lock(&state.out_m);
if (state.readbuf) {
- ret = strdup(state.readbuf);
+ tlv_init(ret, TEXT);
+ ret->data = malloc(state.bytes_read);
+ ret->head.size = state.bytes_read;
+ memcpy(ret->data, state.readbuf, state.bytes_read);
free(state.readbuf);
state.readbuf = NULL;
state.readbufsize = 0;
+ state.bytes_read = 0;
+ } else {
+ ret = NULL;
}
pthread_mutex_unlock(&state.out_m);
@@ -70,7 +75,7 @@ static void *read_stdin(void *arg)
pthread_mutex_lock(&state.in_m);
if (!state.readbuf) {
- state.readbufsize = getline(&state.readbuf, NULL, stdin);
+ state.bytes_read = getline(&state.readbuf, &state.readbufsize, stdin);
}
pthread_mutex_unlock(&state.in_m);