showManual tries to open the specified manual page using man on stdout
(manual string)
| 506 | |
| 507 | // showManual tries to open the specified manual page using man on stdout |
| 508 | func showManual(manual string) error { |
| 509 | manBinary, err := exec.LookPath("man") |
| 510 | if err != nil { |
| 511 | if errors.Is(err, exec.ErrNotFound) { |
| 512 | fmt.Printf("toolbox - Tool for interactive command line environments on Linux\n") |
| 513 | fmt.Printf("\n") |
| 514 | fmt.Printf("Common commands are:\n") |
| 515 | |
| 516 | usage := getUsageForCommonCommands() |
| 517 | fmt.Printf("%s", usage) |
| 518 | |
| 519 | fmt.Printf("\n") |
| 520 | fmt.Printf("Go to https://containertoolbx.org/ for further information.\n") |
| 521 | return nil |
| 522 | } |
| 523 | |
| 524 | return errors.New("failed to look up man(1)") |
| 525 | } |
| 526 | |
| 527 | manualArgs := []string{"man", manual} |
| 528 | env := os.Environ() |
| 529 | |
| 530 | stderrFd := os.Stderr.Fd() |
| 531 | stderrFdInt := int(stderrFd) |
| 532 | stdoutFd := os.Stdout.Fd() |
| 533 | stdoutFdInt := int(stdoutFd) |
| 534 | if err := syscall.Dup3(stdoutFdInt, stderrFdInt, 0); err != nil { |
| 535 | return errors.New("failed to redirect standard error to standard output") |
| 536 | } |
| 537 | |
| 538 | if err := syscall.Exec(manBinary, manualArgs, env); err != nil { |
| 539 | return errors.New("failed to invoke man(1)") |
| 540 | } |
| 541 | |
| 542 | return nil |
| 543 | } |
| 544 | |
| 545 | func watchContextForEventFD(ctx context.Context, eventFD int) { |
| 546 | done := ctx.Done() |
no test coverage detected
searching dependent graphs…