chiark / gitweb /
fishdescriptor: .so can be loaded
authorIan Jackson <ian.jackson@eu.citrix.com>
Thu, 5 Oct 2017 17:06:23 +0000 (18:06 +0100)
committerIan Jackson <Ian.Jackson@eu.citrix.com>
Thu, 5 Oct 2017 17:06:23 +0000 (18:06 +0100)
(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 <fishdescriptor_donate>
(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 <Ian.Jackson@eu.citrix.com>
fishdescriptor/.gitignore [new file with mode: 0644]
fishdescriptor/Makefile
fishdescriptor/donate.c

diff --git a/fishdescriptor/.gitignore b/fishdescriptor/.gitignore
new file mode 100644 (file)
index 0000000..41c45ad
--- /dev/null
@@ -0,0 +1 @@
+libfishdescriptor-donate.so.*
index dd0dfbe3bc92db5e4cb036d93488b4b2083d537a..f9065154f58c17ba048456d7e10250567c71c78b 100644 (file)
@@ -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
 
 donate.o:                      donate.c
index 6e5dea7808290495b2fd5465b90cda94896a981e..11c51dbf8cc86ea507f1306efce0dff23a5ba25e 100644 (file)
@@ -18,6 +18,7 @@
 
 #include <stdlib.h>
 #include <errno.h>
 
 #include <stdlib.h>
 #include <errno.h>
+#include <unistd.h>
 
 #include <sys/types.h>
 #include <sys/socket.h>
 
 #include <sys/types.h>
 #include <sys/socket.h>
@@ -65,12 +66,12 @@ int fishdescriptor_donate(const char *path, const int *fds) {
   int carrier=-1;
 
   carrier = socket(AF_UNIX, SOCK_STREAM, 0);
   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;
 
   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));
   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;
  out:
   if (carrier >= 0) close(carrier);
   r = !r ? 0 : !errno ? EIO : errno;
-  esave = errno;
+  errno = esave;
   return r;
 }
   return r;
 }