Skip to content

Commit 6063645

Browse files
refactor
1 parent a1e7199 commit 6063645

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

cli/cli.go

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -94,18 +94,21 @@ func BaseCommand() *serpent.Command {
9494
}
9595
}
9696

97+
func isChild() bool {
98+
return os.Getenv("CHILD") == "true"
99+
}
100+
97101
// Run executes the boundary command with the given configuration and arguments
98102
func Run(ctx context.Context, config Config, args []string) error {
99-
isChild := os.Getenv("CHILD") == "true"
100-
if isChild {
101-
log.Printf("CHILD process is started")
102-
vethNetJail := os.Getenv("VETH_JAIL_NAME")
103+
if isChild() {
104+
log.Printf("boundary CHILD process is started")
103105

106+
vethNetJail := os.Getenv("VETH_JAIL_NAME")
104107
err := jail.SetupChildNetworking(vethNetJail)
105108
if err != nil {
106-
return fmt.Errorf("failed to run SetupChildNetworking: %v", err)
109+
return fmt.Errorf("failed to setup child networking: %v", err)
107110
}
108-
log.Printf("child networking is configured")
111+
log.Printf("child networking is successfully configured")
109112

110113
// Program to run
111114
bin := args[0]
@@ -117,10 +120,9 @@ func Run(ctx context.Context, config Config, args []string) error {
117120
cmd.Stderr = os.Stderr
118121
err = cmd.Run()
119122
if err != nil {
120-
log.Printf("failed to run %s: %v, output: %s", bin, err, "output")
123+
log.Printf("failed to run %s: %v", bin, err)
121124
return err
122125
}
123-
log.Printf("successfully run %s: %s", bin, "output")
124126

125127
return nil
126128
}
@@ -227,18 +229,21 @@ func Run(ctx context.Context, config Config, args []string) error {
227229
logger.Debug("Executing command in boundary", "command", strings.Join(os.Args, " "))
228230
err := cmd.Start()
229231
if err != nil {
230-
logger.Error("Command execution failed(Start)", "error", err)
232+
logger.Error("Command failed to start", "error", err)
233+
return
231234
}
232235

233236
err = boundaryInstance.ConfigureAfterCommandExecution(cmd.Process.Pid)
234237
if err != nil {
235-
logger.Error("configuration failed", "error", err)
238+
logger.Error("configuration after command execution failed", "error", err)
239+
return
236240
}
237241

238242
logger.Debug("waiting on a child process to finish")
239243
err = cmd.Wait()
240244
if err != nil {
241-
logger.Error("Command execution failed(Wait)", "error", err)
245+
logger.Error("Command execution failed", "error", err)
246+
return
242247
}
243248
}()
244249

0 commit comments

Comments
 (0)