timeval: Make time_init() static and remove calls to it.
[sliver-openvswitch.git] / extras / ezio / ovs-switchui.c
index 0f6640e..ea47704 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2008, 2009 Nicira Networks, Inc.
+/* Copyright (c) 2008, 2009, 2010 Nicira Networks, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -35,6 +35,7 @@
 #include "ezio.h"
 #include "fatal-signal.h"
 #include "netdev.h"
+#include "ofp-util.h"
 #include "ofpbuf.h"
 #include "openflow/nicira-ext.h"
 #include "openflow/openflow.h"
@@ -144,8 +145,8 @@ main(int argc, char *argv[])
     long long int last_key_time = 0;
     int repeat_count = 0;
 
+    proctitle_init(argc, argv);
     set_program_name(argv[0]);
-    time_init();
     vlog_init();
     parse_options(argc, argv);
     signal(SIGPIPE, SIG_IGN);
@@ -159,13 +160,14 @@ main(int argc, char *argv[])
                   "use --help for help");
     }
 
-    rconn = rconn_new(argv[0], 5, 5);
+    rconn = rconn_create(5, 5);
+    rconn_connect(rconn, argv[0], NULL);
 
     die_if_already_running();
     daemonize();
 
     initialize_terminal();
-    fatal_signal_add_hook(restore_terminal, NULL, true);
+    fatal_signal_add_hook(restore_terminal, NULL, NULL, true);
 
     msg = NULL;
     countdown = 0;
@@ -241,7 +243,7 @@ main(int argc, char *argv[])
             refresh();
 
             poll_fd_wait(STDIN_FILENO, POLLIN);
-            poll_timer_wait(timeout - time_msec());
+            poll_timer_wait_until(timeout);
             poll_block();
         } while (time_msec() < timeout);
         age_messages();
@@ -867,7 +869,7 @@ fetch_status(struct rconn *rconn, struct dict *dict, long long timeout)
 
         rconn_run_wait(rconn);
         rconn_recv_wait(rconn);
-        poll_timer_wait(timeout - time_msec());
+        poll_timer_wait_until(timeout);
         poll_block();
     }
 }
@@ -995,7 +997,7 @@ initialize_terminal(void)
 }
 
 static void
-restore_terminal(void *aux UNUSED)
+restore_terminal(void *aux OVS_UNUSED)
 {
     endwin();
 }
@@ -1104,6 +1106,7 @@ do_show_data_rates(void *rates_)
     }
     if (!rates->xid) {
         struct ofp_stats_request *rq;
+        struct ofp_port_stats_request *psr;
         struct ofpbuf *b;
 
         rates->xid = random_uint32();
@@ -1111,6 +1114,10 @@ do_show_data_rates(void *rates_)
                                rates->xid, &b);
         rq->type = htons(OFPST_PORT);
         rq->flags = htons(0);
+        psr = ofpbuf_put_uninit(b, sizeof *psr);
+        memset(psr, 0, sizeof *psr);
+        psr->port_no = htons(OFPP_NONE);
+        update_openflow_length(b);
         rconn_send_with_limit(rates->rconn, b, counter, 10);
     }
 
@@ -1247,7 +1254,7 @@ allocate_message(struct message **msgp)
 {
     if (!*msgp) {
         /* Allocate and initialize message. */
-        *msgp = xcalloc(1, sizeof **msgp);
+        *msgp = xzalloc(sizeof **msgp);
         (*msgp)->index = n_messages;
 
         /* Add to list of messages. */
@@ -1444,7 +1451,7 @@ init_reboot_notifier(void)
 }
 
 static void
-sigusr1_handler(int signr UNUSED)
+sigusr1_handler(int signr OVS_UNUSED)
 {
     sigusr1_triggered = true;
 }
@@ -1486,7 +1493,7 @@ static int menu_show(const struct menu *, int start, bool select);
 static void cmd_shell(const struct dict *);
 static void cmd_show_version(const struct dict *);
 static void cmd_configure(const struct dict *);
-static void cmd_setup_pki(const struct dict *);
+static void cmd_set_up_pki(const struct dict *);
 static void cmd_browse_status(const struct dict *);
 static void cmd_show_motto(const struct dict *);
 
@@ -1542,7 +1549,7 @@ menu(const struct dict *dict)
     menu_add_item(&menu, "Exit");
     menu_add_item(&menu, "Show Version")->f = cmd_show_version;
     menu_add_item(&menu, "Configure")->f = cmd_configure;
-    menu_add_item(&menu, "Setup PKI")->f = cmd_setup_pki;
+    menu_add_item(&menu, "Set up PKI")->f = cmd_set_up_pki;
     if (debug_mode) {
         menu_add_item(&menu, "Browse Status")->f = cmd_browse_status;
         menu_add_item(&menu, "Shell")->f = cmd_shell;
@@ -1708,7 +1715,7 @@ menu_show(const struct menu *menu, int start, bool select)
         refresh();
 
         if (pos < min || pos > max) {
-            poll_timer_wait(adjust - time_msec());
+            poll_timer_wait_until(adjust);
         }
         poll_fd_wait(STDIN_FILENO, POLLIN);
         poll_block();
@@ -1874,7 +1881,7 @@ yesno(const char *title, bool def)
 }
 
 static void
-cmd_show_version(const struct dict *dict UNUSED)
+cmd_show_version(const struct dict *dict OVS_UNUSED)
 {
     show_string(VERSION BUILDNR);
 }
@@ -1895,7 +1902,7 @@ cmd_browse_status(const struct dict *dict)
 }
 
 static void
-cmd_shell(const struct dict *dict UNUSED)
+cmd_shell(const struct dict *dict OVS_UNUSED)
 {
     const char *home;
 
@@ -1919,7 +1926,7 @@ cmd_shell(const struct dict *dict UNUSED)
 }
 
 static void
-cmd_show_motto(const struct dict *dict UNUSED)
+cmd_show_motto(const struct dict *dict OVS_UNUSED)
 {
     show_string("\"Just Add Ice\"");
 }
@@ -1940,7 +1947,7 @@ static void
 block_until(long long timeout)
 {
     while (timeout > time_msec()) {
-        poll_timer_wait(timeout - time_msec());
+        poll_timer_wait_until(timeout);
         poll_block();
     }
     drain_keyboard_buffer();
@@ -2079,7 +2086,7 @@ save_config(const struct svec *settings)
     }
 
     svec_init(&argv);
-    svec_add(&argv, "/usr/share/openvswitch/commands/reconfigure");
+    svec_add(&argv, "/usr/share/openvswitch-switchui/reconfigure");
     svec_append(&argv, settings);
     svec_terminate(&argv);
     ok = run_and_report_failure(argv.names, "Save failed");
@@ -2457,7 +2464,7 @@ abbreviate_netdevs(const struct svec *netdevs, struct ds *abbrev)
 static void
 choose_netdevs(struct svec *choices)
 {
-    struct svec netdevs;
+    struct svec netdevs = SVEC_EMPTY_INITIALIZER;
     struct menu menu;
     size_t i;
 
@@ -2478,7 +2485,7 @@ choose_netdevs(struct svec *choices)
             continue;
         }
 
-        retval = netdev_open(name, NETDEV_ETH_TYPE_NONE, &netdev);
+        retval = netdev_open_default(name, &netdev);
         if (!retval) {
             bool exclude = netdev_get_in4(netdev, NULL, NULL) == 0;
             netdev_close(netdev);
@@ -2547,7 +2554,7 @@ disconnected_string(int value)
 }
 
 static void
-cmd_configure(const struct dict *dict UNUSED)
+cmd_configure(const struct dict *dict OVS_UNUSED)
 {
     bool debug_mode = dict_get_bool(dict, "debug", false);
     struct dict config_dict;
@@ -2889,7 +2896,7 @@ cmd_configure(const struct dict *dict UNUSED)
 }
 
 static void
-cmd_setup_pki(const struct dict *dict UNUSED)
+cmd_set_up_pki(const struct dict *dict OVS_UNUSED)
 {
     static const char def_privkey_file[]
         = "/etc/openflow-switch/of0-privkey.pem";