Kid.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
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.
7  */
8 
9 #ifndef SQUID_SRC_IPC_KID_H
10 #define SQUID_SRC_IPC_KID_H
11 
12 #include "SquidString.h"
13 #include "tools.h"
14 
17 class Kid
18 {
19 public:
20 
22  enum { badFailureLimit = 4 };
23 
25  enum { fastFailureTimeLimit = 10 }; // seconds
26 
27 public:
28  Kid();
29 
30  Kid(const char *role, const int id);
31 
33  void start(pid_t cpid);
34 
36  void stop(PidStatus const exitStatus);
37 
39  bool running() const;
40 
42  bool shouldRestart() const;
43 
45  pid_t getPid() const;
46 
48  bool hopeless() const;
49 
51  void forgetFailures() { badFailures = 0; }
52 
54  time_t deathDuration() const;
55 
57  bool calledExit() const;
58 
60  int exitStatus() const;
61 
63  bool calledExit(int code) const;
64 
66  bool exitedHappy() const;
67 
69  bool signaled() const;
70 
72  int termSignal() const;
73 
75  bool signaled(int sgnl) const;
76 
78  SBuf processName() const;
79 
81  SBuf gist() const;
82 
83 private:
84  void reportStopped() const;
85 
86  // Information preserved across restarts
88  int processId = 0;
89  int badFailures = 0;
90 
91  // Information specific to a running or stopped kid
92  pid_t pid = -1;
93  time_t startTime = 0;
94  time_t stopTime = 0;
95  bool isRunning = false;
97 };
98 
99 // TODO: processes may not be kids; is there a better place to put this?
100 
102 typedef enum {
103  pkOther = 0,
105  pkWorker = 2,
106  pkDisker = 4,
107  pkHelper = 8
108 } ProcessKind;
109 
111 extern int TheProcessKind;
112 
113 #endif /* SQUID_SRC_IPC_KID_H */
114 
@ pkHelper
general-purpose helper child
Definition: Kid.h:107
int processId
Definition: Kid.h:88
time_t deathDuration() const
Definition: Kid.cc:179
SBuf processRole
Definition: Kid.h:87
bool exitedHappy() const
whether the process exited with code 0
Definition: Kid.cc:139
time_t startTime
last start time
Definition: Kid.h:93
int exitStatus() const
returns the exit status of the process
Definition: Kid.cc:127
SBuf gist() const
Definition: Kid.cc:171
Definition: Kid.h:17
bool calledExit() const
returns true if the process terminated normally
Definition: Kid.cc:121
void start(pid_t cpid)
called when this kid got started, records PID
Definition: Kid.cc:34
Definition: SBuf.h:93
int termSignal() const
returns the number of the signal that caused the kid to terminate
Definition: Kid.cc:151
bool hopeless() const
whether the failures are "repeated and frequent"
Definition: Kid.cc:115
pid_t getPid() const
returns current pid for a running kid and last pid for a stopped kid
Definition: Kid.cc:108
void reportStopped() const
describes a recently stopped kid
Definition: Kid.cc:66
@ badFailureLimit
Definition: Kid.h:22
pid_t pid
current (for a running kid) or last (for stopped kid) PID
Definition: Kid.h:92
@ fastFailureTimeLimit
Definition: Kid.h:25
void forgetFailures()
forgets all past failures, ensuring that we are not hopeless()
Definition: Kid.h:51
PidStatus status
exit status of a stopped kid
Definition: Kid.h:96
int TheProcessKind
ProcessKind for the current process.
Definition: Kid.cc:21
int code
Definition: smb-errors.c:145
bool shouldRestart() const
returns true if master should restart this kid
Definition: Kid.cc:97
@ pkOther
we do not know or do not care
Definition: Kid.h:103
int badFailures
number of "repeated frequent" failures
Definition: Kid.h:89
bool running() const
returns true if tracking of kid is stopped
Definition: Kid.cc:91
@ pkWorker
general-purpose worker bee
Definition: Kid.h:105
bool signaled() const
returns true if the kid was terminated by a signal
Definition: Kid.cc:145
int PidStatus
Definition: tools.h:91
time_t stopTime
last termination time
Definition: Kid.h:94
bool isRunning
whether the kid is assumed to be alive
Definition: Kid.h:95
void stop(PidStatus const exitStatus)
called when kid terminates, sets exiting status
Definition: Kid.cc:47
SBuf processName() const
returns kid name
Definition: Kid.cc:163
Kid()
Definition: Kid.cc:23
@ pkCoordinator
manages all other kids
Definition: Kid.h:104
ProcessKind
process kinds
Definition: Kid.h:102
@ pkDisker
cache_dir manager
Definition: Kid.h:106

 

Introduction

Documentation

Support

Miscellaneous