]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/tools.h
2 * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
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.
9 /* DEBUG: section 21 Misc Functions */
11 #ifndef SQUID_TOOLS_H_
12 #define SQUID_TOOLS_H_
14 #include "sbuf/SBuf.h"
19 extern int DebugSignal
;
21 /// The Squid -n parameter service name.
22 /// Default is APP_SHORTNAME ('squid').
23 extern SBuf service_name
;
25 void parseEtcHosts(void);
27 void setUmask(mode_t mask
);
28 void strwordquote(MemBuf
* mb
, const char *str
);
32 /* a common objPackInto interface; used by debugObj */
33 typedef void (*ObjPackMethod
) (void *obj
, Packable
* p
);
35 /* packs, then prints an object using debugs() */
36 void debugObj(int section
, int level
, const char *label
, void *obj
, ObjPackMethod pm
);
38 /// callback type for signal handlers
39 typedef void SIGHDLR(int sig
);
41 const char *getMyHostname(void);
42 const char *uniqueHostname(void);
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);
52 void setSystemLimits(void);
53 void squid_signal(int sig
, SIGHDLR
*, int flags
);
54 void keepCapabilities(void);
55 void BroadcastSignalIfAny(int& sig
);
57 /// whether the current process is the parent of all other Squid processes
58 bool IamMasterProcess();
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
63 bool IamPrimaryProcess();
64 /// whether the current process coordinates worker processes
65 bool IamCoordinatorProcess();
66 /// whether the current process handles HTTP transactions and such
67 bool IamWorkerProcess();
68 /// whether the current process is dedicated to managing a cache_dir
69 bool IamDiskProcess();
70 /// Whether we are running in daemon mode
71 bool InDaemonMode(); // try using specific Iam*() checks above first
72 /// Whether there should be more than one worker process running
73 bool UsingSmp(); // try using specific Iam*() checks above first
74 /// number of Kid processes as defined in src/ipc/Kid.h
76 /// a string describing this process roles such as worker or coordinator
79 void debug_trap(const char *);
83 void squid_getrusage(struct rusage
*r
);
84 double rusage_cputime(struct rusage
*r
);
85 int rusage_maxrss(struct rusage
*r
);
86 int rusage_pagefaults(struct rusage
*r
);
87 void releaseServerSockets(void);
88 void PrintRusage(void);
89 void dumpMallocStats(void);
92 typedef union wait PidStatus
;
94 typedef int PidStatus
;
98 * Compatibility wrapper function for waitpid
99 * \pid the pid of child proccess to wait for.
100 * \param status the exit status returned by waitpid
101 * \param flags WNOHANG or 0
103 pid_t
WaitForOnePid(pid_t pid
, PidStatus
&status
, int flags
);
106 * Wait for state changes in any of the kid processes.
107 * Equivalent to waitpid(-1, ...) system call
108 * \param status the exit status returned by waitpid
109 * \param flags WNOHANG or 0
111 inline pid_t
WaitForAnyPid(PidStatus
&status
, int flags
)
113 return WaitForOnePid(-1, status
, flags
);
117 /// xstrerror(errno) equivalent for Windows errors returned by GetLastError()
118 SBuf
WindowsErrorMessage(DWORD errorId
);
119 #endif // _SQUID_WINDOWS_
121 #endif /* SQUID_TOOLS_H_ */