History

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.

Steven Rostedt committed 17 years ago

Commit 8650ae31 parent 4c739ff3 files · +4 −4Browse files

Unified · Split

3 files
  1. kernel/trace/ftrace.c +2 −2
  2. kernel/trace/trace.c +1 −1
  3. kernel/trace/trace_events.c +1 −1
kernel/trace/ftrace.c+2−2
@@ -1662,7 +1662,7 @@ ftrace_regex_open(struct inode *inode, struct file *file, int enable) · 1661 unmodified lines
16621662
16631663 mutex_lock(&ftrace_regex_lock);
16641664 if ((file->f_mode & FMODE_WRITE) &&
1665− !(file->f_flags & O_APPEND))
1665+ (file->f_flags & O_TRUNC))
16661666 ftrace_filter_reset(enable);
16671667
16681668 if (file->f_mode & FMODE_READ) {
@@ -2577,7 +2577,7 @@ ftrace_graph_open(struct inode *inode, struct file *file) · 908 unmodified lines
25772577
25782578 mutex_lock(&graph_lock);
25792579 if ((file->f_mode & FMODE_WRITE) &&
2580− !(file->f_flags & O_APPEND)) {
2580+ (file->f_flags & O_TRUNC)) {
25812581 ftrace_graph_count = 0;
25822582 memset(ftrace_graph_funcs, 0, sizeof(ftrace_graph_funcs));
25832583 }
kernel/trace/trace.c+1−1
@@ -2031,7 +2031,7 @@ static int tracing_open(struct inode *inode, struct file *file) · 2030 unmodified lines
20312031
20322032 /* If this file was open for write, then erase contents */
20332033 if ((file->f_mode & FMODE_WRITE) &&
2034− !(file->f_flags & O_APPEND)) {
2034+ (file->f_flags & O_TRUNC)) {
20352035 long cpu = (long) inode->i_private;
20362036
20372037 if (cpu == TRACE_PIPE_ALL_CPU)
kernel/trace/trace_events.c+1−1
@@ -376,7 +376,7 @@ ftrace_event_seq_open(struct inode *inode, struct file *file) · 375 unmodified lines
376376 const struct seq_operations *seq_ops;
377377
378378 if ((file->f_mode & FMODE_WRITE) &&
379− !(file->f_flags & O_APPEND))
379+ (file->f_flags & O_TRUNC))
380380 ftrace_clear_events();
381381
382382 seq_ops = inode->i_private;