[Lldb-commits] [PATCH] D68316: [Host] Return the user's shell from GetDefaultShell

Jonas Devlieghere via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Tue Oct 1 23:03:45 PDT 2019


JDevlieghere updated this revision to Diff 222759.
JDevlieghere marked an inline comment as done.
JDevlieghere added a comment.

Check pointer returned by `getpwuid`.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D68316/new/

https://reviews.llvm.org/D68316

Files:
  lldb/lit/Host/Inputs/simple.c
  lldb/lit/Host/TestCustomShell.test
  lldb/source/Host/posix/HostInfoPosix.cpp


Index: lldb/source/Host/posix/HostInfoPosix.cpp
===================================================================
--- lldb/source/Host/posix/HostInfoPosix.cpp
+++ lldb/source/Host/posix/HostInfoPosix.cpp
@@ -113,7 +113,14 @@
 
 uint32_t HostInfoPosix::GetEffectiveGroupID() { return getegid(); }
 
-FileSpec HostInfoPosix::GetDefaultShell() { return FileSpec("/bin/sh"); }
+FileSpec HostInfoPosix::GetDefaultShell() {
+  if (const char *v = ::getenv("SHELL"))
+    return FileSpec(v);
+  if (const auto *pw = ::getpwuid(::geteuid()))
+    if (const char *v = pw->pw_shell)
+      return FileSpec(v);
+  return FileSpec("/bin/sh");
+}
 
 bool HostInfoPosix::ComputeSupportExeDirectory(FileSpec &file_spec) {
   return ComputePathRelativeToLibrary(file_spec, "/bin");
Index: lldb/lit/Host/TestCustomShell.test
===================================================================
--- /dev/null
+++ lldb/lit/Host/TestCustomShell.test
@@ -0,0 +1,5 @@
+# UNSUPPORTED: system-windows
+
+# RUN: %clang %S/Inputs/simple.c -g -o %t.out
+# RUN: SHELL=bogus %lldb %t.out -b -o 'run' 2>&1 | FileCheck %s
+# CHECK: error: shell expansion failed
Index: lldb/lit/Host/Inputs/simple.c
===================================================================
--- /dev/null
+++ lldb/lit/Host/Inputs/simple.c
@@ -0,0 +1 @@
+int main(int argc, char const *argv[]) { return 0; }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68316.222759.patch
Type: text/x-patch
Size: 1353 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20191002/354022e6/attachment.bin>


More information about the lldb-commits mailing list