]> git.ipfire.org Git - thirdparty/squid.git/blame - src/ipc/Kid.h
SourceFormat Enforcement
[thirdparty/squid.git] / src / ipc / Kid.h
CommitLineData
40daaeb8 1/*
4ac4a490 2 * Copyright (C) 1996-2017 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
17class Kid
18{
19public:
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
27public:
28 Kid();
29
30 Kid(const String& kid_name);
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
50 /// returns true if the process terminated normally
51 bool calledExit() const;
52
53 /// returns the exit status of the process
54 int exitStatus() const;
55
56 /// whether the process exited with a given exit status code
57 bool calledExit(int code) const;
58
59 /// whether the process exited with code 0
60 bool exitedHappy() const;
61
62 /// returns true if the kid was terminated by a signal
63 bool signaled() const;
64
65 /// returns the number of the signal that caused the kid to terminate
66 int termSignal() const;
67
68 /// whether the process was terminated by a given signal
69 bool signaled(int sgnl) const;
70
71 /// returns kid name
72 const String& name() const;
73
74private:
75 // Information preserved across restarts
76 String theName; ///< process name
77 int badFailures; ///< number of "repeated frequent" failures
78
79 // Information specific to a running or stopped kid
80 pid_t pid; ///< current (for a running kid) or last (for stopped kid) PID
81 time_t startTime; ///< last start time
82 bool isRunning; ///< whether the kid is assumed to be alive
dbf55289 83 PidStatus status; ///< exit status of a stopped kid
40daaeb8
AR
84};
85
095ec2b1
AR
86// TODO: processes may not be kids; is there a better place to put this?
87
9199139f 88/// process kinds
095ec2b1
AR
89typedef enum {
90 pkOther = 0, ///< we do not know or do not care
91 pkCoordinator = 1, ///< manages all other kids
92 pkWorker = 2, ///< general-purpose worker bee
93 pkDisker = 4, ///< cache_dir manager
ed1a1519 94 pkHelper = 8 ///< general-purpose helper child
095ec2b1
AR
95} ProcessKind;
96
97/// ProcessKind for the current process
98extern int TheProcessKind;
99
40daaeb8 100#endif /* SQUID_IPC_KID_H */
f53969cc 101