summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2015-09-15 13:32:26 +0100
committerMaxime Coste <frrrwww@gmail.com>2015-09-15 13:32:26 +0100
commit85918d9f15d1a454ec9bebb091eec7d563c162c7 (patch)
tree0cd4ea725204648f268e73e3f4959cd6ee786b4c /src
parent0338c0f43702b66d4279eb63a5a81f269420752d (diff)
use getpwuid(geteuid())->pw_name rather than getlogin()
getlogin() can fail when stdin is not a tty on certain configuration as it needs to find a controling terminal.
Diffstat (limited to 'src')
-rw-r--r--src/main.cc3
-rw-r--r--src/remote.cc5
2 files changed, 5 insertions, 3 deletions
diff --git a/src/main.cc b/src/main.cc
index d11fa828..938097ce 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -29,6 +29,7 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
+#include <pwd.h>
using namespace Kakoune;
@@ -598,7 +599,7 @@ int main(int argc, char* argv[])
if (parser.get_switch("l"))
{
- for (auto& file : list_files(format("/tmp/kakoune/{}/", getlogin())))
+ for (auto& file : list_files(format("/tmp/kakoune/{}/", getpwuid(geteuid())->pw_name)))
write_stdout(format("{}\n", file));
return 0;
}
diff --git a/src/remote.cc b/src/remote.cc
index fd043f9a..1c8795d3 100644
--- a/src/remote.cc
+++ b/src/remote.cc
@@ -13,6 +13,7 @@
#include <sys/un.h>
#include <sys/wait.h>
#include <unistd.h>
+#include <pwd.h>
#include <fcntl.h>
@@ -411,7 +412,7 @@ static sockaddr_un session_addr(StringView session)
{
sockaddr_un addr;
addr.sun_family = AF_UNIX;
- format_to(addr.sun_path, "/tmp/kakoune/{}/{}", getlogin(), session);
+ format_to(addr.sun_path, "/tmp/kakoune/{}/{}", getpwuid(geteuid())->pw_name, session);
return addr;
}
@@ -631,7 +632,7 @@ Server::Server(String session_name)
void Server::close_session()
{
char socket_file[128];
- format_to(socket_file, "/tmp/kakoune/{}/{}", getlogin(), m_session);
+ format_to(socket_file, "/tmp/kakoune/{}/{}", getpwuid(geteuid())->pw_name, m_session);
unlink(socket_file);
m_listener->close_fd();
m_listener.reset();