(pidPath: string, info: DaemonLockInfo)
| 613 | * window between create and write. Exported for testing. |
| 614 | */ |
| 615 | export function acquireLockViaExclusiveOpen(pidPath: string, info: DaemonLockInfo): boolean { |
| 616 | let fd: number; |
| 617 | try { |
| 618 | fd = fs.openSync(pidPath, 'wx', 0o600); // O_CREAT | O_EXCL | O_WRONLY |
| 619 | } catch (err: unknown) { |
| 620 | if ((err as NodeJS.ErrnoException).code === 'EEXIST') return false; |
| 621 | throw err; |
| 622 | } |
| 623 | try { |
| 624 | fs.writeSync(fd, encodeLockInfo(info)); |
| 625 | } finally { |
| 626 | fs.closeSync(fd); |
| 627 | } |
| 628 | return true; |
| 629 | } |
| 630 | |
| 631 | /** |
| 632 | * Remove a stale pidfile, but only if it still names a dead process. Re-reads |
no test coverage detected