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.
This commit is contained in:
Bananymous 2023-09-29 19:20:48 +03:00
parent 96b1186c19
commit 6304388100
1 changed files with 11 additions and 5 deletions

View File

@ -700,12 +700,18 @@ BAN::String get_prompt()
break; break;
} }
case 'u': case 'u':
{
static char* username = nullptr;
if (username == nullptr)
{ {
auto* passwd = getpwuid(geteuid()); auto* passwd = getpwuid(geteuid());
if (passwd == nullptr) if (passwd == nullptr)
break; break;
MUST(prompt.append(passwd->pw_name)); username = new char[strlen(passwd->pw_name) + 1];
strcpy(username, passwd->pw_name);
endpwent(); endpwent();
}
MUST(prompt.append(username));
break; break;
} }
case 'h': case 'h':