package selftest import ( "errors" "fmt" "io" "os" "strconv" "github.com/databricks/cli/libs/daemon" "github.com/databricks/cli/libs/process" "github.com/spf13/cobra" ) // TODO CONTINUE: // // Ensure that a robust timeout mechanism exists for the telemetry process. We // do not want the daemons to hang indefinitely. Can this also be tested? // // TODO: One set of tests will be asserting that the tests have the right // properties. A thread on my personal slack account will help with that. // The other set of tests will assert on the functional behaviour, that the // parent and child process are indeed indpenedent, and that the child process // does not block the parent process. // // TODO: Make sure to acknowledge the risk of failing when people try to delete // the binary in windows. // // TODO: Ensure that child stdout / stderr are not sent to the parent process. func newChildCommand() *cobra.Command { return &cobra.Command{ Use: "child", RunE: func(cmd *cobra.Command, args []string) error { parentPid, err := strconv.Atoi(os.Getenv(daemon.DatabricksCliParentPid)) if err != nil { return fmt.Errorf("failed to parse parent PID: %w", err) } err = process.Wait(parentPid) if err != nil && !errors.As(err, &process.ErrProcessNotFound{}) { return fmt.Errorf("failed to wait for parent process: %w", err) } fmt.Println("\n====================") fmt.Println("\nAll output from this point on is from the child process") fmt.Println("Parent process has exited") in, err := io.ReadAll(os.Stdin) if err != nil { return fmt.Errorf("failed to read from stdin: %w", err) } fmt.Println("Received input from parent process:") fmt.Println(string(in)) return nil }, } }