socket-util: Unlink Unix domain sockets that bind but fail to connect.
[sliver-openvswitch.git] / lib / socket-util.c
index 26e2908..94ff391 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2009, 2010, 2011 Nicira Networks.
+ * Copyright (c) 2008, 2009, 2010, 2011, 2012 Nicira Networks.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -458,7 +458,7 @@ error:
         error = EPROTO;
     }
     if (bind_path) {
-        fatal_signal_remove_file_to_unlink(bind_path);
+        fatal_signal_unlink_file_now(bind_path);
     }
     close(fd);
     return -error;
@@ -673,7 +673,7 @@ inet_open_passive(int style, const char *target, int default_port,
     unsigned int yes = 1;
 
     if (!inet_parse_passive(target, default_port, &sin)) {
-        return EAFNOSUPPORT;
+        return -EAFNOSUPPORT;
     }
 
     /* Create non-blocking socket, set SO_REUSEADDR. */
@@ -681,7 +681,7 @@ inet_open_passive(int style, const char *target, int default_port,
     if (fd < 0) {
         error = errno;
         VLOG_ERR("%s: socket: %s", target, strerror(error));
-        return error;
+        return -error;
     }
     error = set_nonblocking(fd);
     if (error) {
@@ -716,6 +716,7 @@ inet_open_passive(int style, const char *target, int default_port,
             goto error;
         }
         if (sin.sin_family != AF_INET || sin_len != sizeof sin) {
+            error = EAFNOSUPPORT;
             VLOG_ERR("%s: getsockname: invalid socket name", target);
             goto error;
         }
@@ -726,7 +727,7 @@ inet_open_passive(int style, const char *target, int default_port,
 
 error:
     close(fd);
-    return error;
+    return -error;
 }
 
 /* Returns a readable and writable fd for /dev/null, if successful, otherwise