Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
Firmware
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Alberto Ruiz Garcia
Firmware
Commits
728de5f8
Commit
728de5f8
authored
8 years ago
by
Mark Whitehorn
Committed by
Lorenz Meier
8 years ago
Browse files
Options
Downloads
Patches
Plain Diff
clean up file open/close logic
parent
672042e0
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/modules/logger/log_writer.cpp
+27
-26
27 additions, 26 deletions
src/modules/logger/log_writer.cpp
src/modules/logger/log_writer.h
+1
-0
1 addition, 0 deletions
src/modules/logger/log_writer.h
src/modules/logger/logger.cpp
+1
-1
1 addition, 1 deletion
src/modules/logger/logger.cpp
with
29 additions
and
27 deletions
src/modules/logger/log_writer.cpp
+
27
−
26
View file @
728de5f8
...
...
@@ -22,11 +22,23 @@ LogWriter::LogWriter(uint8_t *buffer, size_t buffer_size) :
void
LogWriter
::
start_log
(
const
char
*
filename
)
{
::
strncpy
(
_filename
,
filename
,
sizeof
(
_filename
));
_fd
=
::
open
(
_filename
,
O_CREAT
|
O_WRONLY
,
PX4_O_MODE_666
);
if
(
_fd
<
0
)
{
PX4_WARN
(
"can't open log file %s"
,
_filename
);
_should_run
=
false
;
return
;
}
else
{
PX4_WARN
(
"opened log file: %s"
,
_filename
);
_should_run
=
true
;
_running
=
true
;
}
// Clear buffer and counters
_head
=
0
;
_count
=
0
;
_total_written
=
0
;
_should_run
=
true
;
notify
();
}
...
...
@@ -90,21 +102,7 @@ void LogWriter::run()
}
while
(
!
_exit_thread
)
{
// Outer endless loop, start new file each time
// _filename must be set before setting _should_run = true
_fd
=
::
open
(
_filename
,
O_CREAT
|
O_WRONLY
,
PX4_O_MODE_666
);
if
(
_fd
<
0
)
{
PX4_WARN
(
"can't open log file %s"
,
_filename
);
_should_run
=
false
;
continue
;
}
PX4_WARN
(
"started, log file: %s"
,
_filename
);
_should_run
=
true
;
// Outer endless loop
int
poll_count
=
0
;
int
written
=
0
;
...
...
@@ -164,22 +162,25 @@ void LogWriter::run()
_total_written
+=
written
;
}
if
(
!
_should_run
&&
written
==
static_cast
<
int
>
(
available
)
&&
!
is_part
)
{
if
(
_running
&&
!
_should_run
&&
written
==
static_cast
<
int
>
(
available
)
&&
!
is_part
)
{
// Stop only when all data written
break
;
}
}
_running
=
false
;
_head
=
0
;
_count
=
0
;
_head
=
0
;
_count
=
0
;
int
res
=
::
close
(
_fd
);
if
(
res
)
{
PX4_WARN
(
"error closing log file"
);
int
res
=
::
close
(
_fd
);
}
else
{
PX4_WARN
(
"closed logfile: %s, bytes written: %zu"
,
_filename
,
_total_written
);
}
if
(
res
)
{
PX4_WARN
(
"error closing log file"
);
break
;
}
}
PX4_WARN
(
"stopped, bytes written: %zu"
,
_total_written
);
}
}
...
...
This diff is collapsed.
Click to expand it.
src/modules/logger/log_writer.h
+
1
−
0
View file @
728de5f8
...
...
@@ -63,6 +63,7 @@ private:
size_t
_count
=
0
;
size_t
_total_written
=
0
;
bool
_should_run
=
false
;
bool
_running
=
false
;
bool
_exit_thread
=
false
;
pthread_mutex_t
_mtx
;
pthread_cond_t
_cv
;
...
...
This diff is collapsed.
Click to expand it.
src/modules/logger/logger.cpp
+
1
−
1
View file @
728de5f8
...
...
@@ -356,7 +356,7 @@ void Logger::run()
struct
mallinfo
alloc_info
=
{};
#endif
/* DBGPRINT */
PX4_WARN
(
"started"
);
PX4_WARN
(
"
logger
started"
);
int
mkdir_ret
=
mkdir
(
LOG_ROOT
,
S_IRWXU
|
S_IRWXG
|
S_IRWXO
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment