]>
Commit | Line | Data |
---|---|---|
40daaeb8 | 1 | /* |
b8ae064d | 2 | * Copyright (C) 1996-2023 The Squid Software Foundation and contributors |
bbc27441 AJ |
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. | |
40daaeb8 AR |
7 | */ |
8 | ||
9 | #ifndef SQUID_IPC_KID_H | |
10 | #define SQUID_IPC_KID_H | |
11 | ||
12 | #include "SquidString.h" | |
dbf55289 | 13 | #include "tools.h" |
40daaeb8 | 14 | |
40daaeb8 AR |
15 | /// Squid child, including current forked process info and |
16 | /// info persistent across restarts | |
17 | class Kid | |
18 | { | |
19 | public: | |
40daaeb8 AR |
20 | |
21 | /// keep restarting until the number of bad failures exceed this limit | |
22 | enum { badFailureLimit = 4 }; | |
23 | ||
24 | /// slower start failures are not "frequent enough" to be counted as "bad" | |
25 | enum { fastFailureTimeLimit = 10 }; // seconds | |
26 | ||
27 | public: | |
28 | Kid(); | |
29 | ||
28bca1f7 | 30 | Kid(const char *role, const int id); |
40daaeb8 AR |
31 | |
32 | /// called when this kid got started, records PID | |
33 | void start(pid_t cpid); | |
34 | ||
35 | /// called when kid terminates, sets exiting status | |
dbf55289 | 36 | void stop(PidStatus const exitStatus); |
40daaeb8 AR |
37 | |
38 | /// returns true if tracking of kid is stopped | |
39 | bool running() const; | |
40 | ||
ca4b9ee6 DK |
41 | /// returns true if master should restart this kid |
42 | bool shouldRestart() const; | |
43 | ||
40daaeb8 AR |
44 | /// returns current pid for a running kid and last pid for a stopped kid |
45 | pid_t getPid() const; | |
46 | ||
47 | /// whether the failures are "repeated and frequent" | |
48 | bool hopeless() const; | |
49 | ||
00e2479d AR |
50 | /// forgets all past failures, ensuring that we are not hopeless() |
51 | void forgetFailures() { badFailures = 0; } | |
52 | ||
53 | /// \returns the time since process termination | |
54 | time_t deathDuration() const; | |
55 | ||
40daaeb8 AR |
56 | /// returns true if the process terminated normally |
57 | bool calledExit() const; | |
58 | ||
59 | /// returns the exit status of the process | |
60 | int exitStatus() const; | |
61 | ||
62 | /// whether the process exited with a given exit status code | |
63 | bool calledExit(int code) const; | |
64 | ||
65 | /// whether the process exited with code 0 | |
66 | bool exitedHappy() const; | |
67 | ||
68 | /// returns true if the kid was terminated by a signal | |
69 | bool signaled() const; | |
70 | ||
71 | /// returns the number of the signal that caused the kid to terminate | |
72 | int termSignal() const; | |
73 | ||
74 | /// whether the process was terminated by a given signal | |
75 | bool signaled(int sgnl) const; | |
76 | ||
28bca1f7 EB |
77 | /// \returns kid's role and ID formatted for use as a process name |
78 | SBuf processName() const; | |
79 | ||
80 | /// \returns kid's role and ID summary; usable as a --kid parameter value | |
81 | SBuf gist() const; | |
40daaeb8 AR |
82 | |
83 | private: | |
00e2479d AR |
84 | void reportStopped() const; |
85 | ||
40daaeb8 | 86 | // Information preserved across restarts |
28bca1f7 EB |
87 | SBuf processRole; |
88 | int processId = 0; | |
89 | int badFailures = 0; ///< number of "repeated frequent" failures | |
40daaeb8 AR |
90 | |
91 | // Information specific to a running or stopped kid | |
28bca1f7 EB |
92 | pid_t pid = -1; ///< current (for a running kid) or last (for stopped kid) PID |
93 | time_t startTime = 0; ///< last start time | |
00e2479d | 94 | time_t stopTime = 0; ///< last termination time |
28bca1f7 EB |
95 | bool isRunning = false; ///< whether the kid is assumed to be alive |
96 | PidStatus status = 0; ///< exit status of a stopped kid | |
40daaeb8 AR |
97 | }; |
98 | ||
095ec2b1 AR |
99 | // TODO: processes may not be kids; is there a better place to put this? |
100 | ||
9199139f | 101 | /// process kinds |
095ec2b1 AR |
102 | typedef enum { |
103 | pkOther = 0, ///< we do not know or do not care | |
104 | pkCoordinator = 1, ///< manages all other kids | |
105 | pkWorker = 2, ///< general-purpose worker bee | |
106 | pkDisker = 4, ///< cache_dir manager | |
ed1a1519 | 107 | pkHelper = 8 ///< general-purpose helper child |
095ec2b1 AR |
108 | } ProcessKind; |
109 | ||
110 | /// ProcessKind for the current process | |
111 | extern int TheProcessKind; | |
112 | ||
40daaeb8 | 113 | #endif /* SQUID_IPC_KID_H */ |
f53969cc | 114 |