Linux-Trace-Devel Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH v3 0/5] Handle the case when KernelShark is started as Root
@ 2019-09-20 10:28 Yordan Karadzhov (VMware)
  2019-09-20 10:28 ` [PATCH v3 1/5] kernel-shark: Show warning message when running " Yordan Karadzhov (VMware)
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Yordan Karadzhov (VMware) @ 2019-09-20 10:28 UTC (permalink / raw)
  To: rostedt; +Cc: linux-trace-devel, Yordan Karadzhov (VMware)

A patch set implementing the improvements suggested here:

https://bugzilla.kernel.org/show_bug.cgi?id=204475

Plus a minor improvements of the error messages printed when something
goes wrong withe the "Record" dialog.  

v2 changes:
  - Correcting typos in patch 1/5
  - Fixing a bug in patch 2/5. trace-cmd now gets correctly formatted list
  of command line arguments.
  - Patches 4/5 and 5/5 are new.

v3 changes:
  - Polishing the text of the warning/error messages in patches 1/5 and
  5/5. The modifications have been suggested by Steven.

Yordan Karadzhov (VMware) (5):
  kernel-shark: Show warning message when running as Root
  kernel-shark: Don't use pkexec when running as Root
  kernel-shark: Use standart error message in KsMainWindow::_record()
  kernel-shark: Optimize the error messages when "Record" fails to start
  kernel-shark: Better formatting of the error messages from "Record"

 kernel-shark/src/KsMainWindow.cpp | 90 +++++++++++++++++++++++--------
 kernel-shark/src/KsMainWindow.hpp |  4 ++
 2 files changed, 71 insertions(+), 23 deletions(-)

-- 
2.20.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v3 1/5] kernel-shark: Show warning message when running as Root
  2019-09-20 10:28 [PATCH v3 0/5] Handle the case when KernelShark is started as Root Yordan Karadzhov (VMware)
@ 2019-09-20 10:28 ` " Yordan Karadzhov (VMware)
  2019-09-20 10:28 ` [PATCH v3 2/5] kernel-shark: Don't use pkexec " Yordan Karadzhov (VMware)
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Yordan Karadzhov (VMware) @ 2019-09-20 10:28 UTC (permalink / raw)
  To: rostedt; +Cc: linux-trace-devel, Yordan Karadzhov (VMware)

Running the KernelShark GUI with Root privileges is not recommended due
to security reasons. The user will be allowed to continue on its own risk.

Suggested-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=204475
Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
---
 kernel-shark/src/KsMainWindow.cpp | 28 ++++++++++++++++++++++++++++
 kernel-shark/src/KsMainWindow.hpp |  2 ++
 2 files changed, 30 insertions(+)

diff --git a/kernel-shark/src/KsMainWindow.cpp b/kernel-shark/src/KsMainWindow.cpp
index 6439265..904d682 100644
--- a/kernel-shark/src/KsMainWindow.cpp
+++ b/kernel-shark/src/KsMainWindow.cpp
@@ -76,6 +76,9 @@ KsMainWindow::KsMainWindow(QWidget *parent)
 	_createMenus();
 	_initCapture();
 
+	if (geteuid() == 0)
+		_rootWarning();
+
 	_splitter.addWidget(&_graph);
 	_splitter.addWidget(&_view);
 	setCentralWidget(&_splitter);
@@ -1271,3 +1274,28 @@ void KsMainWindow::_deselectB()
 	_mState.updateLabels();
 	_graph.glPtr()->model()->update();
 }
+
+void KsMainWindow::_rootWarning()
+{
+	QString cbFlag("noRootWarn");
+
+	if (_settings.value(cbFlag).toBool())
+		return;
+
+	QMessageBox warn;
+	warn.setText("KernelShark is running with Root privileges.");
+	warn.setInformativeText("Continue at your own risk.");
+	warn.setIcon(QMessageBox::Warning);
+	warn.setStandardButtons(QMessageBox::Close);
+
+	QCheckBox cb("Don't show this message again.");
+
+	auto lamCbChec = [&] (int state) {
+		if (state)
+			_settings.setValue(cbFlag, true);
+	};
+
+	connect(&cb, &QCheckBox::stateChanged, lamCbChec);
+	warn.setCheckBox(&cb);
+	warn.exec();
+}
diff --git a/kernel-shark/src/KsMainWindow.hpp b/kernel-shark/src/KsMainWindow.hpp
index 62e66a0..4a7b8ab 100644
--- a/kernel-shark/src/KsMainWindow.hpp
+++ b/kernel-shark/src/KsMainWindow.hpp
@@ -238,6 +238,8 @@ private:
 
 	void _deselectB();
 
+	void _rootWarning();
+
 	void _updateFilterMenu();
 
 	void _filterSyncCBoxUpdate(kshark_context *kshark_ctx);
-- 
2.20.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v3 2/5] kernel-shark: Don't use pkexec when running as Root
  2019-09-20 10:28 [PATCH v3 0/5] Handle the case when KernelShark is started as Root Yordan Karadzhov (VMware)
  2019-09-20 10:28 ` [PATCH v3 1/5] kernel-shark: Show warning message when running " Yordan Karadzhov (VMware)
@ 2019-09-20 10:28 ` " Yordan Karadzhov (VMware)
  2019-09-20 10:28 ` [PATCH v3 3/5] kernel-shark: Use standart error message in KsMainWindow::_record() Yordan Karadzhov (VMware)
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Yordan Karadzhov (VMware) @ 2019-09-20 10:28 UTC (permalink / raw)
  To: rostedt; +Cc: linux-trace-devel, Yordan Karadzhov (VMware)

If KernelShark GUI has been started as Root we do not need to use
"pkexec" when starting the Record dialog. Note that the actual place
where "pkexec" gets used is in the script "kshark-su-record".

Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
---
 kernel-shark/src/KsMainWindow.cpp | 47 +++++++++++++++++++++----------
 1 file changed, 32 insertions(+), 15 deletions(-)

diff --git a/kernel-shark/src/KsMainWindow.cpp b/kernel-shark/src/KsMainWindow.cpp
index 904d682..c220afb 100644
--- a/kernel-shark/src/KsMainWindow.cpp
+++ b/kernel-shark/src/KsMainWindow.cpp
@@ -883,23 +883,26 @@ void KsMainWindow::_pluginAdd()
 
 void KsMainWindow::_record()
 {
-#ifndef DO_AS_ROOT
+	bool canDoAsRoot(false);
 
-	QErrorMessage *em = new QErrorMessage(this);
-	QString message;
-
-	message = "Record is currently not supported.";
-	message += " Install \"pkexec\" and then do:<br>";
-	message += " cd build <br> sudo ./cmake_uninstall.sh <br>";
-	message += " ./cmake_clean.sh <br> cmake .. <br> make <br>";
-	message += " sudo make install";
+#ifdef DO_AS_ROOT
+	canDoAsRoot = true;
+#endif
 
-	em->showMessage(message);
-	qCritical() << "ERROR: " << message;
+	if (geteuid() && !canDoAsRoot) {
+		QErrorMessage *em = new QErrorMessage(this);
+		QString message;
 
-	return;
+		message = "Record is currently not supported.";
+		message += " Install \"pkexec\" and then do:<br>";
+		message += " cd build <br> sudo ./cmake_uninstall.sh <br>";
+		message += " ./cmake_clean.sh <br> cmake .. <br> make <br>";
+		message += " sudo make install";
 
-#endif
+		em->showMessage(message);
+		qCritical() << "ERROR: " << message;
+		return;
+	}
 
 	_capture.start();
 }
@@ -1134,9 +1137,24 @@ void KsMainWindow::loadSession(const QString &fileName)
 
 void KsMainWindow::_initCapture()
 {
+	bool canDoAsRoot(false);
+
 #ifdef DO_AS_ROOT
+	canDoAsRoot = true;
+#endif
+
+	if (geteuid() && !canDoAsRoot)
+		return;
 
-	_capture.setProgram("kshark-su-record");
+	if (geteuid()) {
+		_capture.setProgram("kshark-su-record");
+	} else {
+		QStringList argv;
+
+		_capture.setProgram("kshark-record");
+		argv << QString("-o") << QDir::homePath() + "/trace.dat";
+		_capture.setArguments(argv);
+	}
 
 	connect(&_capture,	&QProcess::started,
 		this,		&KsMainWindow::_captureStarted);
@@ -1155,7 +1173,6 @@ void KsMainWindow::_initCapture()
 	connect(&_captureLocalServer,	&QLocalServer::newConnection,
 		this,			&KsMainWindow::_readSocket);
 
-#endif
 }
 
 void KsMainWindow::_captureStarted()
-- 
2.20.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v3 3/5] kernel-shark: Use standart error message in KsMainWindow::_record()
  2019-09-20 10:28 [PATCH v3 0/5] Handle the case when KernelShark is started as Root Yordan Karadzhov (VMware)
  2019-09-20 10:28 ` [PATCH v3 1/5] kernel-shark: Show warning message when running " Yordan Karadzhov (VMware)
  2019-09-20 10:28 ` [PATCH v3 2/5] kernel-shark: Don't use pkexec " Yordan Karadzhov (VMware)
@ 2019-09-20 10:28 ` Yordan Karadzhov (VMware)
  2019-09-20 10:28 ` [PATCH v3 4/5] kernel-shark: Optimize the error messages when "Record" fails to start Yordan Karadzhov (VMware)
  2019-09-20 10:28 ` [PATCH v3 5/5] kernel-shark: Better formatting of the error messages from "Record" Yordan Karadzhov (VMware)
  4 siblings, 0 replies; 6+ messages in thread
From: Yordan Karadzhov (VMware) @ 2019-09-20 10:28 UTC (permalink / raw)
  To: rostedt; +Cc: linux-trace-devel, Yordan Karadzhov (VMware)

The error message is printed using the method KsMainWindow::_error().
The message itself remains unchanged. If we want to change the message,
this can be done in another patch.

Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
---
 kernel-shark/src/KsMainWindow.cpp | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/kernel-shark/src/KsMainWindow.cpp b/kernel-shark/src/KsMainWindow.cpp
index c220afb..e24b0f5 100644
--- a/kernel-shark/src/KsMainWindow.cpp
+++ b/kernel-shark/src/KsMainWindow.cpp
@@ -890,7 +890,6 @@ void KsMainWindow::_record()
 #endif
 
 	if (geteuid() && !canDoAsRoot) {
-		QErrorMessage *em = new QErrorMessage(this);
 		QString message;
 
 		message = "Record is currently not supported.";
@@ -899,8 +898,7 @@ void KsMainWindow::_record()
 		message += " ./cmake_clean.sh <br> cmake .. <br> make <br>";
 		message += " sudo make install";
 
-		em->showMessage(message);
-		qCritical() << "ERROR: " << message;
+		_error(message, "recordCantStart", false, false);
 		return;
 	}
 
-- 
2.20.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v3 4/5] kernel-shark: Optimize the error messages when "Record" fails to start
  2019-09-20 10:28 [PATCH v3 0/5] Handle the case when KernelShark is started as Root Yordan Karadzhov (VMware)
                   ` (2 preceding siblings ...)
  2019-09-20 10:28 ` [PATCH v3 3/5] kernel-shark: Use standart error message in KsMainWindow::_record() Yordan Karadzhov (VMware)
@ 2019-09-20 10:28 ` Yordan Karadzhov (VMware)
  2019-09-20 10:28 ` [PATCH v3 5/5] kernel-shark: Better formatting of the error messages from "Record" Yordan Karadzhov (VMware)
  4 siblings, 0 replies; 6+ messages in thread
From: Yordan Karadzhov (VMware) @ 2019-09-20 10:28 UTC (permalink / raw)
  To: rostedt; +Cc: linux-trace-devel, Yordan Karadzhov (VMware)

Removing duplicate code.

Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
---
 kernel-shark/src/KsMainWindow.cpp | 14 +++++++-------
 kernel-shark/src/KsMainWindow.hpp |  2 ++
 2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/kernel-shark/src/KsMainWindow.cpp b/kernel-shark/src/KsMainWindow.cpp
index e24b0f5..311aa87 100644
--- a/kernel-shark/src/KsMainWindow.cpp
+++ b/kernel-shark/src/KsMainWindow.cpp
@@ -1199,18 +1199,18 @@ void KsMainWindow::_captureFinished(int ret, QProcess::ExitStatus st)
 		return;
 	}
 
-	if (ret != 0 && st == QProcess::NormalExit) {
-		QString message = "Capture process failed:<br>";
-
-		message += capture->errorString();
-		message += capture->readAllStandardError();
-		_error(message, "captureFinishedErr", false, false);
-	}
+	if (ret != 0 && st == QProcess::NormalExit)
+		_captureErrorMessage(capture);
 }
 
 void KsMainWindow::_captureError(QProcess::ProcessError error)
 {
 	QProcess *capture = (QProcess *)sender();
+	_captureErrorMessage(capture);
+}
+
+void KsMainWindow::_captureErrorMessage(QProcess *capture)
+{
 	QString message = "Capture process failed:<br>";
 
 	message += capture->errorString();
diff --git a/kernel-shark/src/KsMainWindow.hpp b/kernel-shark/src/KsMainWindow.hpp
index 4a7b8ab..eef4f96 100644
--- a/kernel-shark/src/KsMainWindow.hpp
+++ b/kernel-shark/src/KsMainWindow.hpp
@@ -215,6 +215,8 @@ private:
 
 	void _captureError(QProcess::ProcessError error);
 
+	void _captureErrorMessage(QProcess *capture);
+
 	void _readSocket();
 
 	void _splitterMoved(int pos, int index);
-- 
2.20.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v3 5/5] kernel-shark: Better formatting of the error messages from "Record"
  2019-09-20 10:28 [PATCH v3 0/5] Handle the case when KernelShark is started as Root Yordan Karadzhov (VMware)
                   ` (3 preceding siblings ...)
  2019-09-20 10:28 ` [PATCH v3 4/5] kernel-shark: Optimize the error messages when "Record" fails to start Yordan Karadzhov (VMware)
@ 2019-09-20 10:28 ` Yordan Karadzhov (VMware)
  4 siblings, 0 replies; 6+ messages in thread
From: Yordan Karadzhov (VMware) @ 2019-09-20 10:28 UTC (permalink / raw)
  To: rostedt; +Cc: linux-trace-devel, Yordan Karadzhov (VMware)

Make the message easier to read and understand by separating the
QProcess's error and the Standard error.

Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
---
 kernel-shark/src/KsMainWindow.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/kernel-shark/src/KsMainWindow.cpp b/kernel-shark/src/KsMainWindow.cpp
index 311aa87..a583f5f 100644
--- a/kernel-shark/src/KsMainWindow.cpp
+++ b/kernel-shark/src/KsMainWindow.cpp
@@ -1211,9 +1211,10 @@ void KsMainWindow::_captureError(QProcess::ProcessError error)
 
 void KsMainWindow::_captureErrorMessage(QProcess *capture)
 {
-	QString message = "Capture process failed:<br>";
+	QString message = "Capture process failed: ";
 
 	message += capture->errorString();
+	message += "<br>Standard Error: ";
 	message += capture->readAllStandardError();
 	_error(message, "captureFinishedErr", false, false);
 }
-- 
2.20.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, back to index

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-20 10:28 [PATCH v3 0/5] Handle the case when KernelShark is started as Root Yordan Karadzhov (VMware)
2019-09-20 10:28 ` [PATCH v3 1/5] kernel-shark: Show warning message when running " Yordan Karadzhov (VMware)
2019-09-20 10:28 ` [PATCH v3 2/5] kernel-shark: Don't use pkexec " Yordan Karadzhov (VMware)
2019-09-20 10:28 ` [PATCH v3 3/5] kernel-shark: Use standart error message in KsMainWindow::_record() Yordan Karadzhov (VMware)
2019-09-20 10:28 ` [PATCH v3 4/5] kernel-shark: Optimize the error messages when "Record" fails to start Yordan Karadzhov (VMware)
2019-09-20 10:28 ` [PATCH v3 5/5] kernel-shark: Better formatting of the error messages from "Record" Yordan Karadzhov (VMware)

Linux-Trace-Devel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-trace-devel/0 linux-trace-devel/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-trace-devel linux-trace-devel/ https://lore.kernel.org/linux-trace-devel \
		linux-trace-devel@vger.kernel.org
	public-inbox-index linux-trace-devel

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-trace-devel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git