]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/ipc/Kid.cc
2 * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
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.
9 /* DEBUG: section 54 Interprocess Communication */
14 #include "SquidConfig.h"
21 int TheProcessKind
= pkOther
;
27 Kid::Kid(const char *aRole
, const int anId
):
33 /// called when this kid got started, records PID
34 void Kid::start(pid_t cpid
)
42 startTime
= squid_curtime
;
45 /// called when kid terminates, sets exiting status
47 Kid::stop(PidStatus
const theExitStatus
)
50 assert(startTime
!= 0);
53 stopTime
= squid_curtime
;
54 status
= theExitStatus
;
56 if ((stopTime
- startTime
) < fastFailureTimeLimit
)
59 badFailures
= 0; // the failures are not "frequent" [any more]
61 reportStopped(); // after all state changes
64 /// describes a recently stopped kid
66 Kid::reportStopped() const
70 "Squid Parent: %s process %d exited with status %d",
71 gist().c_str(), pid
, exitStatus());
72 } else if (signaled()) {
74 "Squid Parent: %s process %d exited due to signal %d with status %d",
75 gist().c_str(), pid
, termSignal(), exitStatus());
77 syslog(LOG_NOTICE
, "Squid Parent: %s process %d exited",
81 if (hopeless() && Config
.hopelessKidRevivalDelay
) {
82 syslog(LOG_NOTICE
, "Squid Parent: %s process %d will not be restarted for %ld "
83 "seconds due to repeated, frequent failures",
86 static_cast<long int>(Config
.hopelessKidRevivalDelay
));
90 /// returns true if tracking of kid is stopped
91 bool Kid::running() const
96 /// returns true if master process should restart this kid
97 bool Kid::shouldRestart() const
103 signaled(SIGINT
) || // unexpected forced shutdown
104 signaled(SIGTERM
)); // unexpected forced shutdown
107 /// returns current pid for a running kid and last pid for a stopped kid
108 pid_t
Kid::getPid() const
114 /// whether the failures are "repeated and frequent"
115 bool Kid::hopeless() const
117 return badFailures
> badFailureLimit
;
120 /// returns true if the process terminated normally
121 bool Kid::calledExit() const
123 return (pid
> 0) && !running() && WIFEXITED(status
);
126 /// returns the exit status of the process
127 int Kid::exitStatus() const
129 return WEXITSTATUS(status
);
132 /// whether the process exited with a given exit status code
133 bool Kid::calledExit(int code
) const
135 return calledExit() && (exitStatus() == code
);
138 /// whether the process exited with code 0
139 bool Kid::exitedHappy() const
141 return calledExit(0);
144 /// returns true if the kid was terminated by a signal
145 bool Kid::signaled() const
147 return (pid
> 0) && !running() && WIFSIGNALED(status
);
150 /// returns the number of the signal that caused the kid to terminate
151 int Kid::termSignal() const
153 return WTERMSIG(status
);
156 /// whether the process was terminated by a given signal
157 bool Kid::signaled(int sgnl
) const
159 return signaled() && (termSignal() == sgnl
);
163 SBuf
Kid::processName() const
171 SBuf
Kid::gist() const
173 SBuf
name(processRole
);
174 name
.appendf("-%d", processId
);
179 Kid::deathDuration() const
181 return squid_curtime
> stopTime
? squid_curtime
- stopTime
: 0;