[ovs-dev] [PATCH 2/2] ovs-appctl: Support the daemon name as a target

Justin Pettit jpettit at nicira.com
Thu Sep 17 00:33:35 UTC 2009


It can be inconvenient to be required to type the entire path of the
Unix daemon socket as a target.  This commit allows the name of the
daemon to be used instead, when a pidfile for the daemon exists in the
default location.
---
 utilities/ovs-appctl.8.in |   19 +++++++++++++++----
 utilities/ovs-appctl.c    |   24 +++++++++++++++++++++++-
 2 files changed, 38 insertions(+), 5 deletions(-)

diff --git a/utilities/ovs-appctl.8.in b/utilities/ovs-appctl.8.in
index 88fb295..a763bc3 100644
--- a/utilities/ovs-appctl.8.in
+++ b/utilities/ovs-appctl.8.in
@@ -16,6 +16,7 @@ ovs\-appctl \- utility for configuring running Open vSwitch daemons
 The available \fItarget\fR options are:
 .br
 [\fB-t\fR \fIsocket\fR | \fB--target=\fIsocket\fR]
+[\fB-d\fR \fIdaemon\fR | \fB--daemon=\fIdaemon\fR]
 .sp 1
 The available \fIaction\fR options are:
 .br
@@ -29,7 +30,6 @@ The available \fIaction\fR options are:
 The \fBovs\-appctl\fR program connects to one or more running
 Open vSwitch daemons (such as \fBovs\-vswitchd\fR(8)), as specified by the
 user, and sends them commands to query or modify their behavior.
-Its primary purpose is currently to adjust daemons' logging levels.
 
 \fBovs\-appctl\fR applies one or more actions to each of one or more
 target processes.  Targets may be specified using:
@@ -37,14 +37,25 @@ target processes.  Targets may be specified using:
 .IP "\fB-t \fIsocket\fR"
 .IQ "\fB--target=\fIsocket\fR"
 The specified \fIsocket\fR must be the name of a Unix domain socket
-for a \fBovs\-appctl\fR-controllable process.  If \fIsocket\fR does not
+for an \fBovs\-appctl\fR-controllable process.  If \fIsocket\fR does not
 begin with \fB/\fR, it is treated as relative to \fB at RUNDIR@\fR.
 
 Each Open vSwitch daemon by default creates a socket named
-\fB at RUNDIR@/\fIprogram\fB.\fIpid\fB.ctl\fR, where \fIprogram\fR is
-the program's name (such as \fBovs\-vswitchd\fR) and \fIpid\fR is the
+\fB at RUNDIR@/\fIdaemon\fB.\fIpid\fB.ctl\fR, where \fIdaemon\fR is
+the daemon's name (such as \fBovs\-vswitchd\fR) and \fIpid\fR is the
 daemon's PID.
 
+.IP "\fB-d \fIdaemon\fR"
+.IQ "\fB--daemon=\fIdaemon\fR"
+The specified \fIdaemon\fR is the name of a running
+\fBovs\-appctl\fR-controllable process.  A pidfile for the daemon must 
+exist in \fB at RUNDIR@/\fIdaemon\fB.pid\fR, which is the default behavior 
+when starting a daemon with an unadourned \fB--pidfile\fR option.  
+\fBovs\-appctl\fR will use the value from the pidfile to control the 
+daemon with the Unix domain socket in
+\fB at RUNDIR@/\fIdaemon\fB.\fIpid\fB.ctl\fR, where \fIdaemon\fR is the
+given argument and \fIpid\fR is the value from the pidfile.
+
 .PP
 The available actions are:
 
diff --git a/utilities/ovs-appctl.c b/utilities/ovs-appctl.c
index 9349662..0533b92 100644
--- a/utilities/ovs-appctl.c
+++ b/utilities/ovs-appctl.c
@@ -26,6 +26,8 @@
 
 #include "command-line.h"
 #include "compiler.h"
+#include "daemon.h"
+#include "dirs.h"
 #include "timeval.h"
 #include "unixctl.h"
 #include "util.h"
@@ -36,6 +38,7 @@ usage(char *prog_name, int exit_code)
     printf("Usage: %s [TARGET] [ACTION...]\n"
            "Targets:\n"
            "  -t, --target=TARGET  Path to Unix domain socket\n"
+           "  -d, --daemon=DAEMON  Name of daemon\n"
            "Actions:\n"
            "  -l, --list         List current settings\n"
            "  -s, --set=MODULE[:FACILITY[:LEVEL]]\n"
@@ -122,6 +125,7 @@ int main(int argc, char *argv[])
     static const struct option long_options[] = {
         /* Target options must come first. */
         {"target", required_argument, NULL, 't'},
+        {"daemon", required_argument, NULL, 'd'},
         {"help", no_argument, NULL, 'h'},
         {"version", no_argument, NULL, 'V'},
 
@@ -152,7 +156,7 @@ int main(int argc, char *argv[])
         if (option == -1) {
             break;
         }
-        if (!strchr("thV", option) && n_clients == 0) {
+        if (!strchr("tdhV", option) && n_clients == 0) {
             ovs_fatal(0, "no targets specified (use --help for help)");
         } else {
             ++n_actions;
@@ -162,6 +166,24 @@ int main(int argc, char *argv[])
             add_target(&clients, &n_clients, optarg, &ok);
             break;
 
+        case 'd': {
+            char *pidfile = NULL;
+            pid_t pid;
+
+            pidfile = xasprintf("%s/%s.pid", ovs_rundir, optarg);
+            pid = read_pidfile(pidfile);
+            if (pid >= 0) {
+                char *sock_name = xasprintf("%s/%s.%ld.ctl", ovs_rundir,
+                                            optarg, (long int) pid);
+                add_target(&clients, &n_clients, sock_name, &ok);
+                free(sock_name);
+            } else {
+                ovs_fatal(0, "could not read %s", pidfile);
+            }
+            free(pidfile);
+            break;
+        }
+
         case 'l':
             for (i = 0; i < n_clients; i++) {
                 struct unixctl_client *client = clients[i];
-- 
1.6.4





More information about the dev mailing list