From 6304388100812413146e98c2a8cd8a513e80aaf8 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Fri, 29 Sep 2023 19:20:48 +0300 Subject: [PATCH] Shell: Quick fix to not freeze for multiple seconds When sync is writing to disk, it reserves whole disk to itself. This commit makes Shell to read username only once from getpwuid(). We used to get username every time prompt was printed. --- userspace/Shell/main.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/userspace/Shell/main.cpp b/userspace/Shell/main.cpp index b4036763aa..279c14c22a 100644 --- a/userspace/Shell/main.cpp +++ b/userspace/Shell/main.cpp @@ -701,11 +701,17 @@ BAN::String get_prompt() } case 'u': { - auto* passwd = getpwuid(geteuid()); - if (passwd == nullptr) - break; - MUST(prompt.append(passwd->pw_name)); - endpwent(); + static char* username = nullptr; + if (username == nullptr) + { + auto* passwd = getpwuid(geteuid()); + if (passwd == nullptr) + break; + username = new char[strlen(passwd->pw_name) + 1]; + strcpy(username, passwd->pw_name); + endpwent(); + } + MUST(prompt.append(username)); break; } case 'h':