]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/tools.h
2 * Copyright (C) 1996-2015 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_
15 #include "SquidString.h"
20 extern int DebugSignal
;
22 /// The Squid -n parameter service name.
23 /// Default is APP_SHORTNAME ('squid').
24 extern SBuf service_name
;
26 void kb_incr(kb_t
*, size_t);
27 void parseEtcHosts(void);
29 void setUmask(mode_t mask
);
30 void strwordquote(MemBuf
* mb
, const char *str
);
34 /* a common objPackInto interface; used by debugObj */
35 typedef void (*ObjPackMethod
) (void *obj
, Packable
* p
);
37 /* packs, then prints an object using debugs() */
38 void debugObj(int section
, int level
, const char *label
, void *obj
, ObjPackMethod pm
);
40 const char *getMyHostname(void);
41 const char *uniqueHostname(void);
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);
50 void writePidFile(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
);
59 /// whether the current process is the parent of all other Squid processes
60 bool IamMasterProcess();
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
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
78 /// a string describing this process roles such as worker or coordinator
79 String
ProcessRoles();
81 void debug_trap(const char *);
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);
94 typedef union wait PidStatus
;
96 typedef int PidStatus
;
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
105 pid_t
WaitForOnePid(pid_t pid
, PidStatus
&status
, int flags
);
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
113 inline pid_t
WaitForAnyPid(PidStatus
&status
, int flags
)
115 return WaitForOnePid(-1, status
, flags
);
118 #endif /* SQUID_TOOLS_H_ */