internal/router: fix fresh tomato config path

When ctrld performs upgrading tasks, the current binary would be moved
to different file, thus the executable will return this new file name,
instead of the old "/path/to/ctrld".

The config path on FreshTomato is located in the same directory with
ctrld binary, with ".startup" suffix. So when the binary was moved
during upgrading, the config path is located wrongly.

To fix it, read the binary path from service config first, then only
fallback to the current executable if the path is empty (this is the
same way ctrld is doing for other router platforms).
This commit is contained in:
Cuong Manh Le
2025-02-27 18:25:56 +07:00
committed by Cuong Manh Le
parent 46a1039f21
commit e578867118

View File

@@ -45,11 +45,15 @@ func (s *tomatoSvc) Platform() string {
}
func (s *tomatoSvc) configPath() string {
path, err := os.Executable()
if err != nil {
return ""
bin := s.Config.Executable
if bin == "" {
path, err := os.Executable()
if err != nil {
return ""
}
bin = path
}
return path + ".startup"
return bin + ".startup"
}
func (s *tomatoSvc) template() *template.Template {