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