]> git.ipfire.org Git - thirdparty/squid.git/blame - src/ipc/Kid.h
SourceFormat Enforcement
[thirdparty/squid.git] / src / ipc / Kid.h
CommitLineData
40daaeb8
AR
1/*
2 * $Id$
3 *
4 */
5
6#ifndef SQUID_IPC_KID_H
7#define SQUID_IPC_KID_H
8
9#include "SquidString.h"
10
40daaeb8
AR
11/// Squid child, including current forked process info and
12/// info persistent across restarts
13class Kid
14{
15public:
1191b93b 16#if _SQUID_NEXT_
40daaeb8
AR
17 typedef union wait status_type;
18#else
19 typedef int status_type;
20#endif
21
22 /// keep restarting until the number of bad failures exceed this limit
23 enum { badFailureLimit = 4 };
24
25 /// slower start failures are not "frequent enough" to be counted as "bad"
26 enum { fastFailureTimeLimit = 10 }; // seconds
27
28public:
29 Kid();
30
31 Kid(const String& kid_name);
32
33 /// called when this kid got started, records PID
34 void start(pid_t cpid);
35
36 /// called when kid terminates, sets exiting status
37 void stop(status_type exitStatus);
38
39 /// returns true if tracking of kid is stopped
40 bool running() const;
41
ca4b9ee6
DK
42 /// returns true if master should restart this kid
43 bool shouldRestart() const;
44
40daaeb8
AR
45 /// returns current pid for a running kid and last pid for a stopped kid
46 pid_t getPid() const;
47
48 /// whether the failures are "repeated and frequent"
49 bool hopeless() const;
50
51 /// returns true if the process terminated normally
52 bool calledExit() const;
53
54 /// returns the exit status of the process
55 int exitStatus() const;
56
57 /// whether the process exited with a given exit status code
58 bool calledExit(int code) const;
59
60 /// whether the process exited with code 0
61 bool exitedHappy() const;
62
63 /// returns true if the kid was terminated by a signal
64 bool signaled() const;
65
66 /// returns the number of the signal that caused the kid to terminate
67 int termSignal() const;
68
69 /// whether the process was terminated by a given signal
70 bool signaled(int sgnl) const;
71
72 /// returns kid name
73 const String& name() const;
74
75private:
76 // Information preserved across restarts
77 String theName; ///< process name
78 int badFailures; ///< number of "repeated frequent" failures
79
80 // Information specific to a running or stopped kid
81 pid_t pid; ///< current (for a running kid) or last (for stopped kid) PID
82 time_t startTime; ///< last start time
83 bool isRunning; ///< whether the kid is assumed to be alive
84 status_type status; ///< exit status of a stopped kid
85};
86
095ec2b1
AR
87// TODO: processes may not be kids; is there a better place to put this?
88
9199139f 89/// process kinds
095ec2b1
AR
90typedef enum {
91 pkOther = 0, ///< we do not know or do not care
92 pkCoordinator = 1, ///< manages all other kids
93 pkWorker = 2, ///< general-purpose worker bee
94 pkDisker = 4, ///< cache_dir manager
95} ProcessKind;
96
97/// ProcessKind for the current process
98extern int TheProcessKind;
99
40daaeb8 100#endif /* SQUID_IPC_KID_H */