]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
Make tc and ip batch mode consistent
authorStephen Hemminger <stephen@networkplumber.org>
Tue, 16 Jul 2013 17:04:05 +0000 (10:04 -0700)
committerStephen Hemminger <stephen@networkplumber.org>
Tue, 16 Jul 2013 17:04:05 +0000 (10:04 -0700)
Change the code for tc and ip so that batch mode is handled
the same.

include/utils.h
ip/ip.c
ip/ipnetns.c
tc/tc.c

index 2bd8c623b0f82b5cd246693d2736302d50c317a8..24ff19f80530ab5804e58d3a4fb23998d727214c 100644 (file)
@@ -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 69bd5ffb93a5bf9d2d9dec1d70cbd6d464a82e59..86f8b455cf34fc21287d4e94bd2e25e82db4050c 100644 (file)
--- 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)
index 5b911f76d18e404aa5394fcfe741521afd820620..794a4988084274f339b7e98d58432938ac868734 100644 (file)
@@ -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 8e362d285d0cda1d5cc24f3a3e9052d6e2cac222..9b50e7474769affc0f297198b1fcbf6bd8a09d1a 100644 (file)
--- 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();