@andersbakken/fisk 5.0.3 → 5.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/daemon/fisk-daemon.js +37 -20
- package/package.json +1 -1
package/daemon/fisk-daemon.js
CHANGED
|
@@ -3434,26 +3434,38 @@ var output = {
|
|
|
3434
3434
|
var fs = libExports;
|
|
3435
3435
|
|
|
3436
3436
|
// systemd socket activation: the first passed fd is at SD_LISTEN_FDS_START (3).
|
|
3437
|
-
// See sd_listen_fds(3).
|
|
3438
|
-
//
|
|
3439
|
-
//
|
|
3440
|
-
//
|
|
3441
|
-
//
|
|
3437
|
+
// See sd_listen_fds(3). systemd sets LISTEN_PID to the PID it should be
|
|
3438
|
+
// consumed by; a child process must be exec'd (not fork+exec of a wrapper)
|
|
3439
|
+
// so its own pid matches. We fail hard on any mismatch rather than silently
|
|
3440
|
+
// falling back to path binding, because that fallback would unlink the
|
|
3441
|
+
// systemd-owned socket file and re-create a new inode, defeating the whole
|
|
3442
|
+
// point of activation (and breaking every docker container that bind-mounted
|
|
3443
|
+
// the socket file).
|
|
3442
3444
|
const SD_LISTEN_FDS_START = 3;
|
|
3443
3445
|
function systemdListenFd() {
|
|
3444
|
-
const
|
|
3445
|
-
const
|
|
3446
|
-
|
|
3447
|
-
|
|
3448
|
-
|
|
3449
|
-
|
|
3450
|
-
|
|
3451
|
-
|
|
3452
|
-
|
|
3453
|
-
|
|
3454
|
-
|
|
3455
|
-
|
|
3456
|
-
|
|
3446
|
+
const pidRaw = process.env.LISTEN_PID;
|
|
3447
|
+
const fdsRaw = process.env.LISTEN_FDS;
|
|
3448
|
+
// Consume the activation env so any subprocess we spawn does not inherit
|
|
3449
|
+
// stale LISTEN_PID/LISTEN_FDS. sd_listen_fds_with_names(3) recommends
|
|
3450
|
+
// unsetenv after use.
|
|
3451
|
+
delete process.env.LISTEN_PID;
|
|
3452
|
+
delete process.env.LISTEN_FDS;
|
|
3453
|
+
delete process.env.LISTEN_FDNAMES;
|
|
3454
|
+
if (!pidRaw && !fdsRaw) {
|
|
3455
|
+
return "none";
|
|
3456
|
+
}
|
|
3457
|
+
if (!pidRaw || !fdsRaw) {
|
|
3458
|
+
return "mismatch";
|
|
3459
|
+
}
|
|
3460
|
+
const pid = Number(pidRaw);
|
|
3461
|
+
const count = Number(fdsRaw);
|
|
3462
|
+
if (!Number.isInteger(pid) || !Number.isInteger(count) || count < 1) {
|
|
3463
|
+
return "mismatch";
|
|
3464
|
+
}
|
|
3465
|
+
if (pid !== process.pid) {
|
|
3466
|
+
return "mismatch";
|
|
3467
|
+
}
|
|
3468
|
+
return { fd: SD_LISTEN_FDS_START };
|
|
3457
3469
|
}
|
|
3458
3470
|
class Server extends EventEmitter__default["default"] {
|
|
3459
3471
|
constructor(option, common) {
|
|
@@ -3486,8 +3498,13 @@ class Server extends EventEmitter__default["default"] {
|
|
|
3486
3498
|
}
|
|
3487
3499
|
}
|
|
3488
3500
|
listen() {
|
|
3489
|
-
const
|
|
3490
|
-
if (
|
|
3501
|
+
const activation = systemdListenFd();
|
|
3502
|
+
if (activation === "mismatch") {
|
|
3503
|
+
console.error("fisk-daemon: LISTEN_FDS/LISTEN_PID present but do not match our pid. Refusing to fall back to path binding -- exiting so systemd can restart us with correct activation.");
|
|
3504
|
+
process.exit(1);
|
|
3505
|
+
}
|
|
3506
|
+
if (activation !== "none") {
|
|
3507
|
+
const inheritedFd = activation.fd;
|
|
3491
3508
|
this._activated = true;
|
|
3492
3509
|
if (this.debug) {
|
|
3493
3510
|
console.log("Server::listen using systemd-activated fd", inheritedFd);
|