(pidPath: string, info: DaemonLockInfo)
| 904 | * window between create and write. Exported for testing. |
| 905 | */ |
| 906 | export function acquireLockViaExclusiveOpen(pidPath: string, info: DaemonLockInfo): boolean { |
| 907 | let fd: number; |
| 908 | try { |
| 909 | fd = fs.openSync(pidPath, 'wx', 0o600); // O_CREAT | O_EXCL | O_WRONLY |
| 910 | } catch (err: unknown) { |
| 911 | if ((err as NodeJS.ErrnoException).code === 'EEXIST') return false; |
| 912 | throw err; |
| 913 | } |
| 914 | try { |
| 915 | fs.writeSync(fd, encodeLockInfo(info)); |
| 916 | } finally { |
| 917 | fs.closeSync(fd); |
| 918 | } |
| 919 | return true; |
| 920 | } |
| 921 | |
| 922 | /** |
| 923 | * Remove a stale pidfile. Re-reads the file immediately before unlinking so a |
no test coverage detected