]> git.ipfire.org Git - thirdparty/squid.git/blame - src/tools.h
NoNewGlobals for MapLabel (#1746)
[thirdparty/squid.git] / src / tools.h
CommitLineData
fc54b8d2 1/*
b8ae064d 2 * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
fc54b8d2 3 *
bbc27441
AJ
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
fc54b8d2
FC
7 */
8
bbc27441
AJ
9/* DEBUG: section 21 Misc Functions */
10
ff9d9458
FC
11#ifndef SQUID_SRC_TOOLS_H
12#define SQUID_SRC_TOOLS_H
fc54b8d2 13
65e41a45 14#include "sbuf/SBuf.h"
fc54b8d2
FC
15#include "typedefs.h"
16
17class MemBuf;
18
a8e49d54
FC
19extern int DebugSignal;
20
8b505ba9
AJ
21/// The Squid -n parameter service name.
22/// Default is APP_SHORTNAME ('squid').
23extern SBuf service_name;
24
8a648e8d
FC
25void parseEtcHosts(void);
26int getMyPort(void);
27void setUmask(mode_t mask);
28void strwordquote(MemBuf * mb, const char *str);
fc54b8d2 29
0a647ffb
AJ
30class Packable;
31
32/* a common objPackInto interface; used by debugObj */
33typedef void (*ObjPackMethod) (void *obj, Packable * p);
34
fc54b8d2 35/* packs, then prints an object using debugs() */
8a648e8d 36void debugObj(int section, int level, const char *label, void *obj, ObjPackMethod pm);
fc54b8d2 37
d4b95209
FC
38/// callback type for signal handlers
39typedef void SIGHDLR(int sig);
40
8a648e8d
FC
41const char *getMyHostname(void);
42const char *uniqueHostname(void);
8d03bdb4 43
8a648e8d
FC
44void death(int sig);
45void sigusr2_handle(int sig);
46void sig_child(int sig);
47void sig_shutdown(int sig); ///< handles shutdown notifications from kids
48void leave_suid(void);
49void enter_suid(void);
50void no_suid(void);
8a648e8d
FC
51void setMaxFD(void);
52void setSystemLimits(void);
53void squid_signal(int sig, SIGHDLR *, int flags);
8a648e8d
FC
54void keepCapabilities(void);
55void BroadcastSignalIfAny(int& sig);
561076e2 56
5bed43d6 57/// whether the current process is the parent of all other Squid processes
8a648e8d 58bool IamMasterProcess();
5bed43d6
FC
59/**
60 * whether the current process is dedicated to doing things that only
61 * a single process should do, such as PID file maintenance and WCCP
62 */
8a648e8d 63bool IamPrimaryProcess();
5bed43d6 64/// whether the current process coordinates worker processes
8a648e8d 65bool IamCoordinatorProcess();
5bed43d6 66/// whether the current process handles HTTP transactions and such
8a648e8d 67bool IamWorkerProcess();
5bed43d6 68/// whether the current process is dedicated to managing a cache_dir
8a648e8d 69bool IamDiskProcess();
5bed43d6 70/// Whether we are running in daemon mode
8a648e8d 71bool InDaemonMode(); // try using specific Iam*() checks above first
5bed43d6 72/// Whether there should be more than one worker process running
8a648e8d 73bool UsingSmp(); // try using specific Iam*() checks above first
5bed43d6 74/// number of Kid processes as defined in src/ipc/Kid.h
8a648e8d 75int NumberOfKids();
5bed43d6 76/// a string describing this process roles such as worker or coordinator
1fdc4f42 77SBuf ProcessRoles();
5bed43d6 78
8a648e8d 79void debug_trap(const char *);
561076e2 80
8a648e8d 81void logsFlush(void);
a8e49d54 82
8a648e8d
FC
83void squid_getrusage(struct rusage *r);
84double rusage_cputime(struct rusage *r);
85int rusage_maxrss(struct rusage *r);
86int rusage_pagefaults(struct rusage *r);
87void releaseServerSockets(void);
88void PrintRusage(void);
89void dumpMallocStats(void);
a8e49d54 90
dbf55289 91typedef int PidStatus;
dbf55289
CT
92
93/**
94 * Compatibility wrapper function for waitpid
2f8abb64 95 * \pid the pid of child process to wait for.
dbf55289
CT
96 * \param status the exit status returned by waitpid
97 * \param flags WNOHANG or 0
98 */
99pid_t WaitForOnePid(pid_t pid, PidStatus &status, int flags);
100
101/**
102 * Wait for state changes in any of the kid processes.
103 * Equivalent to waitpid(-1, ...) system call
104 * \param status the exit status returned by waitpid
105 * \param flags WNOHANG or 0
106 */
107inline pid_t WaitForAnyPid(PidStatus &status, int flags)
108{
109 return WaitForOnePid(-1, status, flags);
110}
111
d9cb4f7a 112#if _SQUID_WINDOWS_ || _SQUID_MINGW_
e99fa721
EB
113/// xstrerror(errno) equivalent for Windows errors returned by GetLastError()
114SBuf WindowsErrorMessage(DWORD errorId);
d9cb4f7a 115#endif // _SQUID_WINDOWS_ || _SQUID_MINGW_
e99fa721 116
ff9d9458 117#endif /* SQUID_SRC_TOOLS_H */
f53969cc 118