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