Skip to content

Commit aaacc26

Browse files
committed
Move the rest of the protos (spawn) to internal
1 parent 17fc901 commit aaacc26

File tree

9 files changed

+85
-82
lines changed

9 files changed

+85
-82
lines changed
Lines changed: 56 additions & 56 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
syntax = "proto3";
2-
option go_package = "ask.systems/daemon/spawn/embedspawn";
2+
option go_package = "ask.systems/daemon/internal/spawnpb";
33

44
// The schema of the config file
55
//

internal/spawnpb/embed.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package spawnpb
2+
3+
import _ "embed"
4+
5+
//go:embed config.proto
6+
var ConfigProto string

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ import (
9898

9999
//go:generate protoc -I ./ internal/portalpb/storage.proto --go_out ./ --go_opt=paths=source_relative
100100
//go:generate protoc -I ./ internal/portalpb/service.proto --go_out ./ --go-grpc_out ./ --go_opt=paths=source_relative --go-grpc_opt=paths=source_relative
101-
//go:generate protoc -I ./spawn/ spawn/embedspawn/config.proto --go_out ./spawn --go_opt=paths=source_relative
101+
//go:generate protoc -I ./ internal/spawnpb/config.proto --go_out ./ --go_opt=paths=source_relative
102102

103103
type command struct {
104104
name string

spawn/embedspawn/children.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"syscall"
1818
"time"
1919

20+
"ask.systems/daemon/internal/spawnpb"
2021
_ "ask.systems/daemon/portal/flags"
2122
"ask.systems/daemon/tools"
2223
)
@@ -30,7 +31,7 @@ type child struct {
3031
Up bool
3132
Message error
3233
Name string
33-
Cmd *Command
34+
Cmd *spawnpb.Command
3435
Proc *os.Process
3536
ChrootFiles []string
3637
Binary string
@@ -66,7 +67,7 @@ func newChildren(quit chan struct{}) *children {
6667
return c
6768
}
6869

69-
func (c *children) StartPrograms(programs []*Command) (errCnt int) {
70+
func (c *children) StartPrograms(programs []*spawnpb.Command) (errCnt int) {
7071
// Make portal first if it exists
7172
portalIdx := 0
7273
for i, cmd := range programs {
@@ -125,7 +126,7 @@ func (c *children) waitForPortalToken() (string, error) {
125126
}
126127
}
127128

128-
func (cmd *Command) FullName() string {
129+
func commandName(cmd *spawnpb.Command) string {
129130
name := filepath.Base(cmd.Binary)
130131
if cmd.Name != "" {
131132
name = fmt.Sprintf("%v-%v", name, cmd.Name)
@@ -170,7 +171,7 @@ func (c *children) ReloadConfig() {
170171
c.Lock()
171172
defer c.Unlock()
172173
for _, cmd := range commands {
173-
name := cmd.FullName()
174+
name := commandName(cmd)
174175
cmdChild, ok := c.ByName[name]
175176
if ok {
176177
cmdChild.Cmd = cmd
@@ -393,7 +394,7 @@ func copyBinary(bin, out string, exclusive bool, uid, gid uint32) (string, error
393394
return binary, openerr
394395
}
395396

396-
func (children *children) setupChildFiles(cmd *Command, quit chan struct{}) ([]*os.File, error) {
397+
func (children *children) setupChildFiles(cmd *spawnpb.Command, quit chan struct{}) ([]*os.File, error) {
397398
// Set up stdout and stderr piping
398399
r, w, err := os.Pipe()
399400
if err != nil {
@@ -420,6 +421,6 @@ func (children *children) setupChildFiles(cmd *Command, quit chan struct{}) ([]*
420421
if err != nil {
421422
return files, err
422423
}
423-
go children.HandleLogs(r, cmd.FullName())
424+
go children.HandleLogs(r, commandName(cmd))
424425
return files, nil
425426
}

spawn/embedspawn/children_unix.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"syscall"
2020
"time"
2121

22+
"ask.systems/daemon/internal/spawnpb"
2223
"ask.systems/daemon/portal/gate"
2324
)
2425

@@ -63,12 +64,12 @@ type platformSpecificChildrenInfo struct{}
6364

6465
func (p *platformSpecificChildrenInfo) Init(c *children) {}
6566

66-
func (children *children) StartProgram(cmd *Command) error {
67+
func (children *children) StartProgram(cmd *spawnpb.Command) error {
6768
if len(cmd.Binary) == 0 {
6869
return fmt.Errorf("Binary is required")
6970
}
7071
isPortal := filepath.Base(cmd.Binary) == "portal"
71-
name := cmd.FullName()
72+
name := commandName(cmd)
7273
attr := &os.ProcAttr{
7374
Env: []string{
7475
fmt.Sprintf("SPAWN_FILES=%v", len(cmd.Files)),
@@ -328,7 +329,7 @@ func lookupUser(username string) (*syscall.Credential, *user.User, error) {
328329
}, u, nil
329330
}
330331

331-
func openOrRefreshFiles(cmd *Command, quitFileRefresh <-chan struct{}) ([]*os.File, error) {
332+
func openOrRefreshFiles(cmd *spawnpb.Command, quitFileRefresh <-chan struct{}) ([]*os.File, error) {
332333
if len(cmd.Files) == 0 {
333334
return nil, nil
334335
}

spawn/embedspawn/children_windows.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"time"
1515
"unsafe"
1616

17+
"ask.systems/daemon/internal/spawnpb"
1718
"ask.systems/daemon/portal/gate"
1819

1920
"golang.org/x/sys/windows"
@@ -72,7 +73,7 @@ func (c *children) addProcToJobObject(proc *os.Process) error {
7273
return nil
7374
}
7475

75-
func (children *children) StartProgram(cmd *Command) error {
76+
func (children *children) StartProgram(cmd *spawnpb.Command) error {
7677
if len(cmd.Binary) == 0 {
7778
return fmt.Errorf("Binary is required")
7879
}
@@ -89,7 +90,7 @@ func (children *children) StartProgram(cmd *Command) error {
8990
if err != nil {
9091
return err
9192
}
92-
name := cmd.FullName()
93+
name := commandName(cmd)
9394
attr := &os.ProcAttr{
9495
// Note: on windows we need to pass in the existing environment variables
9596
// because there are some important system variables that are needed to
@@ -276,7 +277,7 @@ func copyFile(oldName string, newName string, uid, gid uint32, exclusive bool) (
276277
// Windows doesn't support watching files on spawn
277278
// TODO: try windows.FindFirstChangeNotification or windows.ReadDirectoryChanges
278279
// thanks https://stackoverflow.com/a/17376701/428740
279-
func openOrRefreshFiles(cmd *Command, quitFileRefresh <-chan struct{}) ([]*os.File, error) {
280+
func openOrRefreshFiles(cmd *spawnpb.Command, quitFileRefresh <-chan struct{}) ([]*os.File, error) {
280281
if len(cmd.Files) == 0 {
281282
return nil, nil
282283
}

0 commit comments

Comments
 (0)