From: Ethan Jackson Date: Wed, 10 Oct 2012 20:33:54 +0000 (-0700) Subject: ovs-ofctl: Don't rely on stat() to check unix sockets. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c3f2538933e2a7663283158a8bf806bf66ac1a23;p=openvswitch ovs-ofctl: Don't rely on stat() to check unix sockets. ESX supports unix sockets, but they don't manifest themselves in file system like they do on Linux. Instead of using stat to check if a unix socket exist, this patch simply tries to open it instead. Signed-off-by: Ethan Jackson --- diff --git a/lib/stream-unix.c b/lib/stream-unix.c index 4feefdfd..6dee17d7 100644 --- a/lib/stream-unix.c +++ b/lib/stream-unix.c @@ -48,7 +48,7 @@ unix_open(const char *name, char *suffix, struct stream **streamp, fd = make_unix_socket(SOCK_STREAM, true, NULL, connect_path); if (fd < 0) { - VLOG_WARN("%s: connection failed (%s)", connect_path, strerror(-fd)); + VLOG_DBG("%s: connection failed (%s)", connect_path, strerror(-fd)); return -fd; } diff --git a/utilities/ovs-ofctl.c b/utilities/ovs-ofctl.c index 08c3aa92..363c0a3a 100644 --- a/utilities/ovs-ofctl.c +++ b/utilities/ovs-ofctl.c @@ -52,6 +52,7 @@ #include "poll-loop.h" #include "random.h" #include "stream-ssl.h" +#include "socket-util.h" #include "timeval.h" #include "unixctl.h" #include "util.h" @@ -332,14 +333,20 @@ run(int retval, const char *message, ...) /* Generic commands. */ -static void +static int open_vconn_socket(const char *name, struct vconn **vconnp) { char *vconn_name = xasprintf("unix:%s", name); - VLOG_DBG("connecting to %s", vconn_name); - run(vconn_open_block(vconn_name, 0, vconnp), - "connecting to %s", vconn_name); + int error; + + error = vconn_open(vconn_name, 0, vconnp, DSCP_DEFAULT); + if (error && error != ENOENT) { + ovs_fatal(0, "%s: failed to open socket (%s)", name, + strerror(error)); + } free(vconn_name); + + return error; } static enum ofputil_protocol @@ -350,7 +357,7 @@ open_vconn__(const char *name, const char *default_suffix, enum ofputil_protocol protocol; char *bridge_path; int ofp_version; - struct stat s; + int error; bridge_path = xasprintf("%s/%s.%s", ovs_rundir(), name, default_suffix); @@ -362,16 +369,12 @@ open_vconn__(const char *name, const char *default_suffix, if (strchr(name, ':')) { run(vconn_open_block(name, 0, vconnp), "connecting to %s", name); - } else if (!stat(name, &s) && S_ISSOCK(s.st_mode)) { - open_vconn_socket(name, vconnp); - } else if (!stat(bridge_path, &s) && S_ISSOCK(s.st_mode)) { - open_vconn_socket(bridge_path, vconnp); - } else if (!stat(socket_name, &s)) { - if (!S_ISSOCK(s.st_mode)) { - ovs_fatal(0, "cannot connect to %s: %s is not a socket", - name, socket_name); - } - open_vconn_socket(socket_name, vconnp); + } else if (!open_vconn_socket(name, vconnp)) { + /* Fall Through. */ + } else if (!open_vconn_socket(bridge_path, vconnp)) { + /* Fall Through. */ + } else if (!open_vconn_socket(socket_name, vconnp)) { + /* Fall Through. */ } else { ovs_fatal(0, "%s is not a bridge or a socket", name); } @@ -379,6 +382,13 @@ open_vconn__(const char *name, const char *default_suffix, free(bridge_path); free(socket_name); + VLOG_DBG("connecting to %s", vconn_get_name(*vconnp)); + error = vconn_connect_block(*vconnp); + if (error) { + ovs_fatal(0, "%s: failed to connect to socket (%s)", name, + strerror(error)); + } + ofp_version = vconn_get_version(*vconnp); protocol = ofputil_protocol_from_ofp_version(ofp_version); if (!protocol) {