mirror of
https://github.com/oven-sh/bun
synced 2026-02-15 13:22:07 +00:00
Fix edgecase with socketpair() impacting shell and spawn (#15725)
This commit is contained in:
@@ -26,7 +26,7 @@ import {
|
||||
getBuildUrl,
|
||||
getEnv,
|
||||
getFileUrl,
|
||||
getLoggedInUserCount,
|
||||
getLoggedInUserCountOrDetails,
|
||||
getShell,
|
||||
getWindowsExitReason,
|
||||
isBuildkite,
|
||||
@@ -1499,7 +1499,7 @@ export async function main() {
|
||||
|
||||
let waitForUser = false;
|
||||
while (isCI) {
|
||||
const userCount = getLoggedInUserCount();
|
||||
const userCount = getLoggedInUserCountOrDetails();
|
||||
if (!userCount) {
|
||||
if (waitForUser) {
|
||||
!isQuiet && console.log("No users logged in, exiting runner...");
|
||||
@@ -1509,7 +1509,11 @@ export async function main() {
|
||||
|
||||
if (!waitForUser) {
|
||||
startGroup("Summary");
|
||||
console.warn(`Found ${userCount} users logged in, keeping the runner alive until logout...`);
|
||||
if (typeof userCount === "number") {
|
||||
console.warn(`Found ${userCount} users logged in, keeping the runner alive until logout...`);
|
||||
} else {
|
||||
console.warn(userCount);
|
||||
}
|
||||
waitForUser = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -2688,7 +2688,7 @@ export function printEnvironment() {
|
||||
/**
|
||||
* @returns {number | undefined}
|
||||
*/
|
||||
export function getLoggedInUserCount() {
|
||||
export function getLoggedInUserCountOrDetails() {
|
||||
if (isWindows) {
|
||||
const pwsh = which(["pwsh", "powershell"]);
|
||||
if (pwsh) {
|
||||
@@ -2705,7 +2705,31 @@ export function getLoggedInUserCount() {
|
||||
|
||||
const { error, stdout } = spawnSync(["who"]);
|
||||
if (!error) {
|
||||
return stdout.split("\n").filter(line => /tty|pts/i.test(line)).length;
|
||||
const users = stdout
|
||||
.split("\n")
|
||||
.filter(line => /tty|pts/i.test(line))
|
||||
.map(line => {
|
||||
// who output format: username terminal date/time (ip)
|
||||
const [username, terminal, datetime, ip] = line.split(/\s+/);
|
||||
return {
|
||||
username,
|
||||
terminal,
|
||||
datetime,
|
||||
ip: (ip || "").replace(/[()]/g, ""), // Remove parentheses from IP
|
||||
};
|
||||
});
|
||||
|
||||
if (users.length === 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
let message = users.length + " currently logged in users:";
|
||||
|
||||
for (const user of users) {
|
||||
message += `\n- ${user.username} on ${user.terminal} since ${user.datetime}${user.ip ? ` from ${user.ip}` : ""}`;
|
||||
}
|
||||
|
||||
return message;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user