chiark / gitweb /
fishdescriptor: wip (found)
[chiark-utils.git] / fishdescriptor / donate.c
index 6e5dea7808290495b2fd5465b90cda94896a981e..11c51dbf8cc86ea507f1306efce0dff23a5ba25e 100644 (file)
@@ -18,6 +18,7 @@
 
 #include <stdlib.h>
 #include <errno.h>
+#include <unistd.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);
-  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;
 }