Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
lima-vm
GitHub Repository: lima-vm/lima
Path: blob/master/pkg/instance/start_unix.go
2613 views
1
//go:build !windows
2
3
// SPDX-FileCopyrightText: Copyright The Lima Authors
4
// SPDX-License-Identifier: Apache-2.0
5
6
package instance
7
8
import (
9
"fmt"
10
"os"
11
"os/exec"
12
"syscall"
13
14
"github.com/mattn/go-isatty"
15
"github.com/sirupsen/logrus"
16
17
"github.com/lima-vm/lima/v2/pkg/osutil"
18
)
19
20
func execHostAgentForeground(limactl string, haCmd *exec.Cmd) error {
21
haStdoutW, ok := haCmd.Stdout.(*os.File)
22
if !ok {
23
return fmt.Errorf("expected haCmd.Stdout to be *os.File, got %T", haCmd.Stdout)
24
}
25
haStderrW, ok := haCmd.Stderr.(*os.File)
26
if !ok {
27
return fmt.Errorf("expected haCmd.Stderr to be *os.File, got %T", haCmd.Stderr)
28
}
29
logrus.Info("Running the host agent in the foreground")
30
if isatty.IsTerminal(os.Stdin.Fd()) || isatty.IsCygwinTerminal(os.Stdin.Fd()) {
31
// Write message to standard log files to avoid confusing users
32
message := "This log file is not used because `limactl start` was launched in the terminal with the `--foreground` option."
33
if _, err := haStdoutW.WriteString(message); err != nil {
34
return err
35
}
36
if _, err := haStderrW.WriteString(message); err != nil {
37
return err
38
}
39
} else {
40
if err := osutil.Dup2(int(haStdoutW.Fd()), syscall.Stdout); err != nil {
41
return err
42
}
43
if err := osutil.Dup2(int(haStderrW.Fd()), syscall.Stderr); err != nil {
44
return err
45
}
46
}
47
return syscall.Exec(limactl, haCmd.Args, haCmd.Environ())
48
}
49
50