mirror of
				https://github.com/TeaOSLab/EdgeNode.git
				synced 2025-11-04 16:00:25 +08:00 
			
		
		
		
	修复arm64下无法调用syscall.Dup2的问题
This commit is contained in:
		@@ -1,7 +1,6 @@
 | 
			
		||||
package nodes
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"bytes"
 | 
			
		||||
	"encoding/json"
 | 
			
		||||
	"errors"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
 | 
			
		||||
@@ -29,7 +28,6 @@ import (
 | 
			
		||||
	"os/exec"
 | 
			
		||||
	"runtime"
 | 
			
		||||
	"sync"
 | 
			
		||||
	"syscall"
 | 
			
		||||
	"time"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
@@ -537,33 +535,3 @@ func (this *Node) listenSock() error {
 | 
			
		||||
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 处理异常
 | 
			
		||||
func (this *Node) handlePanic() {
 | 
			
		||||
	// 如果是在前台运行就直接返回
 | 
			
		||||
	backgroundEnv, _ := os.LookupEnv("EdgeBackground")
 | 
			
		||||
	if backgroundEnv != "on" {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	var panicFile = Tea.Root + "/logs/panic.log"
 | 
			
		||||
 | 
			
		||||
	// 分析panic
 | 
			
		||||
	data, err := ioutil.ReadFile(panicFile)
 | 
			
		||||
	if err == nil {
 | 
			
		||||
		var index = bytes.Index(data, []byte("panic:"))
 | 
			
		||||
		if index >= 0 {
 | 
			
		||||
			remotelogs.Error("NODE", "系统错误,请上报给开发者: "+string(data[index:]))
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	fp, err := os.OpenFile(panicFile, os.O_CREATE|os.O_TRUNC|os.O_WRONLY|os.O_APPEND, 0777)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		logs.Println("NODE", "open 'panic.log' failed: "+err.Error())
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	err = syscall.Dup2(int(fp.Fd()), int(os.Stderr.Fd()))
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		logs.Println("NODE", "write to 'panic.log' failed: "+err.Error())
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										46
									
								
								internal/nodes/node_panic.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								internal/nodes/node_panic.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,46 @@
 | 
			
		||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
 | 
			
		||||
//go:build !arm64
 | 
			
		||||
// +build !arm64
 | 
			
		||||
 | 
			
		||||
package nodes
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"bytes"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeNode/internal/remotelogs"
 | 
			
		||||
	"github.com/iwind/TeaGo/Tea"
 | 
			
		||||
	"github.com/iwind/TeaGo/logs"
 | 
			
		||||
	"io/ioutil"
 | 
			
		||||
	"os"
 | 
			
		||||
	"syscall"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// 处理异常
 | 
			
		||||
func (this *Node) handlePanic() {
 | 
			
		||||
	// 如果是在前台运行就直接返回
 | 
			
		||||
	backgroundEnv, _ := os.LookupEnv("EdgeBackground")
 | 
			
		||||
	if backgroundEnv != "on" {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	var panicFile = Tea.Root + "/logs/panic.log"
 | 
			
		||||
 | 
			
		||||
	// 分析panic
 | 
			
		||||
	data, err := ioutil.ReadFile(panicFile)
 | 
			
		||||
	if err == nil {
 | 
			
		||||
		var index = bytes.Index(data, []byte("panic:"))
 | 
			
		||||
		if index >= 0 {
 | 
			
		||||
			remotelogs.Error("NODE", "系统错误,请上报给开发者: "+string(data[index:]))
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	fp, err := os.OpenFile(panicFile, os.O_CREATE|os.O_TRUNC|os.O_WRONLY|os.O_APPEND, 0777)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		logs.Println("NODE", "open 'panic.log' failed: "+err.Error())
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	err = syscall.Dup2(int(fp.Fd()), int(os.Stderr.Fd()))
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		logs.Println("NODE", "write to 'panic.log' failed: "+err.Error())
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										10
									
								
								internal/nodes/node_panic_arm64.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								internal/nodes/node_panic_arm64.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,10 @@
 | 
			
		||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
 | 
			
		||||
//go:build arm64
 | 
			
		||||
// +build arm64
 | 
			
		||||
 | 
			
		||||
package nodes
 | 
			
		||||
 | 
			
		||||
// 处理异常
 | 
			
		||||
func (this *Node) handlePanic() {
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user