(pidPath: string, info: DaemonLockInfo)
| 583 | * window between create and write. Exported for testing. |
| 584 | */ |
| 585 | export function acquireLockViaExclusiveOpen(pidPath: string, info: DaemonLockInfo): boolean { |
| 586 | let fd: number; |
| 587 | try { |
| 588 | fd = fs.openSync(pidPath, 'wx', 0o600); // O_CREAT | O_EXCL | O_WRONLY |
| 589 | } catch (err: unknown) { |
| 590 | if ((err as NodeJS.ErrnoException).code === 'EEXIST') return false; |
| 591 | throw err; |
| 592 | } |
| 593 | try { |
| 594 | fs.writeSync(fd, encodeLockInfo(info)); |
| 595 | } finally { |
| 596 | fs.closeSync(fd); |
| 597 | } |
| 598 | return true; |
| 599 | } |
| 600 | |
| 601 | /** |
| 602 | * Remove a stale pidfile, but only if it still names a dead process. Re-reads |
no test coverage detected