Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Tammo Jan Dijkema
dt_ctrl
Commits
7e3254d6
Commit
7e3254d6
authored
Jan 15, 2015
by
Jeroen Vreeken
Browse files
Add max size and rotate options to trace2file
parent
1fd85e38
Changes
3
Hide whitespace changes
Inline
Side-by-side
common/trace/test.pcap
deleted
100644 → 0
View file @
1fd85e38
File deleted
common/trace/trace2file.c
View file @
7e3254d6
...
...
@@ -32,7 +32,53 @@
static
struct
timespec
t_int
;
static
char
*
tracename
;
static
int
fd_file
=
1
;
static
int
fd_file
=
-
1
;
size_t
max_size
=
0
;
int
rotate_max
=
0
;
size_t
cur_size
=
0
;
char
*
output_name
;
struct
trace
*
trace
;
static
void
open_output
(
void
)
{
struct
trace_pkt
*
pkt
;
int
i
;
if
(
fd_file
>=
0
)
close
(
fd_file
);
for
(
i
=
rotate_max
;
i
>
0
;
i
--
)
{
char
*
oldpath
,
*
newpath
;
asprintf
(
&
newpath
,
"%s.%d"
,
output_name
,
i
);
if
(
i
>
1
)
asprintf
(
&
oldpath
,
"%s.%d"
,
output_name
,
i
-
1
);
else
asprintf
(
&
oldpath
,
"%s"
,
output_name
);
printf
(
"move %s to %s
\n
"
,
oldpath
,
newpath
);
rename
(
oldpath
,
newpath
);
free
(
oldpath
);
free
(
newpath
);
}
fd_file
=
open
(
output_name
,
O_WRONLY
|
O_TRUNC
|
O_CREAT
,
S_IRUSR
|
S_IWUSR
|
S_IRGRP
|
S_IROTH
);
pkt
=
trace_packet_new
();
trace_packet_name_set
(
pkt
,
tracename
);
trace_packet_write
(
trace
,
pkt
);
trace_packet_write_fd
(
fd_file
,
pkt
);
trace_packet_put
(
pkt
);
pkt
=
trace_packet_new
();
trace_packet_type_set
(
pkt
,
trace
->
type
);
trace_packet_write_fd
(
fd_file
,
pkt
);
trace_packet_put
(
pkt
);
cur_size
=
0
;
}
static
void
handler_interval
(
struct
trace
*
trace
,
struct
timespec
*
interval
,
enum
trace_interval_type
type
)
...
...
@@ -50,6 +96,12 @@ size_t trace_handler_read(struct trace *trace, void *buf, size_t len)
printf
(
"Could not write %zd bytes to file %d : %zd: %s
\n
"
,
r
,
fd_file
,
len
,
strerror
(
errno
));
exit
(
1
);
}
else
{
cur_size
+=
r
;
if
(
cur_size
>=
max_size
)
{
printf
(
"Maximum file size reached, reopening new file
\n
"
);
open_output
();
}
}
return
0
;
...
...
@@ -57,30 +109,29 @@ size_t trace_handler_read(struct trace *trace, void *buf, size_t len)
int
main
(
int
argc
,
char
**
argv
)
{
struct
trace
*
trace
;
struct
trace_pkt
*
pkt
;
int
interval
=
1
;
uint64_t
nsec_interval
;
struct
trace_pkt
*
pkt
;
if
(
argc
<
5
)
{
printf
(
"Usage:
\n\n
"
);
printf
(
"%s [host] [port] [trace] [file] <interval>
\n
"
,
argv
[
0
]);
printf
(
"%s [host] [port] [trace] [file] <interval>
<max_size> <rotate_max>
\n
"
,
argv
[
0
]);
return
0
;
}
tracename
=
argv
[
3
];
output_name
=
argv
[
4
];
trace
=
trace_open
(
argv
[
1
],
atoi
(
argv
[
2
]));
fd_file
=
open
(
argv
[
4
],
O_WRONLY
|
O_APPEND
|
O_CREAT
,
S_IRUSR
|
S_IWUSR
|
S_IRGRP
|
S_IROTH
);
if
(
fd_file
<
0
)
{
printf
(
"%s Could not open output file %s
\n
"
,
argv
[
0
],
argv
[
4
]);
return
0
;
}
if
(
argc
>=
6
)
{
interval
=
atoi
(
argv
[
5
]);
}
if
(
argc
>=
8
)
{
max_size
=
atoi
(
argv
[
6
]);
rotate_max
=
atoi
(
argv
[
7
]);
}
trace
->
handler_interval
=
handler_interval
;
...
...
@@ -124,16 +175,11 @@ int main(int argc, char **argv)
}
pkt
=
trace_packet_new
();
trace_packet_name_set
(
pkt
,
tracename
);
trace_packet_write
(
trace
,
pkt
);
trace_packet_write_fd
(
fd_file
,
pkt
);
trace_packet_put
(
pkt
);
pkt
=
trace_packet_new
();
trace_packet_type_set
(
pkt
,
trace
->
type
);
trace_packet_write_fd
(
fd_file
,
pkt
);
trace_packet_put
(
pkt
);
open_output
();
if
(
fd_file
<
0
)
{
printf
(
"%s Could not open output file %s
\n
"
,
argv
[
0
],
argv
[
4
]);
return
0
;
}
trace
->
handler_read
=
trace_handler_read
;
...
...
console/console/start_console.sh
View file @
7e3254d6
...
...
@@ -24,18 +24,9 @@ screen -S console -X screen -t console_sattracker console_sattracker
screen
-S
console
-X
screen
-t
console_weather console_weather
screen
-S
console
-X
screen
-t
console_httpd console_httpd
TR
=
`
ls
traces/
*
trace
`
for
tr
in
$TR
;
do
echo
$tr
mv
-f
${
tr
}
.4
${
tr
}
.5
mv
-f
${
tr
}
.3
${
tr
}
.4
mv
-f
${
tr
}
.2
${
tr
}
.3
mv
-f
${
tr
}
.1
${
tr
}
.2
mv
-f
${
tr
}
${
tr
}
.1
done
screen
-S
console
-X
screen
-t
trace_az_pos ../../common/trace/trace2file localhost 10000 Azimuth_Position traces/Azimuth_Position.trace 15000
screen
-S
console
-X
screen
-t
trace_az_pos ../../common/trace/trace2file localhost 10000 Elevation_Position traces/Elevation_Position.trace 15000
screen
-S
console
-X
screen
-t
trace_az_pos ../../common/trace/trace2file localhost 10000 Azimuth_Speed traces/Azimuth_Speed.trace 15000
screen
-S
console
-X
screen
-t
trace_az_pos ../../common/trace/trace2file localhost 10000 Elevation_Speed_Right traces/Elevation_Speed_Right.trace 15000
screen
-S
console
-X
screen
-t
trace_az_pos ../../common/trace/trace2file localhost 10000 Elevation_Speed_Left traces/Elevation_Speed_Left.trace 15000
screen
-S
console
-X
screen
-t
trace_az_pos ../../common/trace/trace2file localhost 10000 Azimuth_Position traces/Azimuth_Position.trace 15000 1000000 5
screen
-S
console
-X
screen
-t
trace_az_pos ../../common/trace/trace2file localhost 10000 Elevation_Position traces/Elevation_Position.trace 15000 1000000 5
screen
-S
console
-X
screen
-t
trace_az_pos ../../common/trace/trace2file localhost 10000 Azimuth_Speed traces/Azimuth_Speed.trace 15000 1000000 5
screen
-S
console
-X
screen
-t
trace_az_pos ../../common/trace/trace2file localhost 10000 Elevation_Speed_Right traces/Elevation_Speed_Right.trace 15000 1000000 5
screen
-S
console
-X
screen
-t
trace_az_pos ../../common/trace/trace2file localhost 10000 Elevation_Speed_Left traces/Elevation_Speed_Left.trace 15000 1000000 5
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