* [PATCH v2] kernel-shark: Retrieve the home of root using getpwent()
@ 2019-12-12 13:45 Yordan Karadzhov (VMware)
0 siblings, 0 replies; only message in thread
From: Yordan Karadzhov (VMware) @ 2019-12-12 13:45 UTC (permalink / raw)
To: rostedt; +Cc: linux-trace-devel, Yordan Karadzhov (VMware), Slavomir Kaslev
Do not assume that root is always at "/root". Instead use getpwent(void)
and searche for user id of 0. Return the home path for that user. On any
error just quietly default back to "/root".
Suggested-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Suggested-by: Slavomir Kaslev <kaslevs@vmware.com>
Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
---
kernel-shark/src/KsMainWindow.cpp | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/kernel-shark/src/KsMainWindow.cpp b/kernel-shark/src/KsMainWindow.cpp
index bd6c338..31224ed 100644
--- a/kernel-shark/src/KsMainWindow.cpp
+++ b/kernel-shark/src/KsMainWindow.cpp
@@ -422,6 +422,20 @@ QString KsMainWindow::_getCacheDir()
QDir().mkpath(dir);
};
+ auto lamRootHome = [] () {
+ QString home("/root");
+ struct passwd *pwd;
+
+ while ((pwd = getpwent()) != NULL) {
+ if (pwd->pw_uid == 0) {
+ home = pwd->pw_dir;
+ break;
+ }
+ }
+
+ return home;
+ };
+
dir = getenv("KS_USER_CACHE_DIR");
if (!dir.isEmpty()) {
if (!QDir(dir).exists())
@@ -432,7 +446,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
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2019-12-12 13:46 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-12 13:45 [PATCH v2] kernel-shark: Retrieve the home of root using getpwent() Yordan Karadzhov (VMware)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).