X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Funixctl.c;h=7cc7e5e234a6ee4e45d79ededbf8e150c488d68a;hb=69ebca1e35a39d75032f3d8092da563f60673110;hp=c333c54e9eb5b8ce4971960e9e6e31ac57437cf9;hpb=fe1e967e3bc6c04f773b150fbb358b2350d0ad8c;p=openvswitch diff --git a/lib/unixctl.c b/lib/unixctl.c index c333c54e..7cc7e5e2 100644 --- a/lib/unixctl.c +++ b/lib/unixctl.c @@ -48,6 +48,7 @@ COVERAGE_DEFINE(unixctl_received); COVERAGE_DEFINE(unixctl_replied); struct unixctl_command { + const char *args; unixctl_cb_func *cb; void *aux; }; @@ -85,36 +86,40 @@ unixctl_help(struct unixctl_conn *conn, const char *args OVS_UNUSED, void *aux OVS_UNUSED) { struct ds ds = DS_EMPTY_INITIALIZER; - struct shash_node *node; - struct svec names; - const char *name; + const struct shash_node **nodes = shash_sort(&commands); size_t i; ds_put_cstr(&ds, "The available commands are:\n"); - svec_init(&names); - SHASH_FOR_EACH (node, &commands) { - svec_add(&names, node->name); + for (i = 0; i < shash_count(&commands); i++) { + const struct shash_node *node = nodes[i]; + const struct unixctl_command *command = node->data; + + ds_put_format(&ds, " %-23s%s\n", node->name, command->args); } - svec_sort(&names); - - SVEC_FOR_EACH (i, name, &names) { - ds_put_format(&ds, "\t%s\n", name); - } - svec_destroy(&names); + free(nodes); unixctl_command_reply(conn, 214, ds_cstr(&ds)); ds_destroy(&ds); } +static void +unixctl_version(struct unixctl_conn *conn, const char *args OVS_UNUSED, + void *aux OVS_UNUSED) +{ + unixctl_command_reply(conn, 200, get_program_version()); +} + void -unixctl_command_register(const char *name, unixctl_cb_func *cb, void *aux) +unixctl_command_register(const char *name, const char *args, + unixctl_cb_func *cb, void *aux) { struct unixctl_command *command; assert(!shash_find_data(&commands, name) || shash_find_data(&commands, name) == cb); command = xmalloc(sizeof *command); + command->args = args; command->cb = cb; command->aux = aux; shash_add(&commands, name, command); @@ -205,7 +210,8 @@ unixctl_server_create(const char *path, struct unixctl_server **serverp) return 0; } - unixctl_command_register("help", unixctl_help, NULL); + unixctl_command_register("help", "", unixctl_help, NULL); + unixctl_command_register("version", "", unixctl_version, NULL); server = xmalloc(sizeof *server); list_init(&server->conns);