ovs-appctl: Add "version" command to print version of running daemons.
[sliver-openvswitch.git] / lib / unixctl.c
index e10de49..ca90b39 100644 (file)
@@ -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,6 +43,9 @@
 #endif
 
 VLOG_DEFINE_THIS_MODULE(unixctl);
+
+COVERAGE_DEFINE(unixctl_received);
+COVERAGE_DEFINE(unixctl_replied);
 \f
 struct unixctl_command {
     unixctl_cb_func *cb;
@@ -104,6 +107,13 @@ unixctl_help(struct unixctl_conn *conn, const char *args OVS_UNUSED,
     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)
 {
@@ -203,14 +213,15 @@ unixctl_server_create(const char *path, struct unixctl_server **serverp)
     }
 
     unixctl_command_register("help", unixctl_help, NULL);
+    unixctl_command_register("version", unixctl_version, NULL);
 
     server = xmalloc(sizeof *server);
     list_init(&server->conns);
 
     if (path) {
-        server->path = abs_file_name(ovs_rundir, path);
+        server->path = abs_file_name(ovs_rundir(), path);
     } else {
-        server->path = xasprintf("%s/%s.%ld.ctl", ovs_rundir,
+        server->path = xasprintf("%s/%s.%ld.ctl", ovs_rundir(),
                                  program_name, (long int) getpid());
     }
 
@@ -471,7 +482,7 @@ unixctl_server_destroy(struct unixctl_server *server)
 \f
 /* Connects to a Vlog server socket.  'path' should be the name of a Vlog
  * server socket.  If it does not start with '/', it will be prefixed with
- * ovs_rundir (e.g. /var/run/openvswitch).
+ * the rundir (e.g. /usr/local/var/run/openvswitch).
  *
  * Returns 0 if successful, otherwise a positive errno value.  If successful,
  * sets '*clientp' to the new unixctl_client, otherwise to NULL. */
@@ -485,7 +496,7 @@ unixctl_client_create(const char *path, struct unixctl_client **clientp)
 
     /* Determine location. */
     client = xmalloc(sizeof *client);
-    client->connect_path = abs_file_name(ovs_rundir, path);
+    client->connect_path = abs_file_name(ovs_rundir(), path);
     client->bind_path = xasprintf("/tmp/vlog.%ld.%d",
                                   (long int) getpid(), counter++);
 
@@ -565,8 +576,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;
         }