mirror of
https://git.proxmox.com/git/mirror_iproute2
synced 2025-10-05 20:48:07 +00:00
Make tc and ip batch mode consistent
Change the code for tc and ip so that batch mode is handled the same.
This commit is contained in:
parent
09154ec15f
commit
a3aa47a559
@ -19,6 +19,7 @@ extern int oneline;
|
|||||||
extern int timestamp;
|
extern int timestamp;
|
||||||
extern char * _SL_;
|
extern char * _SL_;
|
||||||
extern int max_flush_loops;
|
extern int max_flush_loops;
|
||||||
|
extern int batch_mode;
|
||||||
|
|
||||||
#ifndef IPPROTO_ESP
|
#ifndef IPPROTO_ESP
|
||||||
#define IPPROTO_ESP 50
|
#define IPPROTO_ESP 50
|
||||||
|
5
ip/ip.c
5
ip/ip.c
@ -30,9 +30,9 @@ int resolve_hosts = 0;
|
|||||||
int oneline = 0;
|
int oneline = 0;
|
||||||
int timestamp = 0;
|
int timestamp = 0;
|
||||||
char * _SL_ = NULL;
|
char * _SL_ = NULL;
|
||||||
char *batch_file = NULL;
|
|
||||||
int force = 0;
|
int force = 0;
|
||||||
int max_flush_loops = 10;
|
int max_flush_loops = 10;
|
||||||
|
int batch_mode = 0;
|
||||||
|
|
||||||
struct rtnl_handle rth = { .fd = -1 };
|
struct rtnl_handle rth = { .fd = -1 };
|
||||||
|
|
||||||
@ -113,6 +113,8 @@ static int batch(const char *name)
|
|||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
int ret = EXIT_SUCCESS;
|
int ret = EXIT_SUCCESS;
|
||||||
|
|
||||||
|
batch_mode = 1;
|
||||||
|
|
||||||
if (name && strcmp(name, "-") != 0) {
|
if (name && strcmp(name, "-") != 0) {
|
||||||
if (freopen(name, "r", stdin) == NULL) {
|
if (freopen(name, "r", stdin) == NULL) {
|
||||||
fprintf(stderr, "Cannot open file \"%s\" for reading: %s\n",
|
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)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
char *basename;
|
char *basename;
|
||||||
|
char *batch_file = NULL;
|
||||||
|
|
||||||
basename = strrchr(argv[0], '/');
|
basename = strrchr(argv[0], '/');
|
||||||
if (basename == NULL)
|
if (basename == NULL)
|
||||||
|
@ -42,8 +42,6 @@
|
|||||||
#define MS_SHARED (1 << 20)
|
#define MS_SHARED (1 << 20)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern char *batch_file;
|
|
||||||
|
|
||||||
#ifndef HAVE_SETNS
|
#ifndef HAVE_SETNS
|
||||||
static int setns(int fd, int nstype)
|
static int setns(int fd, int nstype)
|
||||||
{
|
{
|
||||||
@ -190,7 +188,7 @@ static int netns_exec(int argc, char **argv)
|
|||||||
|
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
|
||||||
if (batch_file) {
|
if (batch_mode) {
|
||||||
int status;
|
int status;
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
|
|
||||||
|
15
tc/tc.c
15
tc/tc.c
@ -34,6 +34,7 @@ int show_stats = 0;
|
|||||||
int show_details = 0;
|
int show_details = 0;
|
||||||
int show_raw = 0;
|
int show_raw = 0;
|
||||||
int show_pretty = 0;
|
int show_pretty = 0;
|
||||||
|
int batch_mode = 0;
|
||||||
|
|
||||||
int resolve_hosts = 0;
|
int resolve_hosts = 0;
|
||||||
int use_iec = 0;
|
int use_iec = 0;
|
||||||
@ -220,6 +221,7 @@ static int batch(const char *name)
|
|||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
|
batch_mode = 1;
|
||||||
if (name && strcmp(name, "-") != 0) {
|
if (name && strcmp(name, "-") != 0) {
|
||||||
if (freopen(name, "r", stdin) == NULL) {
|
if (freopen(name, "r", stdin) == NULL) {
|
||||||
fprintf(stderr, "Cannot open file \"%s\" for reading: %s\n",
|
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 main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
int do_batching = 0;
|
char *batch_file = NULL;
|
||||||
char *batchfile = NULL;
|
|
||||||
|
|
||||||
while (argc > 1) {
|
while (argc > 1) {
|
||||||
if (argv[1][0] != '-')
|
if (argv[1][0] != '-')
|
||||||
@ -288,10 +289,10 @@ int main(int argc, char **argv)
|
|||||||
} else if (matches(argv[1], "-force") == 0) {
|
} else if (matches(argv[1], "-force") == 0) {
|
||||||
++force;
|
++force;
|
||||||
} else if (matches(argv[1], "-batch") == 0) {
|
} else if (matches(argv[1], "-batch") == 0) {
|
||||||
do_batching = 1;
|
|
||||||
if (argc > 2)
|
|
||||||
batchfile = argv[2];
|
|
||||||
argc--; argv++;
|
argc--; argv++;
|
||||||
|
if (argc <= 1)
|
||||||
|
usage();
|
||||||
|
batch_file = argv[1];
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Option \"%s\" is unknown, try \"tc -help\".\n", argv[1]);
|
fprintf(stderr, "Option \"%s\" is unknown, try \"tc -help\".\n", argv[1]);
|
||||||
return -1;
|
return -1;
|
||||||
@ -299,8 +300,8 @@ int main(int argc, char **argv)
|
|||||||
argc--; argv++;
|
argc--; argv++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (do_batching)
|
if (batch_file)
|
||||||
return batch(batchfile);
|
return batch(batch_file);
|
||||||
|
|
||||||
if (argc <= 1) {
|
if (argc <= 1) {
|
||||||
usage();
|
usage();
|
||||||
|
Loading…
Reference in New Issue
Block a user