summaryrefslogtreecommitdiff
path: root/components/utilities
diff options
context:
space:
mode:
authorbernard <[email protected]>2017-09-29 10:23:56 +0800
committerbernard <[email protected]>2017-09-29 10:23:56 +0800
commitcccff34fcac04f34233a33e453f2d0ec255bf231 (patch)
treed406036f73296b27f3cb96e77ede98dd7803c61d /components/utilities
parente9a77b513f0a4b37d539a030592a61b08d03602d (diff)
parent3691b67e83ab57196dfc62606b1be18db76994a7 (diff)
Merge branch 'master' of https://github.com/RT-Thread/rt-thread
Diffstat (limited to 'components/utilities')
-rw-r--r--components/utilities/logtrace/log_file.c28
1 files changed, 24 insertions, 4 deletions
diff --git a/components/utilities/logtrace/log_file.c b/components/utilities/logtrace/log_file.c
index 2f4a28b63c..7a77008798 100644
--- a/components/utilities/logtrace/log_file.c
+++ b/components/utilities/logtrace/log_file.c
@@ -93,6 +93,25 @@ static rt_size_t fdevice_write(rt_device_t dev, rt_off_t pos, const void *buffer
return write(fdev->fd, buffer, size);
}
+static rt_err_t fdevice_control(rt_device_t dev, rt_uint8_t cmd, void *arg)
+{
+ struct file_device *fdev = (struct file_device *)dev;
+
+ if (fdev->fd < 0)
+ return 0;
+
+ switch (cmd)
+ {
+ case LOG_TRACE_CTRL_FLUSH:
+ if (fsync(fdev->fd) != 0)
+ return RT_ERROR;
+ break;
+ default:
+ break;
+ }
+ return RT_EOK;
+}
+
void log_trace_file_init(const char *filename)
{
rt_device_t device;
@@ -104,10 +123,11 @@ void log_trace_file_init(const char *filename)
_file_device.parent.type = RT_Device_Class_Char;
- _file_device.parent.init = RT_NULL;
- _file_device.parent.open = fdevice_open;
- _file_device.parent.close = fdevice_close;
- _file_device.parent.write = fdevice_write;
+ _file_device.parent.init = RT_NULL;
+ _file_device.parent.open = fdevice_open;
+ _file_device.parent.close = fdevice_close;
+ _file_device.parent.write = fdevice_write;
+ _file_device.parent.control = fdevice_control;
rt_device_register(&_file_device.parent, "logfile", O_RDWR);
}