]> git.ipfire.org Git - thirdparty/wireguard-tools.git/commitdiff
wg: fixup errno handling
authorJason A. Donenfeld <Jason@zx2c4.com>
Sat, 17 Feb 2018 18:39:26 +0000 (19:39 +0100)
committerJason A. Donenfeld <Jason@zx2c4.com>
Sat, 17 Feb 2018 19:15:49 +0000 (20:15 +0100)
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
src/containers.h
src/ipc.c

index 8294ec742c11f084c344ebcfafb6a9f866a73b79..a23da1ce4bb8a8041835c88736ceecc9c972e24a 100644 (file)
@@ -78,7 +78,6 @@ struct wgdevice {
 
 #define for_each_wgpeer(__dev, __peer) for ((__peer) = (__dev)->first_peer; (__peer); (__peer) = (__peer)->next_peer)
 #define for_each_wgallowedip(__peer, __allowedip) for ((__allowedip) = (__peer)->first_allowedip; (__allowedip); (__allowedip) = (__allowedip)->next_allowedip)
-#define max(a, b) ((a) > (b) ? (a) : (b))
 
 static inline void free_wgdevice(struct wgdevice *dev)
 {
index edc8e8fcbffeb9f4c4ba1d281094e4c16acf754a..3f23d1d0922f486b7b1feff93c157e2f4c999eef 100644 (file)
--- a/src/ipc.c
+++ b/src/ipc.c
@@ -48,7 +48,6 @@
 #define SOCKET_BUFFER_SIZE 8192
 #endif
 
-
 struct inflatable_buffer {
        char *buffer;
        char *next;
@@ -57,6 +56,7 @@ struct inflatable_buffer {
        size_t pos;
 };
 
+#define max(a, b) ((a) > (b) ? (a) : (b))
 static int add_next_to_inflatable_buffer(struct inflatable_buffer *buffer)
 {
        size_t len, expand_to;
@@ -111,7 +111,7 @@ static FILE *userspace_interface_file(const char *interface)
        int fd = -1, ret;
        FILE *f = NULL;
 
-       ret = -EINVAL;
+       errno = EINVAL;
        if (strchr(interface, '/'))
                goto out;
        ret = snprintf(addr.sun_path, sizeof(addr.sun_path), SOCK_PATH "%s" SOCK_SUFFIX, interface);
@@ -120,7 +120,7 @@ static FILE *userspace_interface_file(const char *interface)
        ret = stat(addr.sun_path, &sbuf);
        if (ret < 0)
                goto out;
-       ret = -EBADF;
+       errno = EBADF;
        if (!S_ISSOCK(sbuf.st_mode))
                goto out;
 
@@ -135,12 +135,13 @@ static FILE *userspace_interface_file(const char *interface)
                goto out;
        }
        f = fdopen(fd, "r+");
-       if (!f)
-               ret = -errno;
+       if (f)
+               errno = 0;
 out:
-       if (ret && fd >= 0)
-               close(fd);
+       ret = -errno;
        if (ret) {
+               if (fd >= 0)
+                       close(fd);
                errno = -ret;
                return NULL;
        }