]> git.ipfire.org Git - thirdparty/squid.git/commit
Create PID file ASAP, before the shared memory segments.
authorEduard Bagdasaryan <eduard.bagdasaryan@measurement-factory.com>
Mon, 29 May 2017 01:50:59 +0000 (13:50 +1200)
committerAmos Jeffries <squid3@treenet.co.nz>
Mon, 29 May 2017 01:50:59 +0000 (13:50 +1200)
commit7e0b649dfc37f91ca020e1abbb83888702b41cd3
tree201c1368fd302909478686468571b277606a6a28
parent2a5f44bee7f1c2be9863dbc61b879d96eeda2af2
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