1 /* Copyright (c) 2008, 2009 Nicira Networks
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
28 #include "command-line.h"
33 #include "leak-checker.h"
36 #include "ovs-vswitchd.h"
37 #include "poll-loop.h"
38 #include "proc-net-compat.h"
45 #include "vconn-ssl.h"
49 #define THIS_MODULE VLM_vswitchd
51 static void parse_options(int argc
, char *argv
[]);
52 static void usage(void) NO_RETURN
;
53 static void reload(struct unixctl_conn
*, const char *args
);
55 static bool need_reconfigure
;
56 static struct unixctl_conn
**conns
;
57 static size_t n_conns
;
60 main(int argc
, char *argv
[])
62 struct unixctl_server
*unixctl
;
63 struct signal
*sighup
;
66 set_program_name(argv
[0]);
67 register_fault_handlers();
70 parse_options(argc
, argv
);
71 signal(SIGPIPE
, SIG_IGN
);
72 sighup
= signal_register(SIGHUP
);
75 die_if_already_running();
78 retval
= unixctl_server_create(NULL
, &unixctl
);
80 ovs_fatal(retval
, "could not listen for control connections");
82 unixctl_command_register("vswitchd/reload", reload
);
89 need_reconfigure
= false;
91 if (need_reconfigure
|| signal_poll(sighup
)) {
92 need_reconfigure
= false;
93 vlog_reopen_log_file();
97 need_reconfigure
= true;
100 need_reconfigure
= true;
102 unixctl_server_run(unixctl
);
106 if (need_reconfigure
) {
107 poll_immediate_wake();
112 unixctl_server_wait(unixctl
);
122 reload(struct unixctl_conn
*conn
, const char *args UNUSED
)
124 need_reconfigure
= true;
125 conns
= xrealloc(conns
, sizeof *conns
* (n_conns
+ 1));
126 conns
[n_conns
++] = conn
;
135 bridge_reconfigure();
138 for (i
= 0; i
< n_conns
; i
++) {
139 unixctl_command_reply(conns
[i
], 202, NULL
);
147 parse_options(int argc
, char *argv
[])
150 OPT_PEER_CA_CERT
= UCHAR_MAX
+ 1,
153 LEAK_CHECKER_OPTION_ENUMS
155 static struct option long_options
[] = {
156 {"help", no_argument
, 0, 'h'},
157 {"version", no_argument
, 0, 'V'},
158 {"fake-proc-net", no_argument
, 0, OPT_FAKE_PROC_NET
},
161 LEAK_CHECKER_LONG_OPTIONS
,
163 VCONN_SSL_LONG_OPTIONS
164 {"peer-ca-cert", required_argument
, 0, OPT_PEER_CA_CERT
},
168 char *short_options
= long_options_to_short_options(long_options
);
169 const char *config_file
;
175 c
= getopt_long(argc
, argv
, short_options
, long_options
, NULL
);
186 OVS_PRINT_VERSION(OFP_VERSION
, OFP_VERSION
);
189 case OPT_FAKE_PROC_NET
:
190 error
= proc_net_compat_init();
192 ovs_fatal(error
, "failed to initialize /proc/net "
198 DAEMON_OPTION_HANDLERS
199 VCONN_SSL_OPTION_HANDLERS
200 LEAK_CHECKER_OPTION_HANDLERS
203 case OPT_PEER_CA_CERT
:
204 vconn_ssl_set_peer_ca_cert_file(optarg
);
221 ovs_fatal(0, "config file is only non-option argument; "
222 "use --help for usage");
225 config_file
= argv
[0];
226 error
= cfg_set_file(config_file
);
228 ovs_fatal(error
, "failed to add configuration file \"%s\"",
236 printf("%s: Open vSwitch daemon\n"
237 "usage: %s [OPTIONS] CONFIG\n"
238 "CONFIG is a configuration file in ovs-vswitchd.conf(5) format.\n",
239 program_name
, program_name
);
242 printf("\nLegacy compatibility options:\n"
243 " --fake-proc-net simulate some files in /proc/net\n"
245 " -h, --help display this help message\n"
246 " -V, --version display version information\n");
247 leak_checker_usage();