X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Funixctl.c;h=d75166fe424117c0a5d3703c6223a0bc1cfb3343;hb=268a95e009c4cc57e967e88f916932fac89fdf1c;hp=161374e0faa37ab4b80ac7ab961e940f71231987;hpb=b43c6fe279a5630dfbc0273e06bd1e8ca530ba35;p=openvswitch diff --git a/lib/unixctl.c b/lib/unixctl.c index 161374e0..d75166fe 100644 --- a/lib/unixctl.c +++ b/lib/unixctl.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2009, 2010 Nicira Networks. + * Copyright (c) 2008, 2009, 2010, 2011 Nicira Networks. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -43,8 +43,12 @@ #endif VLOG_DEFINE_THIS_MODULE(unixctl); + +COVERAGE_DEFINE(unixctl_received); +COVERAGE_DEFINE(unixctl_replied); struct unixctl_command { + const char *args; unixctl_cb_func *cb; void *aux; }; @@ -82,36 +86,45 @@ 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); - } - svec_sort(&names); - - SVEC_FOR_EACH (i, name, &names) { - ds_put_format(&ds, "\t%s\n", 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_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; + struct unixctl_command *lookup = shash_find_data(&commands, name); + + assert(!lookup || lookup->cb == cb); + + if (lookup) { + return; + } - 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); @@ -202,7 +215,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); @@ -565,8 +579,7 @@ unixctl_client_transact(struct unixctl_client *client, if (error) { VLOG_WARN("error reading reply from %s: %s", client->connect_path, - (error == EOF ? "unexpected end of file" - : strerror(error))); + ovs_retval_to_string(error)); goto error; }