浏览代码

tracing: Break out of tracing_wait_pipe() before wait_pipe() is called

When reading from trace_pipe, if tracing is off but nothing was read
it should block. If something is read and tracing is off, then EOF
is returned. If tracing is on and there's nothing to read, it will block.

But because the check of whether tracing is off and something was read
is done after the block on the pipe, it is hit or miss if the EOF is
returned or not leading to inconsistent behavior.

Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Steven Rostedt (Red Hat) 11 年之前
父节点
当前提交
f487426104
共有 1 个文件被更改,包括 9 次插入9 次删除
  1. 9 9
      kernel/trace/trace.c

+ 9 - 9
kernel/trace/trace.c

@@ -4237,15 +4237,6 @@ static int tracing_wait_pipe(struct file *filp)
 			return -EAGAIN;
 			return -EAGAIN;
 		}
 		}
 
 
-		mutex_unlock(&iter->mutex);
-
-		iter->trace->wait_pipe(iter);
-
-		mutex_lock(&iter->mutex);
-
-		if (signal_pending(current))
-			return -EINTR;
-
 		/*
 		/*
 		 * We block until we read something and tracing is disabled.
 		 * We block until we read something and tracing is disabled.
 		 * We still block if tracing is disabled, but we have never
 		 * We still block if tracing is disabled, but we have never
@@ -4257,6 +4248,15 @@ static int tracing_wait_pipe(struct file *filp)
 		 */
 		 */
 		if (!tracing_is_on() && iter->pos)
 		if (!tracing_is_on() && iter->pos)
 			break;
 			break;
+
+		mutex_unlock(&iter->mutex);
+
+		iter->trace->wait_pipe(iter);
+
+		mutex_lock(&iter->mutex);
+
+		if (signal_pending(current))
+			return -EINTR;
 	}
 	}
 
 
 	return 1;
 	return 1;