git://git.onelab.eu
/
sliver-openvswitch.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
ofproto-dpif-monitor: Fix deadlock.
[sliver-openvswitch.git]
/
utilities
/
ovs-appctl.c
diff --git
a/utilities/ovs-appctl.c
b/utilities/ovs-appctl.c
index
ebfd54a
..
a6fbebd
100644
(file)
--- a/
utilities/ovs-appctl.c
+++ b/
utilities/ovs-appctl.c
@@
-1,5
+1,5
@@
/*
/*
- * Copyright (c) 2008, 2009, 2010, 2011, 2012 Nicira
Networks
.
+ * Copyright (c) 2008, 2009, 2010, 2011, 2012 Nicira
, Inc
.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@
-26,6
+26,7
@@
#include "daemon.h"
#include "dirs.h"
#include "dynamic-string.h"
#include "daemon.h"
#include "dirs.h"
#include "dynamic-string.h"
+#include "jsonrpc.h"
#include "process.h"
#include "timeval.h"
#include "unixctl.h"
#include "process.h"
#include "timeval.h"
#include "unixctl.h"
@@
-33,16
+34,17
@@
static void usage(void);
static const char *parse_command_line(int argc, char *argv[]);
static void usage(void);
static const char *parse_command_line(int argc, char *argv[]);
-static struct
unixctl_client
*connect_to_target(const char *target);
+static struct
jsonrpc
*connect_to_target(const char *target);
int
main(int argc, char *argv[])
{
int
main(int argc, char *argv[])
{
- struct unixctl_client *client;
+ char *cmd_result, *cmd_error;
+ struct jsonrpc *client;
+ char *cmd, **cmd_argv;
const char *target;
const char *target;
- int code, error;
- char *request;
- char *reply;
+ int cmd_argc;
+ int error;
set_program_name(argv[0]);
set_program_name(argv[0]);
@@
-51,22
+53,29
@@
main(int argc, char *argv[])
client = connect_to_target(target);
/* Transact request and process reply. */
client = connect_to_target(target);
/* Transact request and process reply. */
- request = process_escape_args(argv + optind);
- error = unixctl_client_transact(client, request, &code, &reply);
- free(request);
+ cmd = argv[optind++];
+ cmd_argc = argc - optind;
+ cmd_argv = cmd_argc ? argv + optind : NULL;
+ error = unixctl_client_transact(client, cmd, cmd_argc, cmd_argv,
+ &cmd_result, &cmd_error);
if (error) {
ovs_fatal(error, "%s: transaction error", target);
}
if (error) {
ovs_fatal(error, "%s: transaction error", target);
}
- if (code / 100 != 2) {
- fputs(reply, stderr);
- ovs_error(0, "%s: server returned reply code %03d", target, code);
+
+ if (cmd_error) {
+ jsonrpc_close(client);
+ fputs(cmd_error, stderr);
+ ovs_error(0, "%s: server returned an error", target);
exit(2);
exit(2);
+ } else if (cmd_result) {
+ fputs(cmd_result, stdout);
+ } else {
+ OVS_NOT_REACHED();
}
}
- fputs(reply, stdout);
-
- unixctl_client_destroy(client);
- free(reply);
+ jsonrpc_close(client);
+ free(cmd_result);
+ free(cmd_error);
return 0;
}
return 0;
}
@@
-89,6
+98,7
@@
Common commands:\n\
'off', 'emer', 'err', 'warn', 'info', or 'dbg' ('dbg', bydefault)\n\
vlog/reopen Make the program reopen its log file\n\
Other options:\n\
'off', 'emer', 'err', 'warn', 'info', or 'dbg' ('dbg', bydefault)\n\
vlog/reopen Make the program reopen its log file\n\
Other options:\n\
+ --timeout=SECS wait at most SECS seconds for a response\n\
-h, --help Print this helpful information\n\
-V, --version Display ovs-appctl version information\n",
program_name, program_name);
-h, --help Print this helpful information\n\
-V, --version Display ovs-appctl version information\n",
program_name, program_name);
@@
-103,6
+113,7
@@
parse_command_line(int argc, char *argv[])
{"execute", no_argument, NULL, 'e'},
{"help", no_argument, NULL, 'h'},
{"version", no_argument, NULL, 'V'},
{"execute", no_argument, NULL, 'e'},
{"help", no_argument, NULL, 'h'},
{"version", no_argument, NULL, 'V'},
+ {"timeout", required_argument, NULL, 'T'},
{NULL, 0, NULL, 0},
};
const char *target;
{NULL, 0, NULL, 0},
};
const char *target;
@@
-139,6
+150,10
@@
parse_command_line(int argc, char *argv[])
usage();
break;
usage();
break;
+ case 'T':
+ time_alarm(atoi(optarg));
+ break;
+
case 'V':
ovs_print_version(0, 0);
exit(EXIT_SUCCESS);
case 'V':
ovs_print_version(0, 0);
exit(EXIT_SUCCESS);
@@
-147,7
+162,7
@@
parse_command_line(int argc, char *argv[])
exit(EXIT_FAILURE);
default:
exit(EXIT_FAILURE);
default:
- NOT_REACHED();
+
OVS_
NOT_REACHED();
}
}
}
}
@@
-159,13
+174,14
@@
parse_command_line(int argc, char *argv[])
return target ? target : "ovs-vswitchd";
}
return target ? target : "ovs-vswitchd";
}
-static struct
unixctl_client
*
+static struct
jsonrpc
*
connect_to_target(const char *target)
{
connect_to_target(const char *target)
{
- struct
unixctl_client
*client;
+ struct
jsonrpc
*client;
char *socket_name;
int error;
char *socket_name;
int error;
+#ifndef _WIN32
if (target[0] != '/') {
char *pidfile_name;
pid_t pid;
if (target[0] != '/') {
char *pidfile_name;
pid_t pid;
@@
-178,6
+194,12
@@
connect_to_target(const char *target)
free(pidfile_name);
socket_name = xasprintf("%s/%s.%ld.ctl",
ovs_rundir(), target, (long int) pid);
free(pidfile_name);
socket_name = xasprintf("%s/%s.%ld.ctl",
ovs_rundir(), target, (long int) pid);
+#else
+ /* On windows, if the 'target' contains ':', we make an assumption that
+ * it is an absolute path. */
+ if (!strchr(target, ':')) {
+ socket_name = xasprintf("%s/%s.ctl", ovs_rundir(), target);
+#endif
} else {
socket_name = xstrdup(target);
}
} else {
socket_name = xstrdup(target);
}