Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
I
iproute2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
iproute2
Commits
08856f02
Commit
08856f02
authored
Mar 18, 2005
by
osdl.net!shemminger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Handle batch mode better.
Add comments midline and -force option. (Logical change 1.173)
parent
4717cc91
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
71 additions
and
38 deletions
+71
-38
ChangeLog
ChangeLog
+6
-0
tc/tc.c
tc/tc.c
+65
-38
No files found.
ChangeLog
View file @
08856f02
2005-03-18 Stephen Hemminger <shemminger@osdl.org>
* add -force option to batch mode
* handle midline comments in batch mode
* sum per cpu fields in lnstat correctly
2005-03-14 Stephen Hemminger <shemminger@osdl.org>
2005-03-14 Stephen Hemminger <shemminger@osdl.org>
* cleanup batch mode, allow continuation, comments etc.
* cleanup batch mode, allow continuation, comments etc.
...
...
tc/tc.c
View file @
08856f02
...
@@ -35,6 +35,7 @@ int show_details = 0;
...
@@ -35,6 +35,7 @@ int show_details = 0;
int
show_raw
=
0
;
int
show_raw
=
0
;
int
resolve_hosts
=
0
;
int
resolve_hosts
=
0
;
int
use_iec
=
0
;
int
use_iec
=
0
;
int
force
=
0
;
struct
rtnl_handle
rth
;
struct
rtnl_handle
rth
;
static
void
*
BODY
;
/* cached handle dlopen(NULL) */
static
void
*
BODY
;
/* cached handle dlopen(NULL) */
...
@@ -207,6 +208,7 @@ static int do_cmd(int argc, char **argv)
...
@@ -207,6 +208,7 @@ static int do_cmd(int argc, char **argv)
return
-
1
;
return
-
1
;
}
}
/* split command line into argument vector */
static
int
makeargs
(
char
*
line
,
char
*
argv
[],
int
maxargs
)
static
int
makeargs
(
char
*
line
,
char
*
argv
[],
int
maxargs
)
{
{
static
const
char
ws
[]
=
"
\t\r\n
"
;
static
const
char
ws
[]
=
"
\t\r\n
"
;
...
@@ -225,14 +227,55 @@ static int makeargs(char *line, char *argv[], int maxargs)
...
@@ -225,14 +227,55 @@ static int makeargs(char *line, char *argv[], int maxargs)
return
argc
;
return
argc
;
}
}
static
int
lineno
;
/* Like glibc getline but handle continuation lines and comments */
static
size_t
getcmdline
(
char
**
linep
,
size_t
*
lenp
,
FILE
*
in
)
{
size_t
cc
;
char
*
cp
;
if
(
(
cc
=
getline
(
linep
,
lenp
,
in
))
<
0
)
return
cc
;
/* eof or error */
++
lineno
;
cp
=
strchr
(
*
linep
,
'#'
);
if
(
cp
)
*
cp
=
'\0'
;
while
((
cp
=
strstr
(
*
linep
,
"
\\\n
"
))
!=
NULL
)
{
char
*
line1
=
NULL
;
ssize_t
len1
=
0
;
size_t
cc1
;
if
((
cc1
=
getline
(
&
line1
,
&
len1
,
in
))
<
0
)
{
fprintf
(
stderr
,
"Missing continuation line
\n
"
);
return
cc1
;
}
++
lineno
;
*
cp
=
0
;
cp
=
strchr
(
line1
,
'#'
);
if
(
cp
)
*
cp
=
'\0'
;
*
linep
=
realloc
(
*
linep
,
strlen
(
*
linep
)
+
strlen
(
line1
)
+
1
);
if
(
!*
linep
)
{
fprintf
(
stderr
,
"Out of memory
\n
"
);
return
-
1
;
}
cc
+=
cc1
-
2
;
strcat
(
*
linep
,
line1
);
free
(
line1
);
}
return
cc
;
}
static
int
batch
(
const
char
*
name
)
static
int
batch
(
const
char
*
name
)
{
{
char
*
line
=
NULL
;
char
*
line
=
NULL
;
size_t
len
=
0
;
size_t
len
=
0
;
ssize_t
cc
;
int
ret
=
0
;
int
lineno
=
0
;
char
*
largv
[
100
];
int
largc
,
ret
=
0
;
if
(
strcmp
(
name
,
"-"
)
!=
0
)
{
if
(
strcmp
(
name
,
"-"
)
!=
0
)
{
if
(
freopen
(
name
,
"r"
,
stdin
)
==
NULL
)
{
if
(
freopen
(
name
,
"r"
,
stdin
)
==
NULL
)
{
...
@@ -249,42 +292,20 @@ static int batch(const char *name)
...
@@ -249,42 +292,20 @@ static int batch(const char *name)
return
-
1
;
return
-
1
;
}
}
while
((
cc
=
getline
(
&
line
,
&
len
,
stdin
))
!=
-
1
)
{
lineno
=
0
;
++
lineno
;
while
(
getcmdline
(
&
line
,
&
len
,
stdin
)
!=
-
1
)
{
char
*
largv
[
100
];
/* ignore blank lines and comments */
int
largc
;
if
(
*
line
==
'\n'
||
*
line
==
'#'
)
continue
;
/* handle continuation lines */
while
(
cc
>=
2
&&
strcmp
(
line
+
cc
-
2
,
"
\\\n
"
)
==
0
)
{
char
*
line1
=
NULL
;
ssize_t
len1
=
0
;
int
cc1
;
cc1
=
getline
(
&
line1
,
&
len1
,
stdin
);
if
(
cc1
<
0
)
{
fprintf
(
stderr
,
"Missing continuation line
\n
"
);
return
-
1
;
}
++
lineno
;
line
=
realloc
(
line
,
cc
+
cc1
);
if
(
!
line
)
{
fprintf
(
stderr
,
"Out of memory
\n
"
);
return
-
1
;
}
strcpy
(
line
+
cc
-
2
,
line1
);
cc
+=
cc1
-
2
;
free
(
line1
);
}
largc
=
makeargs
(
line
,
largv
,
100
);
largc
=
makeargs
(
line
,
largv
,
100
);
if
(
largc
==
0
)
continue
;
/* blank line */
ret
=
do_cmd
(
largc
,
largv
);
if
(
do_cmd
(
largc
,
largv
))
{
if
(
ret
)
{
fprintf
(
stderr
,
"Command failed %s:%d
\n
"
,
name
,
lineno
);
fprintf
(
stderr
,
"Command failed %s:%d
\n
"
,
name
,
lineno
);
break
;
ret
=
1
;
if
(
!
force
)
break
;
}
}
}
}
...
@@ -296,6 +317,7 @@ static int batch(const char *name)
...
@@ -296,6 +317,7 @@ static int batch(const char *name)
int
main
(
int
argc
,
char
**
argv
)
int
main
(
int
argc
,
char
**
argv
)
{
{
int
ret
;
int
ret
;
char
*
batchfile
=
NULL
;
while
(
argc
>
1
)
{
while
(
argc
>
1
)
{
if
(
argv
[
1
][
0
]
!=
'-'
)
if
(
argv
[
1
][
0
]
!=
'-'
)
...
@@ -315,13 +337,15 @@ int main(int argc, char **argv)
...
@@ -315,13 +337,15 @@ int main(int argc, char **argv)
}
else
if
(
matches
(
argv
[
1
],
"-help"
)
==
0
)
{
}
else
if
(
matches
(
argv
[
1
],
"-help"
)
==
0
)
{
usage
();
usage
();
return
0
;
return
0
;
}
else
if
(
matches
(
argv
[
1
],
"-force"
)
==
0
)
{
++
force
;
}
else
if
(
matches
(
argv
[
1
],
"-batch"
)
==
0
)
{
}
else
if
(
matches
(
argv
[
1
],
"-batch"
)
==
0
)
{
if
(
argc
<
3
)
{
if
(
argc
<
3
)
{
fprintf
(
stderr
,
"Wrong number of arguments in batch mode
\n
"
);
fprintf
(
stderr
,
"Wrong number of arguments in batch mode
\n
"
);
return
-
1
;
return
-
1
;
}
}
batchfile
=
argv
[
2
];
return
batch
(
argv
[
2
])
;
argc
--
;
argv
++
;
}
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
;
...
@@ -329,6 +353,9 @@ int main(int argc, char **argv)
...
@@ -329,6 +353,9 @@ int main(int argc, char **argv)
argc
--
;
argv
++
;
argc
--
;
argv
++
;
}
}
if
(
batchfile
)
return
batch
(
batchfile
);
if
(
argc
<=
1
)
{
if
(
argc
<=
1
)
{
usage
();
usage
();
return
0
;
return
0
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment