commit d2a2f2226a0530307ca80b00dbb046eb6bd516b4
parent 58fd999785f133bf3fce1ecc67a3ac60b55a80f4
Author: kyle <kyle@getaddrinfo.net>
Date: Sat, 5 Mar 2016 01:10:02 -0700
runtime: add wip unix socket connection code
Diffstat:
3 files changed, 39 insertions(+), 3 deletions(-)
diff --git a/runtime/Makefile b/runtime/Makefile
@@ -3,12 +3,12 @@ error_SCV_PATH
.endif
CFLAGS += -fPIC -pthread
-LIB = libruntime.a
+LIB = libruntime.so
SRCS = runtime.c
OBJS = $(SRCS:c=o)
$(LIB): $(OBJS)
- $(AR) cr $(LIB) $(OBJS)
+ $(CC) $(CFLAGS) -shared -o $(LIB) $(OBJS)
clean:
rm -f $(OBJS) $(LIB)
diff --git a/runtime/libruntime.so b/runtime/libruntime.so
Binary files differ.
diff --git a/runtime/runtime.c b/runtime/runtime.c
@@ -1,14 +1,50 @@
+#include <err.h>
#include <pthread.h>
#include <stdio.h>
+#include <string.h>
+#include <sys/socket.h> // AF_UNIX
+#include <sys/un.h> // sockaddr_un
+
/* guaranteed to exist at link time because of instrumentation */
extern unsigned int lines[];
extern int size;
+extern const char file_name[];
void *
control_thread(void *arg)
{
- // printf("control thread says %i bytes!\n", size);
+ int fd;
+ int i, set;
+
+ printf("%s: file '%s' (%i bytes)\n", __func__, file_name, size);
+
+ fd = socket(AF_UNIX, SOCK_STREAM, 0);
+ if (fd == -1)
+ err(1, "socket");
+
+ struct sockaddr_un addr;
+ memset(&addr, 0, sizeof(addr));
+ addr.sun_family = AF_UNIX;
+ strncpy(addr.sun_path, "socket", sizeof(addr.sun_path) - 1);
+
+ printf("%s: initialized\n", __func__);
+
+ while (1) {
+ if (connect(fd, (struct sockaddr *)&addr, sizeof(addr)))
+ warn("connect");
+
+ set = 0;
+ for (i = 0; i < size; i++)
+ if (lines[i] == 1) {
+ set++;
+ lines[i] = 0;
+ }
+
+ printf("%i lines set\n", set);
+
+ sleep(1);
+ }
}
__attribute__((constructor))