Kid.cc
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/* DEBUG: section 54 Interprocess Communication */
10
11#include "squid.h"
12#include "globals.h"
13#include "ipc/Kid.h"
14#include "SquidConfig.h"
15
16#include <ctime>
17#if HAVE_SYS_WAIT_H
18#include <sys/wait.h>
19#endif
20
22
24{
25}
26
27Kid::Kid(const char *aRole, const int anId):
28 processRole(aRole),
29 processId(anId)
30{
31}
32
34void Kid::start(pid_t cpid)
35{
36 assert(!running());
37 assert(cpid > 0);
38
39 isRunning = true;
40 stopTime = 0;
41 pid = cpid;
43}
44
46void
47Kid::stop(PidStatus const theExitStatus)
48{
49 assert(running());
50 assert(startTime != 0);
51
52 isRunning = false;
54 status = theExitStatus;
55
58 else
59 badFailures = 0; // the failures are not "frequent" [any more]
60
61 reportStopped(); // after all state changes
62}
63
65void
67{
68 if (calledExit()) {
69 syslog(LOG_NOTICE,
70 "Squid Parent: %s process %d exited with status %d",
71 gist().c_str(), pid, exitStatus());
72 } else if (signaled()) {
73 syslog(LOG_NOTICE,
74 "Squid Parent: %s process %d exited due to signal %d with status %d",
75 gist().c_str(), pid, termSignal(), exitStatus());
76 } else {
77 syslog(LOG_NOTICE, "Squid Parent: %s process %d exited",
78 gist().c_str(), pid);
79 }
80
82 syslog(LOG_NOTICE, "Squid Parent: %s process %d will not be restarted for %ld "
83 "seconds due to repeated, frequent failures",
84 gist().c_str(),
85 pid,
86 static_cast<long int>(Config.hopelessKidRevivalDelay));
87 }
88}
89
91bool Kid::running() const
92{
93 return isRunning;
94}
95
98{
99 return !(running() ||
100 exitedHappy() ||
101 hopeless() ||
103 signaled(SIGINT) || // unexpected forced shutdown
104 signaled(SIGTERM)); // unexpected forced shutdown
105}
106
108pid_t Kid::getPid() const
109{
110 assert(pid > 0);
111 return pid;
112}
113
115bool Kid::hopeless() const
116{
118}
119
121bool Kid::calledExit() const
122{
123 return (pid > 0) && !running() && WIFEXITED(status);
124}
125
128{
129 return WEXITSTATUS(status);
130}
131
133bool Kid::calledExit(int code) const
134{
135 return calledExit() && (exitStatus() == code);
136}
137
140{
141 return calledExit(0);
142}
143
145bool Kid::signaled() const
146{
147 return (pid > 0) && !running() && WIFSIGNALED(status);
148}
149
152{
153 return WTERMSIG(status);
154}
155
157bool Kid::signaled(int sgnl) const
158{
159 return signaled() && (termSignal() == sgnl);
160}
161
164{
165 SBuf name("(");
166 name.append(gist());
167 name.append(")");
168 return name;
169}
170
172{
173 SBuf name(processRole);
174 name.appendf("-%d", processId);
175 return name;
176}
177
178time_t
180{
182}
183
int TheProcessKind
ProcessKind for the current process.
Definition: Kid.cc:21
@ pkOther
we do not know or do not care
Definition: Kid.h:103
time_t squid_curtime
Definition: stub_libtime.cc:20
class SquidConfig Config
Definition: SquidConfig.cc:12
#define assert(EX)
Definition: assert.h:17
@ fastFailureTimeLimit
Definition: Kid.h:25
time_t deathDuration() const
Definition: Kid.cc:179
bool calledExit() const
returns true if the process terminated normally
Definition: Kid.cc:121
@ badFailureLimit
Definition: Kid.h:22
int exitStatus() const
returns the exit status of the process
Definition: Kid.cc:127
void start(pid_t cpid)
called when this kid got started, records PID
Definition: Kid.cc:34
pid_t pid
current (for a running kid) or last (for stopped kid) PID
Definition: Kid.h:92
bool running() const
returns true if tracking of kid is stopped
Definition: Kid.cc:91
SBuf processName() const
returns kid name
Definition: Kid.cc:163
SBuf processRole
Definition: Kid.h:87
SBuf gist() const
Definition: Kid.cc:171
time_t stopTime
last termination time
Definition: Kid.h:94
Kid()
Definition: Kid.cc:23
bool hopeless() const
whether the failures are "repeated and frequent"
Definition: Kid.cc:115
void stop(PidStatus const exitStatus)
called when kid terminates, sets exiting status
Definition: Kid.cc:47
bool isRunning
whether the kid is assumed to be alive
Definition: Kid.h:95
time_t startTime
last start time
Definition: Kid.h:93
bool signaled() const
returns true if the kid was terminated by a signal
Definition: Kid.cc:145
int badFailures
number of "repeated frequent" failures
Definition: Kid.h:89
bool exitedHappy() const
whether the process exited with code 0
Definition: Kid.cc:139
pid_t getPid() const
returns current pid for a running kid and last pid for a stopped kid
Definition: Kid.cc:108
int termSignal() const
returns the number of the signal that caused the kid to terminate
Definition: Kid.cc:151
bool shouldRestart() const
returns true if master should restart this kid
Definition: Kid.cc:97
PidStatus status
exit status of a stopped kid
Definition: Kid.h:96
void reportStopped() const
describes a recently stopped kid
Definition: Kid.cc:66
int processId
Definition: Kid.h:88
Definition: SBuf.h:94
SBuf & appendf(const char *fmt,...) PRINTF_FORMAT_ARG2
Definition: SBuf.cc:229
SBuf & append(const SBuf &S)
Definition: SBuf.cc:185
time_t hopelessKidRevivalDelay
hopeless_kid_revival_delay
Definition: SquidConfig.h:109
int shutting_down
int code
Definition: smb-errors.c:145
int PidStatus
Definition: tools.h:91

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors