Commit 8650ae32 authored by Steven Rostedt's avatar Steven Rostedt Committed by Steven Rostedt

tracing: only truncate ftrace files when O_TRUNC is set

The current code will truncate the ftrace files contents if O_APPEND
is not set and the file is opened in write mode. This is incorrect.
It should only truncate the file if O_TRUNC is set. Otherwise
if one of these files is opened by a C program with fopen "r+",
it will incorrectly truncate the file.
Reported-by: default avatarJiri Olsa <jolsa@redhat.com>
Signed-off-by: default avatarSteven Rostedt <rostedt@goodmis.org>
parent 4c739ff0
...@@ -1662,7 +1662,7 @@ ftrace_regex_open(struct inode *inode, struct file *file, int enable) ...@@ -1662,7 +1662,7 @@ ftrace_regex_open(struct inode *inode, struct file *file, int enable)
mutex_lock(&ftrace_regex_lock); mutex_lock(&ftrace_regex_lock);
if ((file->f_mode & FMODE_WRITE) && if ((file->f_mode & FMODE_WRITE) &&
!(file->f_flags & O_APPEND)) (file->f_flags & O_TRUNC))
ftrace_filter_reset(enable); ftrace_filter_reset(enable);
if (file->f_mode & FMODE_READ) { if (file->f_mode & FMODE_READ) {
...@@ -2577,7 +2577,7 @@ ftrace_graph_open(struct inode *inode, struct file *file) ...@@ -2577,7 +2577,7 @@ ftrace_graph_open(struct inode *inode, struct file *file)
mutex_lock(&graph_lock); mutex_lock(&graph_lock);
if ((file->f_mode & FMODE_WRITE) && if ((file->f_mode & FMODE_WRITE) &&
!(file->f_flags & O_APPEND)) { (file->f_flags & O_TRUNC)) {
ftrace_graph_count = 0; ftrace_graph_count = 0;
memset(ftrace_graph_funcs, 0, sizeof(ftrace_graph_funcs)); memset(ftrace_graph_funcs, 0, sizeof(ftrace_graph_funcs));
} }
......
...@@ -2031,7 +2031,7 @@ static int tracing_open(struct inode *inode, struct file *file) ...@@ -2031,7 +2031,7 @@ static int tracing_open(struct inode *inode, struct file *file)
/* If this file was open for write, then erase contents */ /* If this file was open for write, then erase contents */
if ((file->f_mode & FMODE_WRITE) && if ((file->f_mode & FMODE_WRITE) &&
!(file->f_flags & O_APPEND)) { (file->f_flags & O_TRUNC)) {
long cpu = (long) inode->i_private; long cpu = (long) inode->i_private;
if (cpu == TRACE_PIPE_ALL_CPU) if (cpu == TRACE_PIPE_ALL_CPU)
......
...@@ -376,7 +376,7 @@ ftrace_event_seq_open(struct inode *inode, struct file *file) ...@@ -376,7 +376,7 @@ ftrace_event_seq_open(struct inode *inode, struct file *file)
const struct seq_operations *seq_ops; const struct seq_operations *seq_ops;
if ((file->f_mode & FMODE_WRITE) && if ((file->f_mode & FMODE_WRITE) &&
!(file->f_flags & O_APPEND)) (file->f_flags & O_TRUNC))
ftrace_clear_events(); ftrace_clear_events();
seq_ops = inode->i_private; seq_ops = inode->i_private;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment