[PATCH v3] kernel-shark: Retrieve the home of root using getpwuid()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Do not assume that root is always at "/root". Instead use getpwuid() and
get the home path for the user with id=0. On any error just quietly
default back to "/root".

Suggested-by: Steven Rostedt (VMware) <rostedt@xxxxxxxxxxx>
Suggested-by: Slavomir Kaslev <kaslevs@xxxxxxxxxx>
Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@xxxxxxxxx>
---
 kernel-shark/src/KsMainWindow.cpp | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/kernel-shark/src/KsMainWindow.cpp b/kernel-shark/src/KsMainWindow.cpp
index bd6c338..a5a399c 100644
--- a/kernel-shark/src/KsMainWindow.cpp
+++ b/kernel-shark/src/KsMainWindow.cpp
@@ -422,6 +422,12 @@ QString KsMainWindow::_getCacheDir()
 		QDir().mkpath(dir);
 	};
 
+	auto lamRootHome = [] () {
+		struct passwd *pwd = getpwuid(0);
+
+		return pwd ? QString(pwd->pw_dir) : QString("/root");
+	};
+
 	dir = getenv("KS_USER_CACHE_DIR");
 	if (!dir.isEmpty()) {
 		if (!QDir(dir).exists())
@@ -432,7 +438,7 @@ QString KsMainWindow::_getCacheDir()
 		dir += "/kernelshark";
 
 		if (geteuid() == 0)
-			dir.replace(QDir::homePath(), "/root");
+			dir.replace(QDir::homePath(), lamRootHome());
 
 		if (!QDir(dir).exists())
 			lamMakePath(false);
-- 
2.20.1




[Index of Archives]     [Linux USB Development]     [Linux USB Development]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux