summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Hemminger <stephen@networkplumber.org>2013-07-16 10:04:05 -0700
committerStephen Hemminger <stephen@networkplumber.org>2013-07-16 10:04:05 -0700
commita3aa47a559f3f23a9e054e2b75adc7d9eb7fe6cc (patch)
treeb373ff039c772d108db1a0f4137c679da75a5f2c
parent09154ec15f0f37b8af29409d16144c88bd8b3526 (diff)
Make tc and ip batch mode consistent
Change the code for tc and ip so that batch mode is handled the same.
-rw-r--r--include/utils.h1
-rw-r--r--ip/ip.c5
-rw-r--r--ip/ipnetns.c4
-rw-r--r--tc/tc.c15
4 files changed, 14 insertions, 11 deletions
diff --git a/include/utils.h b/include/utils.h
index 2bd8c623..24ff19f8 100644
--- a/include/utils.h
+++ b/include/utils.h
@@ -19,6 +19,7 @@ extern int oneline;
extern int timestamp;
extern char * _SL_;
extern int max_flush_loops;
+extern int batch_mode;
#ifndef IPPROTO_ESP
#define IPPROTO_ESP 50
diff --git a/ip/ip.c b/ip/ip.c
index 69bd5ffb..86f8b455 100644
--- a/ip/ip.c
+++ b/ip/ip.c
@@ -30,9 +30,9 @@ int resolve_hosts = 0;
int oneline = 0;
int timestamp = 0;
char * _SL_ = NULL;
-char *batch_file = NULL;
int force = 0;
int max_flush_loops = 10;
+int batch_mode = 0;
struct rtnl_handle rth = { .fd = -1 };
@@ -113,6 +113,8 @@ static int batch(const char *name)
size_t len = 0;
int ret = EXIT_SUCCESS;
+ batch_mode = 1;
+
if (name && strcmp(name, "-") != 0) {
if (freopen(name, "r", stdin) == NULL) {
fprintf(stderr, "Cannot open file \"%s\" for reading: %s\n",
@@ -153,6 +155,7 @@ static int batch(const char *name)
int main(int argc, char **argv)
{
char *basename;
+ char *batch_file = NULL;
basename = strrchr(argv[0], '/');
if (basename == NULL)
diff --git a/ip/ipnetns.c b/ip/ipnetns.c
index 5b911f76..794a4988 100644
--- a/ip/ipnetns.c
+++ b/ip/ipnetns.c
@@ -42,8 +42,6 @@
#define MS_SHARED (1 << 20)
#endif
-extern char *batch_file;
-
#ifndef HAVE_SETNS
static int setns(int fd, int nstype)
{
@@ -190,7 +188,7 @@ static int netns_exec(int argc, char **argv)
fflush(stdout);
- if (batch_file) {
+ if (batch_mode) {
int status;
pid_t pid;
diff --git a/tc/tc.c b/tc/tc.c
index 8e362d28..9b50e747 100644
--- a/tc/tc.c
+++ b/tc/tc.c
@@ -34,6 +34,7 @@ int show_stats = 0;
int show_details = 0;
int show_raw = 0;
int show_pretty = 0;
+int batch_mode = 0;
int resolve_hosts = 0;
int use_iec = 0;
@@ -220,6 +221,7 @@ static int batch(const char *name)
size_t len = 0;
int ret = 0;
+ batch_mode = 1;
if (name && strcmp(name, "-") != 0) {
if (freopen(name, "r", stdin) == NULL) {
fprintf(stderr, "Cannot open file \"%s\" for reading: %s\n",
@@ -262,8 +264,7 @@ static int batch(const char *name)
int main(int argc, char **argv)
{
int ret;
- int do_batching = 0;
- char *batchfile = NULL;
+ char *batch_file = NULL;
while (argc > 1) {
if (argv[1][0] != '-')
@@ -288,10 +289,10 @@ int main(int argc, char **argv)
} else if (matches(argv[1], "-force") == 0) {
++force;
} else if (matches(argv[1], "-batch") == 0) {
- do_batching = 1;
- if (argc > 2)
- batchfile = argv[2];
argc--; argv++;
+ if (argc <= 1)
+ usage();
+ batch_file = argv[1];
} else {
fprintf(stderr, "Option \"%s\" is unknown, try \"tc -help\".\n", argv[1]);
return -1;
@@ -299,8 +300,8 @@ int main(int argc, char **argv)
argc--; argv++;
}
- if (do_batching)
- return batch(batchfile);
+ if (batch_file)
+ return batch(batch_file);
if (argc <= 1) {
usage();