(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>
--- /dev/null
+libfishdescriptor-donate.so.*
-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)
#include <stdlib.h>
#include <errno.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/socket.h>
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));
out:
if (carrier >= 0) close(carrier);
r = !r ? 0 : !errno ? EIO : errno;
out:
if (carrier >= 0) close(carrier);
r = !r ? 0 : !errno ? EIO : errno;