]> git.ipfire.org Git - thirdparty/squid.git/blob - src/tools.h
Merged from trunk
[thirdparty/squid.git] / src / tools.h
1 /*
2 * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
3 *
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.
7 */
8
9 /* DEBUG: section 21 Misc Functions */
10
11 #ifndef SQUID_TOOLS_H_
12 #define SQUID_TOOLS_H_
13
14 #include "Packer.h"
15 #include "SBuf.h"
16 #include "SquidString.h"
17 #include "typedefs.h"
18
19 class MemBuf;
20
21 extern int DebugSignal;
22
23 /// The Squid -n parameter service name.
24 /// Default is APP_SHORTNAME ('squid').
25 extern SBuf service_name;
26
27 void kb_incr(kb_t *, size_t);
28 void parseEtcHosts(void);
29 int getMyPort(void);
30 void setUmask(mode_t mask);
31 void strwordquote(MemBuf * mb, const char *str);
32
33 /* packs, then prints an object using debugs() */
34 void debugObj(int section, int level, const char *label, void *obj, ObjPackMethod pm);
35
36 const char *getMyHostname(void);
37 const char *uniqueHostname(void);
38
39 void death(int sig);
40 void sigusr2_handle(int sig);
41 void sig_child(int sig);
42 void sig_shutdown(int sig); ///< handles shutdown notifications from kids
43 void leave_suid(void);
44 void enter_suid(void);
45 void no_suid(void);
46 void writePidFile(void);
47 void removePidFile();
48 void setMaxFD(void);
49 void setSystemLimits(void);
50 void squid_signal(int sig, SIGHDLR *, int flags);
51 pid_t readPidFile(void);
52 void keepCapabilities(void);
53 void BroadcastSignalIfAny(int& sig);
54
55 /// whether the current process is the parent of all other Squid processes
56 bool IamMasterProcess();
57 /**
58 * whether the current process is dedicated to doing things that only
59 * a single process should do, such as PID file maintenance and WCCP
60 */
61 bool IamPrimaryProcess();
62 /// whether the current process coordinates worker processes
63 bool IamCoordinatorProcess();
64 /// whether the current process handles HTTP transactions and such
65 bool IamWorkerProcess();
66 /// whether the current process is dedicated to managing a cache_dir
67 bool IamDiskProcess();
68 /// Whether we are running in daemon mode
69 bool InDaemonMode(); // try using specific Iam*() checks above first
70 /// Whether there should be more than one worker process running
71 bool UsingSmp(); // try using specific Iam*() checks above first
72 /// number of Kid processes as defined in src/ipc/Kid.h
73 int NumberOfKids();
74 /// a string describing this process roles such as worker or coordinator
75 String ProcessRoles();
76
77 void debug_trap(const char *);
78
79 void logsFlush(void);
80
81 void squid_getrusage(struct rusage *r);
82 double rusage_cputime(struct rusage *r);
83 int rusage_maxrss(struct rusage *r);
84 int rusage_pagefaults(struct rusage *r);
85 void releaseServerSockets(void);
86 void PrintRusage(void);
87 void dumpMallocStats(void);
88
89 #if _SQUID_NEXT_
90 typedef union wait PidStatus;
91 #else
92 typedef int PidStatus;
93 #endif
94
95 /**
96 * Compatibility wrapper function for waitpid
97 * \pid the pid of child proccess to wait for.
98 * \param status the exit status returned by waitpid
99 * \param flags WNOHANG or 0
100 */
101 pid_t WaitForOnePid(pid_t pid, PidStatus &status, int flags);
102
103 /**
104 * Wait for state changes in any of the kid processes.
105 * Equivalent to waitpid(-1, ...) system call
106 * \param status the exit status returned by waitpid
107 * \param flags WNOHANG or 0
108 */
109 inline pid_t WaitForAnyPid(PidStatus &status, int flags)
110 {
111 return WaitForOnePid(-1, status, flags);
112 }
113
114 #endif /* SQUID_TOOLS_H_ */
115