Merge branch 'bugfix-17492' into 'main'
🐞 fix: TSG-17492 Closes TSG-17492 See merge request linxin/coredump-tools!7
This commit is contained in:
@@ -160,7 +160,7 @@ func writeCoreConfig(config types.Coredump_config) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// write coredump to file
|
// write coredump to file
|
||||||
func writeCoreDumpToFile(config types.Coredump_config) error {
|
func writeCoreDumpToFile(config types.Coredump_config, pipe_config types.Pipeconfig) error {
|
||||||
filename := fmt.Sprintf("%s_%s_%d.coredump", config.Initial_ns_pid, config.Process_ns_pid, config.Timestamp)
|
filename := fmt.Sprintf("%s_%s_%d.coredump", config.Initial_ns_pid, config.Process_ns_pid, config.Timestamp)
|
||||||
file, err := os.Create(filename)
|
file, err := os.Create(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -168,6 +168,7 @@ func writeCoreDumpToFile(config types.Coredump_config) error {
|
|||||||
}
|
}
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
buf := make([]byte, 1024*1024)
|
buf := make([]byte, 1024*1024)
|
||||||
|
nums := 0
|
||||||
for {
|
for {
|
||||||
n, err := os.Stdin.Read(buf)
|
n, err := os.Stdin.Read(buf)
|
||||||
if err != nil && err != io.EOF {
|
if err != nil && err != io.EOF {
|
||||||
@@ -180,6 +181,25 @@ func writeCoreDumpToFile(config types.Coredump_config) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
nums += 1
|
||||||
|
if nums >= 10 {
|
||||||
|
flag, err := isDiskSufficient(pipe_config)
|
||||||
|
if err != nil {
|
||||||
|
journal.Print(journal.PriErr, "Can't judge disk's space is sufficient or not. "+err.Error())
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if !flag {
|
||||||
|
journal.Print(journal.PriErr, "Disk space exceeds limit after write coredump!")
|
||||||
|
err := os.RemoveAll(pipe_config.Storage)
|
||||||
|
if err != nil {
|
||||||
|
journal.Print(journal.PriErr, err.Error())
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
journal.Print(journal.PriInfo, err.Error())
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
nums = 0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -337,7 +357,7 @@ func main() {
|
|||||||
//write coredump file
|
//write coredump file
|
||||||
if !pipe_config.Compress {
|
if !pipe_config.Compress {
|
||||||
if pipe_config.Storage_type == 1 {
|
if pipe_config.Storage_type == 1 {
|
||||||
err = writeCoreDumpToFile(coredump_config)
|
err = writeCoreDumpToFile(coredump_config, pipe_config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
journal.Print(journal.PriErr, err.Error())
|
journal.Print(journal.PriErr, err.Error())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -97,6 +97,9 @@ func TestWriteCoreDumpToFile(t *testing.T) {
|
|||||||
Corepipe_config_path: "/tmp/config.yaml",
|
Corepipe_config_path: "/tmp/config.yaml",
|
||||||
Timestamp: 12345678,
|
Timestamp: 12345678,
|
||||||
}
|
}
|
||||||
|
pipe_config := types.Pipeconfig{
|
||||||
|
Storage: "/tmp",
|
||||||
|
}
|
||||||
cmd := exec.Command("echo", "test")
|
cmd := exec.Command("echo", "test")
|
||||||
cmdReader, err := cmd.StdoutPipe()
|
cmdReader, err := cmd.StdoutPipe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -112,7 +115,7 @@ func TestWriteCoreDumpToFile(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("WriteCoreDumpToFile() error = %v", err)
|
t.Errorf("WriteCoreDumpToFile() error = %v", err)
|
||||||
}
|
}
|
||||||
err = writeCoreDumpToFile(config)
|
err = writeCoreDumpToFile(config, pipe_config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("WriteCoreDumpToFile() error = %v", err)
|
t.Errorf("WriteCoreDumpToFile() error = %v", err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user