Log anything that could prevent a daemon from starting.
[sliver-openvswitch.git] / lib / socket-util.c
index e97e7c9..12bbc71 100644 (file)
@@ -121,6 +121,20 @@ lookup_ip(const char *host_name, struct in_addr *addr)
     return 0;
 }
 
+/* Translates 'host_name', which must be a string representation of an IPv6
+ * address, into a numeric IPv6 address in '*addr'.  Returns 0 if successful,
+ * otherwise a positive errno value. */
+int
+lookup_ipv6(const char *host_name, struct in6_addr *addr)
+{
+    if (inet_pton(AF_INET6, host_name, addr) != 1) {
+        static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
+        VLOG_ERR_RL(&rl, "\"%s\" is not a valid IPv6 address", host_name);
+        return ENOENT;
+    }
+    return 0;
+}
+
 /* Returns the error condition associated with socket 'fd' and resets the
  * socket's error status. */
 int
@@ -219,8 +233,7 @@ static void
 make_sockaddr_un__(const char *name, struct sockaddr_un *un, socklen_t *un_len)
 {
     un->sun_family = AF_UNIX;
-    strncpy(un->sun_path, name, sizeof un->sun_path);
-    un->sun_path[sizeof un->sun_path - 1] = '\0';
+    ovs_strzcpy(un->sun_path, name, sizeof un->sun_path);
     *un_len = (offsetof(struct sockaddr_un, sun_path)
                 + strlen (un->sun_path) + 1);
 }
@@ -256,6 +269,8 @@ make_sockaddr_un(const char *name, struct sockaddr_un *un, socklen_t *un_len,
 
             dirfd = open(dir, O_DIRECTORY | O_RDONLY);
             if (dirfd < 0) {
+                free(base);
+                free(dir);
                 return errno;
             }
 
@@ -752,3 +767,10 @@ get_mtime(const char *file_name, struct timespec *mtime)
     }
 }
 
+void
+xpipe(int fds[2])
+{
+    if (pipe(fds)) {
+        VLOG_FATAL("failed to create pipe (%s)", strerror(errno));
+    }
+}