]> git.ipfire.org Git - thirdparty/squid.git/commit
Create PID file ASAP, before the shared memory segments.
authorEduard Bagdasaryan <eduard.bagdasaryan@measurement-factory.com>
Tue, 23 May 2017 08:45:16 +0000 (20:45 +1200)
committerAmos Jeffries <squid3@treenet.co.nz>
Tue, 23 May 2017 08:45:16 +0000 (20:45 +1200)
commit01ac0a5b7fe21a1049a65e8b91d7fe2198cdb051
tree85c6fa169563590cfa279c3c49ab44b5322575a1
parente99fa721fc2a16026d284336fabe66db4518c3e5
Create PID file ASAP, before the shared memory segments.

PID file is created right after configuration finalization, before the
allocation for any shared memory segments.

Late PID file creation allowed N+1 concurrent Squid instances to create
the same set of shared segments (overwriting each other segments),
resulting in extremely confusing havoc because the N instances would
later lose the race for the PID file (or some other critical resource)
creation and remove the segments. If that removal happened before a kid
of the single surviving instance started, that kid would fail to start
with open() errors in Segment.cc because the shared segment it tries to
open would be gone. Otherwise, that kid would fail to _restart_ after
any unrelated failures (possibly many days after the conflict), with
same errors, for the same reason.

Shared state corruption was also possible if different kids (of the
winning instance) opened (and started using) segments created (and
initialized) by different instances.

Situations with N+1 concurrent Squid instances are not uncommon because
many Squid service management scripts (or manual admin commands!)
* do not check whether another Squid is already running and/or
* incorrectly assume that "squid -z" does not daemonize.

This change finally makes starting N+1 Squid instances safe (AFAIK).

Also made daemonized and non-daemonized Squid create the PID file at the
same startup stage, reducing inconsistencies between the two modes.
src/main.cc