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