return server;
}
-int
-ovsdb_jsonrpc_server_listen(struct ovsdb_jsonrpc_server *svr, const char *name)
+void
+ovsdb_jsonrpc_server_listen(struct ovsdb_jsonrpc_server *svr,
+ struct pstream *pstream)
{
- struct pstream *pstream;
- int error;
-
- error = pstream_open(name, &pstream);
- if (error) {
- return error;
- }
-
if (svr->n_listeners >= svr->allocated_listeners) {
svr->listeners = x2nrealloc(svr->listeners, &svr->allocated_listeners,
sizeof *svr->listeners);
}
svr->listeners[svr->n_listeners++] = pstream;
- return 0;
}
void
#define OVSDB_JSONRPC_SERVER_H 1
struct ovsdb;
+struct pstream;
struct ovsdb_jsonrpc_server *ovsdb_jsonrpc_server_create(struct ovsdb *);
-int ovsdb_jsonrpc_server_listen(struct ovsdb_jsonrpc_server *,
- const char *name);
+void ovsdb_jsonrpc_server_listen(struct ovsdb_jsonrpc_server *,
+ struct pstream *);
void ovsdb_jsonrpc_server_connect(struct ovsdb_jsonrpc_server *,
const char *name);
struct unixctl_server *unixctl;
struct ovsdb_jsonrpc_server *jsonrpc;
struct svec active, passive;
+ struct pstream **listeners;
struct ovsdb_error *error;
struct ovsdb *db;
const char *name;
parse_options(argc, argv, &file_name, &active, &passive, &unixctl_path);
+ /* Open all the passive sockets before detaching, to avoid race with
+ * processes that start up later. */
+ listeners = xmalloc(passive.n * sizeof *listeners);
+ for (i = 0; i < passive.n; i++) {
+ int error;
+
+ error = pstream_open(passive.names[i], &listeners[i]);
+ if (error) {
+ ovs_fatal(error, "failed to listen on \"%s\"", passive.names[i]);
+ }
+ }
+
if (get_detach() && is_chdir_enabled()) {
/* We need to skip chdir("/") in daemonize() and do it later, because
* we need to open the database and possible set up up Unix domain
SVEC_FOR_EACH (i, name, &active) {
ovsdb_jsonrpc_server_connect(jsonrpc, name);
}
- SVEC_FOR_EACH (i, name, &passive) {
- retval = ovsdb_jsonrpc_server_listen(jsonrpc, name);
- if (retval) {
- ovs_fatal(retval, "failed to listen on %s", name);
- }
+ for (i = 0; i < passive.n; i++) {
+ ovsdb_jsonrpc_server_listen(jsonrpc, listeners[i]);
}
svec_destroy(&active);
svec_destroy(&passive);