]> git.ipfire.org Git - thirdparty/squid.git/commit
Fixed handling of shared memory left over by Squid crashes or bugs.
authorMarkus Mayer <code@mmayer.net>
Thu, 28 Jan 2016 01:30:37 +0000 (18:30 -0700)
committerAlex Rousskov <rousskov@measurement-factory.com>
Thu, 28 Jan 2016 01:30:37 +0000 (18:30 -0700)
commitf58b1eb469d981d65659c901b7348899b2d82cf5
tree0d296b274e1f55b9b4574a54c66d7cc944e573bb
parent765afa31e52b03b1257377684b36eed394451a4b
Fixed handling of shared memory left over by Squid crashes or bugs.

A Squid instance may inherit an old shared memory segment from the
previous instance as the result of either a Squid crash or an at-exit
cleanup bug. This change fixes two problems triggered by old segments:

1. After an earlier OS X fix (bug 3805; trunk r13947), Squid stopped
   initializing previously used shared memory. Uninitialzed memory
   resulted in subtle bugs and crashes.

2. When called for an old Squid shared memory segment, OS X
   ftruncate() fails with EINVAL, preventing Squid from starting when
   the old segment is still around.

   More specifically: Darwin ftruncate() calls pshm_truncate().
   pshm_truncate() checks if the PSHM_ALLOCATED flag is already set on
   the memory region. If the flag is set, the call fails with EINVAL.
   Otherwise, pshm_truncate() sets PSHM_ALLOCATED for the region.
   Since Squid must call ftruncate() to size every new segment, all
   old Squid segments have that flag set, preventing ftruncate() calls
   for old segments in newer Sqid instances from succeeding.

   [1] http://www.opensource.apple.com/source/xnu/xnu-3248.20.55/bsd/kern/posix_shm.c

To fix both problems, Squid now uses shm_open(O_EXCL) to detect the
existence of an old segment and remove/recreate it as needed.
src/ipc/mem/Segment.cc
src/ipc/mem/Segment.h