(stderr io.Reader, dst io.Writer)
| 215 | } |
| 216 | |
| 217 | func copyStderr(stderr io.Reader, dst io.Writer) { |
| 218 | br := bufio.NewReader(stderr) |
| 219 | |
| 220 | var panicFd *os.File |
| 221 | defer func() { |
| 222 | if panicFd != nil { |
| 223 | _ = panicFd.Close() |
| 224 | maybeReportPanics() |
| 225 | } |
| 226 | }() |
| 227 | |
| 228 | for { |
| 229 | line, err := br.ReadString('\n') |
| 230 | if err != nil { |
| 231 | return |
| 232 | } |
| 233 | |
| 234 | dst.Write([]byte(line)) |
| 235 | |
| 236 | if panicFd == nil && (strings.HasPrefix(line, "panic:") || strings.HasPrefix(line, "fatal error:") || strings.HasPrefix(line, "runtime:")) { |
| 237 | panicFd, err = os.Create(locations.GetTimestamped(locations.PanicLog)) |
| 238 | if err != nil { |
| 239 | slog.Error("Failed to create panic log", slogutil.Error(err)) |
| 240 | continue |
| 241 | } |
| 242 | |
| 243 | slog.Error("Panic detected, writing to file", slogutil.FilePath(panicFd.Name())) |
| 244 | slog.Info("Please check for existing issues with similar panic message at https://github.com/syncthing/syncthing/issues/") |
| 245 | slog.Info("If no issue with similar panic message exists, please create a new issue with the panic log attached") |
| 246 | |
| 247 | stdoutMut.Lock() |
| 248 | for _, line := range stdoutFirstLines { |
| 249 | panicFd.WriteString(line) |
| 250 | } |
| 251 | panicFd.WriteString("...\n") |
| 252 | for _, line := range stdoutLastLines { |
| 253 | panicFd.WriteString(line) |
| 254 | } |
| 255 | stdoutMut.Unlock() |
| 256 | |
| 257 | panicFd.WriteString("Panic at " + time.Now().Format(time.RFC3339) + "\n") |
| 258 | } |
| 259 | |
| 260 | if panicFd != nil { |
| 261 | panicFd.WriteString(line) |
| 262 | } |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | func copyStdout(stdout io.Reader, dst io.Writer) { |
| 267 | br := bufio.NewReader(stdout) |
no test coverage detected