From 3d8fe1502db9c93883b5899ab405e8610c148b99 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Thu, 5 Oct 2017 18:06:23 +0100 Subject: [PATCH] fishdescriptor: .so can be loaded (gdb) print (void*)dlopen("/u/iwj/things/chiark-utils.git/fishdescriptor/libfishdescriptor-donate.so.1.0",2) $5 = (void *) 0x8f0d408 (gdb) print (void*)dlsym($5, "fishdescriptor_donate") $6 = (void *) 0xf6953620 (gdb) print (( int (*)(const char *, const int *) )$6)("/dev/enoent", (int[2]){0,-1}) $7 = 2 (gdb) print strerror(2) $8 = 0xf74697e8 "No such file or directory" (gdb) Signed-off-by: Ian Jackson --- fishdescriptor/.gitignore | 1 + fishdescriptor/Makefile | 15 +++++++++++++-- fishdescriptor/donate.c | 7 ++++--- 3 files changed, 18 insertions(+), 5 deletions(-) create mode 100644 fishdescriptor/.gitignore diff --git a/fishdescriptor/.gitignore b/fishdescriptor/.gitignore new file mode 100644 index 0000000..41c45ad --- /dev/null +++ b/fishdescriptor/.gitignore @@ -0,0 +1 @@ +libfishdescriptor-donate.so.* diff --git a/fishdescriptor/Makefile b/fishdescriptor/Makefile index dd0dfbe..f906515 100644 --- a/fishdescriptor/Makefile +++ b/fishdescriptor/Makefile @@ -1,4 +1,15 @@ -fishdescriptor-donate.so: donate.o - $(CC) -shared -Wl,-soname $(LIBCANON) -o $@ $< $(LIBS) +OPTIMISE = -O2 +DEBUG = -g + +CFLAGS = -Wall -Werror -Wwrite-strings +CFLAGS += $(OPTIMISE) $(DEBUG) + +MAJOR=1 +MINOR=0 +LIBCANON= libfishdescriptor-donate.so.$(MAJOR) +LIBTARGET= $(LIBCANON).$(MINOR) + +$(LIBTARGET): donate.o + $(CC) -shared -Wl,-soname -Wl,$(LIBCANON) -o $@ $< $(LIBS) donate.o: donate.c diff --git a/fishdescriptor/donate.c b/fishdescriptor/donate.c index 6e5dea7..11c51db 100644 --- a/fishdescriptor/donate.c +++ b/fishdescriptor/donate.c @@ -18,6 +18,7 @@ #include #include +#include #include #include @@ -65,12 +66,12 @@ int fishdescriptor_donate(const char *path, const int *fds) { int carrier=-1; carrier = socket(AF_UNIX, SOCK_STREAM, 0); - if (carrier < 0) goto out; + if (carrier < 0) { r=-1; goto out; } struct sockaddr_un suna; memset(&suna,0,sizeof(suna)); suna.sun_family = AF_UNIX; - if (strlen(path) >= sizeof(suna.sun_path)) { errno = E2BIG; goto out; } + if (strlen(path) >= sizeof(suna.sun_path)) { errno=E2BIG; r=-1; goto out; } strcpy(suna.sun_path, path); r = connect(carrier, (const struct sockaddr*)&suna, sizeof(suna)); @@ -86,6 +87,6 @@ int fishdescriptor_donate(const char *path, const int *fds) { out: if (carrier >= 0) close(carrier); r = !r ? 0 : !errno ? EIO : errno; - esave = errno; + errno = esave; return r; } -- 2.30.2