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