Compare commits
3 commits
1eb77e513e
...
945b295bdf
Author | SHA1 | Date | |
---|---|---|---|
ptrcnull | 945b295bdf | ||
ptrcnull | b5808e7773 | ||
ptrcnull | 8650c833bf |
28
inittab.go
28
inittab.go
|
@ -30,13 +30,27 @@ var ActionMap = map[string]Action{
|
||||||
"ctrlaltdel": CtrlAltDel,
|
"ctrlaltdel": CtrlAltDel,
|
||||||
}
|
}
|
||||||
|
|
||||||
type TabEntry struct {
|
type InitTabEntry struct {
|
||||||
Id string
|
Device string
|
||||||
Action Action
|
Action Action
|
||||||
Process string
|
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"},
|
{"", SysInit, "/etc/init.d/rcS"},
|
||||||
{"", AskFirst, "/bin/sh"},
|
{"", AskFirst, "/bin/sh"},
|
||||||
{"", CtrlAltDel, "/sbin/reboot"},
|
{"", CtrlAltDel, "/sbin/reboot"},
|
||||||
|
@ -48,8 +62,8 @@ var DefaultInittab = []TabEntry{
|
||||||
{"tty4", AskFirst, "/bin/sh"},
|
{"tty4", AskFirst, "/bin/sh"},
|
||||||
}
|
}
|
||||||
|
|
||||||
func ParseInittab(reader io.Reader) []TabEntry {
|
func ParseInitTab(reader io.Reader) InitTab {
|
||||||
var res []TabEntry
|
var res InitTab
|
||||||
scanner := bufio.NewScanner(reader)
|
scanner := bufio.NewScanner(reader)
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
line := scanner.Text()
|
line := scanner.Text()
|
||||||
|
@ -67,8 +81,8 @@ func ParseInittab(reader io.Reader) []TabEntry {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
res = append(res, TabEntry{
|
res = append(res, InitTabEntry{
|
||||||
Id: tokens[0],
|
Device: tokens[0],
|
||||||
Action: action,
|
Action: action,
|
||||||
Process: tokens[3],
|
Process: tokens[3],
|
||||||
})
|
})
|
||||||
|
|
15
main.go
15
main.go
|
@ -1,5 +1,18 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue