feat: Add proper device handling
This commit is contained in:
parent
543e1cdd14
commit
8c6d9e4ab6
3 changed files with 14 additions and 9 deletions
|
@ -7,4 +7,3 @@ Drop-in replacement for busybox init (kind of)
|
|||
### TODO
|
||||
|
||||
- askfirst handling
|
||||
- other devices than /dev/console
|
||||
|
|
|
@ -2,13 +2,12 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
)
|
||||
|
||||
var devices map[string]io.ReadWriteCloser
|
||||
var devices = map[string]*os.File{}
|
||||
|
||||
func GetDevice(name string) (io.ReadWriteCloser, error) {
|
||||
func GetDevice(name string) (*os.File, error) {
|
||||
if dev, ok := devices[name]; ok {
|
||||
return dev, nil
|
||||
}
|
||||
|
|
15
process.go
15
process.go
|
@ -11,10 +11,17 @@ func Spawn(entry InitTabEntry) (*exec.Cmd, error) {
|
|||
cmdline := strings.Split(entry.Process, " ")
|
||||
cmd := exec.Command(cmdline[0], cmdline[1:]...)
|
||||
|
||||
// TODO: add stdio handling
|
||||
cmd.Stdin = os.Stdin
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
stdio := os.Stdout
|
||||
if entry.Device != "" {
|
||||
dev, err := GetDevice(entry.Device)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("open device %s: %w", entry.Device, err)
|
||||
}
|
||||
stdio = dev
|
||||
}
|
||||
cmd.Stdin = stdio
|
||||
cmd.Stdout = stdio
|
||||
cmd.Stderr = stdio
|
||||
|
||||
err := cmd.Start()
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in a new issue