Compare commits

...

3 commits

Author SHA1 Message Date
ptrcnull 945b295bdf wip: Add opening /etc/inittab 2021-11-29 22:12:52 +01:00
ptrcnull b5808e7773 feat: Add type InitTab 2021-11-29 22:12:08 +01:00
ptrcnull 8650c833bf style: Rename TabEntry#Id to Device 2021-11-29 22:11:48 +01:00
2 changed files with 35 additions and 8 deletions

View file

@ -30,13 +30,27 @@ var ActionMap = map[string]Action{
"ctrlaltdel": CtrlAltDel,
}
type TabEntry struct {
Id string
type InitTabEntry struct {
Device string
Action Action
Process string
}
var DefaultInittab = []TabEntry{
type InitTab []InitTabEntry
func (i InitTab) Entries(action Action) InitTab {
var res InitTab
for _, entry := range i {
if entry.Action == action {
res = append(res, entry)
}
}
return res
}
var DefaultInitTab = InitTab{
{"", SysInit, "/etc/init.d/rcS"},
{"", AskFirst, "/bin/sh"},
{"", CtrlAltDel, "/sbin/reboot"},
@ -48,8 +62,8 @@ var DefaultInittab = []TabEntry{
{"tty4", AskFirst, "/bin/sh"},
}
func ParseInittab(reader io.Reader) []TabEntry {
var res []TabEntry
func ParseInitTab(reader io.Reader) InitTab {
var res InitTab
scanner := bufio.NewScanner(reader)
for scanner.Scan() {
line := scanner.Text()
@ -67,8 +81,8 @@ func ParseInittab(reader io.Reader) []TabEntry {
continue
}
res = append(res, TabEntry{
Id: tokens[0],
res = append(res, InitTabEntry{
Device: tokens[0],
Action: action,
Process: tokens[3],
})

15
main.go
View file

@ -1,5 +1,18 @@
package main
import (
"fmt"
"os"
)
func main() {
inittab := DefaultInitTab
if file, err := os.OpenFile("/etc/inittab", os.O_RDONLY, 0644); err != nil {
inittab = ParseInitTab(file)
err := file.Close()
if err != nil {
fmt.Println("close inittab:", err)
}
}
}