From aa78de9dcb0cdd34cc57358fe236c563006eeb74 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Tue, 17 Nov 2009 16:02:38 -0800 Subject: [PATCH] ovsdb-server: Add "exit" unixctl command and --unixctl option. This makes writing predictable test scripts easier. --- ovsdb/ovsdb-server.c | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/ovsdb/ovsdb-server.c b/ovsdb/ovsdb-server.c index 3dc59928..f6308136 100644 --- a/ovsdb/ovsdb-server.c +++ b/ovsdb/ovsdb-server.c @@ -46,13 +46,17 @@ static const struct jsonrpc_server_cbs ovsdb_jsonrpc_cbs; +static unixctl_cb_func ovsdb_server_exit; + static void parse_options(int argc, char *argv[], char **file_namep, - struct svec *active, struct svec *passive); + struct svec *active, struct svec *passive, + char **unixctl_pathp); static void usage(void) NO_RETURN; int main(int argc, char *argv[]) { + char *unixctl_path = NULL; struct unixctl_server *unixctl; struct ovsdb_jsonrpc_server *jsonrpc; struct svec active, passive; @@ -61,6 +65,7 @@ main(int argc, char *argv[]) const char *name; char *file_name; bool do_chdir; + bool exiting; int retval; size_t i; @@ -71,7 +76,7 @@ main(int argc, char *argv[]) signal(SIGPIPE, SIG_IGN); process_init(); - parse_options(argc, argv, &file_name, &active, &passive); + parse_options(argc, argv, &file_name, &active, &passive, &unixctl_path); if (get_detach() && is_chdir_enabled()) { /* We need to skip chdir("/") in daemonize() and do it later, because @@ -105,15 +110,19 @@ main(int argc, char *argv[]) svec_destroy(&active); svec_destroy(&passive); - retval = unixctl_server_create(NULL, &unixctl); + retval = unixctl_server_create(unixctl_path, &unixctl); if (retval) { ovs_fatal(retval, "could not listen for control connections"); } + unixctl_command_register("exit", ovsdb_server_exit, &exiting); + if (do_chdir) { chdir("/"); } - for (;;) { + + exiting = false; + while (!exiting) { ovsdb_jsonrpc_server_run(jsonrpc); unixctl_server_run(unixctl); ovsdb_trigger_run(db, time_msec()); @@ -127,20 +136,32 @@ main(int argc, char *argv[]) return 0; } +static void +ovsdb_server_exit(struct unixctl_conn *conn, const char *args UNUSED, + void *exiting_) +{ + bool *exiting = exiting_; + *exiting = true; + unixctl_command_reply(conn, 200, NULL); +} + static void parse_options(int argc, char *argv[], char **file_namep, - struct svec *active, struct svec *passive) + struct svec *active, struct svec *passive, + char **unixctl_pathp) { enum { OPT_DUMMY = UCHAR_MAX + 1, OPT_CONNECT, OPT_LISTEN, + OPT_UNIXCTL, VLOG_OPTION_ENUMS, LEAK_CHECKER_OPTION_ENUMS }; static struct option long_options[] = { {"connect", required_argument, 0, OPT_CONNECT}, {"listen", required_argument, 0, OPT_LISTEN}, + {"unixctl", required_argument, 0, OPT_UNIXCTL}, {"help", no_argument, 0, 'h'}, {"version", no_argument, 0, 'V'}, DAEMON_LONG_OPTIONS, @@ -169,6 +190,10 @@ parse_options(int argc, char *argv[], char **file_namep, svec_add(passive, optarg); break; + case OPT_UNIXCTL: + *unixctl_pathp = optarg; + break; + case 'h': usage(); -- 2.30.2