aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Rostedt <srostedt@redhat.com>2009-07-22 23:29:30 -0400
committerSteven Rostedt <rostedt@goodmis.org>2009-07-23 10:07:18 -0400
commit8650ae32ef7045e763825dee6256dde7f331bb85 (patch)
tree546a07e4c5b6fc731b48604769392a671c1fb18e
parent4c739ff043e5787d97c9691d62cabf7a29e75a9d (diff)
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: Jiri Olsa <jolsa@redhat.com> Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
-rw-r--r--kernel/trace/ftrace.c4
-rw-r--r--kernel/trace/trace.c2
-rw-r--r--kernel/trace/trace_events.c2
3 files changed, 4 insertions, 4 deletions
diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index 1f3ec2afa511..1e1d23c26308 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -1662,7 +1662,7 @@ ftrace_regex_open(struct inode *inode, struct file *file, int enable)
1662 1662
1663 mutex_lock(&ftrace_regex_lock); 1663 mutex_lock(&ftrace_regex_lock);
1664 if ((file->f_mode & FMODE_WRITE) && 1664 if ((file->f_mode & FMODE_WRITE) &&
1665 !(file->f_flags & O_APPEND)) 1665 (file->f_flags & O_TRUNC))
1666 ftrace_filter_reset(enable); 1666 ftrace_filter_reset(enable);
1667 1667
1668 if (file->f_mode & FMODE_READ) { 1668 if (file->f_mode & FMODE_READ) {
@@ -2577,7 +2577,7 @@ ftrace_graph_open(struct inode *inode, struct file *file)
2577 2577
2578 mutex_lock(&graph_lock); 2578 mutex_lock(&graph_lock);
2579 if ((file->f_mode & FMODE_WRITE) && 2579 if ((file->f_mode & FMODE_WRITE) &&
2580 !(file->f_flags & O_APPEND)) { 2580 (file->f_flags & O_TRUNC)) {
2581 ftrace_graph_count = 0; 2581 ftrace_graph_count = 0;
2582 memset(ftrace_graph_funcs, 0, sizeof(ftrace_graph_funcs)); 2582 memset(ftrace_graph_funcs, 0, sizeof(ftrace_graph_funcs));
2583 } 2583 }
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 8bc8d8afea6a..d8ef28574aa1 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -2031,7 +2031,7 @@ static int tracing_open(struct inode *inode, struct file *file)
2031 2031
2032 /* If this file was open for write, then erase contents */ 2032 /* If this file was open for write, then erase contents */
2033 if ((file->f_mode & FMODE_WRITE) && 2033 if ((file->f_mode & FMODE_WRITE) &&
2034 !(file->f_flags & O_APPEND)) { 2034 (file->f_flags & O_TRUNC)) {
2035 long cpu = (long) inode->i_private; 2035 long cpu = (long) inode->i_private;
2036 2036
2037 if (cpu == TRACE_PIPE_ALL_CPU) 2037 if (cpu == TRACE_PIPE_ALL_CPU)
diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
index 53c8fd376a88..23d2972b22d6 100644
--- a/kernel/trace/trace_events.c
+++ b/kernel/trace/trace_events.c
@@ -376,7 +376,7 @@ ftrace_event_seq_open(struct inode *inode, struct file *file)
376 const struct seq_operations *seq_ops; 376 const struct seq_operations *seq_ops;
377 377
378 if ((file->f_mode & FMODE_WRITE) && 378 if ((file->f_mode & FMODE_WRITE) &&
379 !(file->f_flags & O_APPEND)) 379 (file->f_flags & O_TRUNC))
380 ftrace_clear_events(); 380 ftrace_clear_events();
381 381
382 seq_ops = inode->i_private; 382 seq_ops = inode->i_private;