fix ipc file cannot listen in linux

This commit is contained in:
geekgeekrun
2026-01-21 01:07:11 +08:00
parent a1f6dceedb
commit 0b50d2767a
2 changed files with 14 additions and 17 deletions

View File

@@ -44,14 +44,11 @@ if (process.platform === 'win32') {
}
else {
ipcSocketPath = path.join(tmpdir(), `${ipcSocketName}.sock`)
if (!fs.existsSync(ipcSocketPath)) {
if (process.platform === 'darwin' && !fs.existsSync(ipcSocketPath)) {
fs.writeFileSync(ipcSocketPath, '')
// 设置权限Unix
fs.chmodSync(ipcSocketPath, 0o777)
}
// 设置权限Unix
fs.chmodSync(
ipcSocketPath,
0o777
)
}
const workers = new Map(); // workerId -> { process, status, restartCount, socket, latestScreenshot, latestScreenshotAt }
@@ -443,13 +440,18 @@ new Promise((resolve, reject) => {
)
reject(err)
})
server.listen(ipcSocketPath, () => {
server.listen(ipcSocketPath, (err) => {
console.log(`守护进程服务器运行在端口 ${ipcSocketPath}`);
ipcWritePipe.write(
JSON.stringify({ type: 'DAEMON_READY' }),
(err) => void err
)
resolve(true)
if (!err) {
resolve(true)
}
else {
reject(err)
}
});
})

View File

@@ -18,18 +18,13 @@ export async function connectToDaemon() {
let isConnected = false
await new Promise((resolve, reject) => {
const ipcSocketName = process.env.GEEKGEEKRUND_PIPE_NAME
const ipcSocketPath = process.platform === 'win32'
const ipcSocketPath = process.platform === 'win32'
? `\\\\.\\pipe\\${ipcSocketName}`
: path.join(tmpdir(), `${ipcSocketName}.sock`)
if (process.platform !== 'win32' ) {
if (!fs.existsSync(ipcSocketPath)) {
fs.writeFileSync(ipcSocketPath, '')
}
if (process.platform === 'darwin' && !fs.existsSync(ipcSocketPath)) {
fs.writeFileSync(ipcSocketPath, '')
// 设置权限Unix
fs.chmodSync(
ipcSocketPath,
0o777
)
fs.chmodSync(ipcSocketPath, 0o777)
}
daemonClient.connect(ipcSocketPath, 'localhost', () => {
isConnected = true