Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
17019eb
Update Instance.h
ankor2023 Mar 13, 2025
afe4abb
Update Instance.cc
ankor2023 Mar 13, 2025
6b5df31
Update Segment.cc
ankor2023 Mar 13, 2025
3a11795
Update Instance.cc
ankor2023 Mar 13, 2025
de275b5
Update Port.cc
ankor2023 Mar 13, 2025
250173a
Update Port.cc
ankor2023 Mar 13, 2025
e23bf80
Update Instance.cc
ankor2023 Mar 13, 2025
d2c138d
Update Port.cc
ankor2023 Mar 13, 2025
33d1e8a
Update Segment.cc
ankor2023 Mar 13, 2025
bab5435
Update Makefile.am
ankor2023 Mar 14, 2025
aaf0516
Update testRock.cc
ankor2023 Mar 14, 2025
beffd75
Update testUfs.cc
ankor2023 Mar 14, 2025
85b36ee
Update testHttpRange.cc
ankor2023 Mar 14, 2025
b176333
Update testHttpRequest.cc
ankor2023 Mar 14, 2025
c933d7f
Update testCacheManager.cc
ankor2023 Mar 14, 2025
0690091
Update Makefile.am
ankor2023 Mar 14, 2025
ce8b48d
Update Makefile.am
ankor2023 Mar 14, 2025
4844330
Update testHttpReply.cc
ankor2023 Mar 14, 2025
07ff1b2
Update testStore.cc
ankor2023 Mar 14, 2025
42991fa
Update testDiskIO.cc
ankor2023 Mar 14, 2025
cf340d8
Update Makefile.am
ankor2023 Mar 14, 2025
2bae8a5
Update Makefile.am
ankor2023 Mar 14, 2025
d519b7c
Update Instance.cc
ankor2023 Mar 14, 2025
a48d771
Update Instance.h
ankor2023 Mar 14, 2025
22ba2fd
Update Segment.cc
ankor2023 Mar 14, 2025
1dd8c21
Update Port.cc
ankor2023 Mar 14, 2025
79b9745
Some changes to fix building problems
ankor2023 Mar 17, 2025
5c399a3
Remove '-' to shorten the file name
ankor2023 Mar 17, 2025
1a513aa
Comment corrected
ankor2023 Mar 17, 2025
ca16337
Changes for passing source-maintenance tests
ankor2023 Mar 17, 2025
5780e8d
fixup: Removed now-duped/obsolete CONTRIBUTORS entry
rousskov Apr 22, 2025
534cde0
fixup: Polished GetPidFilenameHash() description
rousskov Apr 22, 2025
9bd813b
fixup: Remove an unnecessary word from the new function name
rousskov Apr 22, 2025
2c108c1
fixup: Preserve the empty line at the end of the source file
rousskov Apr 22, 2025
9128fca
fixup: Do not overexpose Instance.h users to SBuf details
rousskov Apr 22, 2025
f36ef80
fixup: Avoid unrelated cache_key type
rousskov Apr 22, 2025
0d168a7
fixup: Undo out-of-scope code formatting improvement
rousskov Apr 22, 2025
21e2706
fixup: Fix Debug::StopCacheLogUse() stubbing
rousskov Apr 22, 2025
b1bdc7e
Add Instance API stub
rousskov Apr 22, 2025
1057873
fixup: Undo changes made unnecessary by the previous branch commit
rousskov Apr 22, 2025
5247147
fixup: Do not increase name-generating code duplication
rousskov Apr 22, 2025
9f56cae
fixup: Remove duplicated variable
rousskov Apr 22, 2025
bcc0413
fixup: Deduplicated risky code and removed magic constants
rousskov Apr 23, 2025
f0c7e9b
Reuse existing printing code instead of writing custom one
rousskov Apr 23, 2025
005ecc1
Revert "Reuse existing printing code instead of writing custom one"
rousskov Apr 23, 2025
69af79f
Separate hash chars from service_name
rousskov Apr 23, 2025
27468e8
fixup: Use current master/v8 boilerplate
rousskov Apr 23, 2025
8bc19f4
fixup: Mimic real instance name format when STUBbing
rousskov Apr 23, 2025
ec45b34
fixup: Minor polishing touches
rousskov Apr 23, 2025
12da372
fixup: Missed "const"
rousskov Apr 23, 2025
5a8e94b
fixup: Explain why we do not add a dash after the hash
rousskov Apr 23, 2025
59a2ba1
fixup: Revert "Removed now-duped/obsolete CONTRIBUTORS entry"
rousskov Apr 23, 2025
a096b0a
Restore "Removed now-duped/obsolete CONTRIBUTORS entry"
rousskov Apr 23, 2025
8407762
fixup: Avoid Squid qualifiers inside Squid
rousskov Apr 28, 2025
8878c67
Merge branch 'master' into prevent-instance-shared-memory-segments-cl…
yadij Jul 2, 2025
5c28433
Untested temporary workaround for testRock ENAMETOOLONG on MacOS
rousskov Jul 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Thank you!
Andrew Tridgell
Andrey <[email protected]>
Andrey Shorin <[email protected]>
ankor2023 <138755079+ankor2023@users.noreply.github.com>
Ankor <ankor2023@gmail.com>
Anonymous <[email protected]>
Anonymous <[email protected]>
Anonymous Pootle User
Expand Down
41 changes: 41 additions & 0 deletions src/Instance.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "debug/Messages.h"
#include "fs_io.h"
#include "Instance.h"
#include "md5.h"
#include "parser/Tokenizer.h"
#include "sbuf/Stream.h"
#include "SquidConfig.h"
Expand Down Expand Up @@ -222,3 +223,43 @@ Instance::WriteOurPid()
debugs(50, Important(23), "Created " << TheFile);
}

/// A hash that is likely to be unique across instances running on the same host
/// because such concurrent instances should use unique PID filenames.
/// All instances with disabled PID file maintenance have the same hash value.
/// \returns a 4-character string suitable for use in file names and similar contexts
static SBuf
PidFilenameHash()
{
uint8_t hash[SQUID_MD5_DIGEST_LENGTH];

SquidMD5_CTX ctx;
SquidMD5Init(&ctx);
const auto name = PidFilenameCalc();
SquidMD5Update(&ctx, name.rawContent(), name.length());
SquidMD5Final(hash, &ctx);

// converts raw hash byte at a given position to a filename-suitable character
const auto hashAt = [&hash](const size_t idx) {
const auto safeChars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
return safeChars[hash[idx] % strlen(safeChars)];
};

SBuf buf;
buf.appendf("%c%c%c%c", hashAt(0), hashAt(1), hashAt(2), hashAt(3));
return buf;
}

SBuf
Instance::NamePrefix(const char * const head, const char * const tail)
{
SBuf buf(head);
buf.append(service_name);
buf.append("-");
buf.append(PidFilenameHash());
if (tail) {
// TODO: Remove leading "-" from callers and explicitly add it here.
buf.append(tail);
}
return buf;
}

10 changes: 10 additions & 0 deletions src/Instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#ifndef SQUID_SRC_INSTANCE_H
#define SQUID_SRC_INSTANCE_H

#include "sbuf/forward.h"

#if HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
Expand All @@ -30,6 +32,14 @@ void WriteOurPid();
/// Throws if PID file maintenance is disabled.
pid_t Other();

/// A service_name-derived string that is likely to be unique across all Squid
/// instances concurrently running on the same host (as long as they do not
/// disable PID file maintenance).
/// \param head is used at the beginning of the generated name
/// \param tail is used at the end of the generated name (when not nil)
/// \returns a head-...tail string suitable for making file and shm segment names
SBuf NamePrefix(const char *head, const char *tail = nullptr);

} // namespace Instance

#endif /* SQUID_SRC_INSTANCE_H */
Expand Down
8 changes: 8 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -1032,6 +1032,7 @@ tests_testRock_SOURCES = \
HttpHeaderTools.h \
HttpReply.cc \
tests/stub_HttpRequest.cc \
tests/stub_Instance.cc \
LogTags.cc \
MasterXaction.cc \
MasterXaction.h \
Expand Down Expand Up @@ -1202,6 +1203,7 @@ tests_testUfs_SOURCES = \
HttpHeaderTools.h \
HttpReply.cc \
tests/stub_HttpRequest.cc \
tests/stub_Instance.cc \
LogTags.cc \
MasterXaction.cc \
MasterXaction.h \
Expand Down Expand Up @@ -1374,6 +1376,7 @@ tests_testStore_SOURCES = \
HttpHeaderTools.h \
tests/stub_HttpReply.cc \
tests/stub_HttpRequest.cc \
tests/stub_Instance.cc \
MasterXaction.cc \
MasterXaction.h \
MemBuf.cc \
Expand Down Expand Up @@ -1537,6 +1540,7 @@ tests_testDiskIO_SOURCES = \
HttpHeaderTools.h \
HttpReply.cc \
tests/stub_HttpRequest.cc \
tests/stub_Instance.cc \
LogTags.cc \
MasterXaction.cc \
MasterXaction.h \
Expand Down Expand Up @@ -1800,6 +1804,7 @@ tests_testHttpRange_SOURCES = \
HttpReply.cc \
HttpRequest.cc \
tests/stub_HttpUpgradeProtocolAccess.cc \
tests/stub_Instance.cc \
IoStats.h \
tests/stub_IpcIoFile.cc \
LogTags.cc \
Expand Down Expand Up @@ -2060,6 +2065,7 @@ tests_testHttpReply_SOURCES = \
tests/testHttpReply.cc \
HttpReply.h \
tests/stub_HttpRequest.cc \
tests/stub_Instance.cc \
MasterXaction.cc \
MasterXaction.h \
MemBuf.cc \
Expand Down Expand Up @@ -2187,6 +2193,7 @@ tests_testHttpRequest_SOURCES = \
tests/testHttpRequest.cc \
tests/testHttpRequestMethod.cc \
tests/stub_HttpUpgradeProtocolAccess.cc \
tests/stub_Instance.cc \
IoStats.h \
tests/stub_IpcIoFile.cc \
LogTags.cc \
Expand Down Expand Up @@ -2484,6 +2491,7 @@ tests_testCacheManager_SOURCES = \
HttpReply.cc \
HttpRequest.cc \
tests/stub_HttpUpgradeProtocolAccess.cc \
tests/stub_Instance.cc \
IoStats.h \
tests/stub_IpcIoFile.cc \
LogTags.cc \
Expand Down
10 changes: 4 additions & 6 deletions src/ipc/Port.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "comm/Connection.h"
#include "comm/Read.h"
#include "CommCalls.h"
#include "Instance.h"
#include "ipc/Port.h"
#include "sbuf/Stream.h"
#include "tools.h"
Expand Down Expand Up @@ -52,9 +53,8 @@ bool Ipc::Port::doneAll() const
String Ipc::Port::MakeAddr(const char* processLabel, int id)
{
assert(id >= 0);
String addr = channelPathPfx;
addr.append(service_name);
addr.append(processLabel);
String addr;
addr.append(Instance::NamePrefix(channelPathPfx, processLabel));
addr.append('-');
addr.append(xitoa(id));
addr.append(".ipc");
Expand All @@ -66,9 +66,7 @@ Ipc::Port::CoordinatorAddr()
{
static String coordinatorAddr;
if (!coordinatorAddr.size()) {
coordinatorAddr= channelPathPfx;
coordinatorAddr.append(service_name);
coordinatorAddr.append(coordinatorAddrLabel);
coordinatorAddr.append(Instance::NamePrefix(channelPathPfx, coordinatorAddrLabel));
coordinatorAddr.append(".ipc");
}
return coordinatorAddr;
Expand Down
4 changes: 2 additions & 2 deletions src/ipc/mem/Segment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "compat/shm.h"
#include "debug/Stream.h"
#include "fatal.h"
#include "Instance.h"
#include "ipc/mem/Segment.h"
#include "sbuf/SBuf.h"
#include "SquidConfig.h"
Expand Down Expand Up @@ -277,8 +278,7 @@ Ipc::Mem::Segment::GenerateName(const char *id)
if (name[name.size()-1] != '/')
name.append('/');
} else {
name.append('/');
name.append(service_name);
name.append(Instance::NamePrefix("/"));
name.append('-');
}

Expand Down
1 change: 1 addition & 0 deletions src/tests/Stub.am
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ STUB_SOURCE = \
tests/stub_HttpReply.cc \
tests/stub_HttpRequest.cc \
tests/stub_HttpUpgradeProtocolAccess.cc \
tests/stub_Instance.cc \
tests/stub_IpcIoFile.cc \
tests/stub_MemBuf.cc \
tests/stub_MemObject.cc \
Expand Down
20 changes: 20 additions & 0 deletions src/tests/stub_Instance.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright (C) 1996-2025 The Squid Software Foundation and contributors
*
* Squid software is distributed under GPLv2+ license and includes
* contributions from numerous individuals and organizations.
* Please see the COPYING and CONTRIBUTORS files for details.
*/

#include "squid.h"
#include "Instance.h"
#include "sbuf/SBuf.h"

#define STUB_API "Instance.cc"
#include "tests/STUB.h"

void Instance::ThrowIfAlreadyRunning() STUB
void Instance::WriteOurPid() STUB
pid_t Instance::Other() STUB_RETVAL({})
SBuf Instance::NamePrefix(const char *, const char *) STUB_RETVAL_NOP(SBuf("squid-0"))