File tree Expand file tree Collapse file tree 4 files changed +103
-43
lines changed Expand file tree Collapse file tree 4 files changed +103
-43
lines changed Original file line number Diff line number Diff line change @@ -4,5 +4,5 @@ Website = "https://fujinet.online"
44 Icon = " Icon.png"
55 Name = " TNFS Server Manager"
66 ID = " org.fujinet.tnfs-ui"
7- Version = " 0.0.1 "
8- Build = 18
7+ Version = " 0.0.2 "
8+ Build = 21
Original file line number Diff line number Diff line change 1+ //go:build darwin || bsd || linux
2+
3+ package tnfs
4+
5+ import (
6+ "errors"
7+ "fmt"
8+ "io"
9+ "os/exec"
10+ "syscall"
11+ )
12+
13+ func (s * Server ) launchSubprocess () error {
14+ cmd := exec .Command (s .cfg .ExePath , s .cfg .TnfsRootPath )
15+
16+ errR , _ := cmd .StderrPipe ()
17+ outR , _ := cmd .StdoutPipe ()
18+ s .Log = io .MultiReader (errR , outR )
19+
20+ err := cmd .Start ()
21+ if err != nil {
22+ return s .fail (err )
23+ }
24+ s .Process = cmd .Process
25+
26+ go func () {
27+ err = cmd .Wait ()
28+ if err != nil {
29+ fmt .Println (err .Error ())
30+ if cmd .ProcessState .ExitCode () == 255 {
31+ s .fail (errors .New ("TNFS port (16384) may be in use" ))
32+ }
33+ }
34+ }()
35+
36+ return nil
37+ }
38+
39+ func (s * Server ) killSubprocess () error {
40+ if s .Process == nil {
41+ return errors .New ("Not started" )
42+ }
43+ // TODO: timeout when killing
44+ s .Process .Signal (syscall .SIGTERM )
45+ _ , err := s .Process .Wait ()
46+
47+ if err != nil && ! errors .Is (err , syscall .ECHILD ) {
48+ return s .fail (err )
49+ }
50+ return nil
51+ }
Original file line number Diff line number Diff line change 1+ //go:build windows
2+
3+ package tnfs
4+
5+ import (
6+ "errors"
7+ "fmt"
8+ "io"
9+ "os/exec"
10+ "syscall"
11+ )
12+
13+ func (s * Server ) launchSubprocess () error {
14+ cmd := exec .Command (s .cfg .ExePath , s .cfg .TnfsRootPath )
15+ cmd .SysProcAttr = & syscall.SysProcAttr {HideWindow : true }
16+
17+ errR , _ := cmd .StderrPipe ()
18+ outR , _ := cmd .StdoutPipe ()
19+ s .Log = io .MultiReader (errR , outR )
20+
21+ err := cmd .Start ()
22+ if err != nil {
23+ return s .fail (err )
24+ }
25+ s .Process = cmd .Process
26+
27+ go func () {
28+ err = cmd .Wait ()
29+ if err != nil {
30+ fmt .Println (err .Error ())
31+ if cmd .ProcessState .ExitCode () == 255 {
32+ s .fail (errors .New ("TNFS port (16384) may be in use" ))
33+ }
34+ }
35+ }()
36+
37+ return nil
38+ }
39+
40+ func (s * Server ) killSubprocess () error {
41+ if s .Process == nil {
42+ return errors .New ("Not started" )
43+ }
44+
45+ if err := s .Process .Kill (); err != nil {
46+ return s .fail (err )
47+ }
48+
49+ return nil
50+ }
Original file line number Diff line number Diff line change 66 "fmt"
77 "io"
88 "os"
9- "os/exec"
109 "os/signal"
1110 "strings"
1211 "syscall"
@@ -98,46 +97,6 @@ func (s *Server) sendLogEvent(msg string) {
9897 s .EventCh <- e
9998}
10099
101- func (s * Server ) launchSubprocess () error {
102- cmd := exec .Command (s .cfg .ExePath , s .cfg .TnfsRootPath )
103-
104- errR , _ := cmd .StderrPipe ()
105- outR , _ := cmd .StdoutPipe ()
106- s .Log = io .MultiReader (errR , outR )
107-
108- err := cmd .Start ()
109- if err != nil {
110- return s .fail (err )
111- }
112- s .Process = cmd .Process
113-
114- go func () {
115- err = cmd .Wait ()
116- if err != nil {
117- fmt .Println (err .Error ())
118- if cmd .ProcessState .ExitCode () == 255 {
119- s .fail (errors .New ("TNFS port (16384) may be in use" ))
120- }
121- }
122- }()
123-
124- return nil
125- }
126-
127- func (s * Server ) killSubprocess () error {
128- if s .Process == nil {
129- return errors .New ("Not started" )
130- }
131- // TODO: timeout when killing
132- s .Process .Signal (syscall .SIGTERM )
133- _ , err := s .Process .Wait ()
134-
135- if err != nil && ! errors .Is (err , syscall .ECHILD ) {
136- return s .fail (err )
137- }
138- return nil
139- }
140-
141100func (s * Server ) findExistingProcess () * os.Process {
142101 all , err := ps .Processes ()
143102 if err != nil {
You can’t perform that action at this time.
0 commit comments