Skip to content

Commit 11949f6

Browse files
europauleriknordmark
authored andcommitted
agentlog: fix dumping stacks locally
Fixing the issue introduced in eb07383. The function dumpStacks takes a file path as parameter, but was given the agent name, thus resulting in saving the stack dumps in a local file Signed-off-by: Paul Gaiduk <[email protected]>
1 parent 2fd3c2f commit 11949f6

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

pkg/pillar/agentlog/agentlog.go

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -153,16 +153,17 @@ func (hook *SkipCallerHook) Levels() []logrus.Level {
153153

154154
// Wait on channel then handle the signals
155155
func handleSignals(log *base.LogObject, agentName string, agentPid int, sigs chan os.Signal) {
156-
for {
157-
select {
158-
case sig := <-sigs:
159-
log.Functionf("handleSignals: received %v\n", sig)
160-
switch sig {
161-
case syscall.SIGUSR1:
162-
dumpStacks(log, agentName)
163-
case syscall.SIGUSR2:
164-
go listenDebug(log, agentName)
165-
}
156+
agentDebugDir := fmt.Sprintf("%s/%s/", types.PersistDebugDir, agentName)
157+
stacksDumpFileName := agentDebugDir + "/sigusr1"
158+
memDumpFileName := agentDebugDir + "/sigusr2"
159+
160+
for sig := range sigs {
161+
log.Functionf("handleSignals: received %v\n", sig)
162+
switch sig {
163+
case syscall.SIGUSR1:
164+
dumpStacks(log, stacksDumpFileName)
165+
case syscall.SIGUSR2:
166+
go listenDebug(log, stacksDumpFileName, memDumpFileName)
166167
}
167168
}
168169
}
@@ -226,15 +227,11 @@ func writeOrLog(log *base.LogObject, w io.Writer, msg string) {
226227

227228
var listenDebugRunning atomic.Bool
228229

229-
func listenDebug(log *base.LogObject, agentName string) {
230+
func listenDebug(log *base.LogObject, stacksDumpFileName, memDumpFileName string) {
230231
if listenDebugRunning.Swap(true) {
231232
return
232233
}
233234

234-
agentDebugDir := fmt.Sprintf("%s/%s/", types.PersistDebugDir, agentName)
235-
stacksDumpFileName := agentDebugDir + "/sigusr1"
236-
memDumpFileName := agentDebugDir + "/sigusr2"
237-
238235
mux := http.NewServeMux()
239236

240237
server := &http.Server{

0 commit comments

Comments
 (0)