sysinit: Support for the -g (gateway) flag used in networking setup

This commit is contained in:
Andrea Luzzardi 2013-02-20 17:45:46 -08:00
parent db4c75f3c1
commit b9b66d0e1b
1 changed files with 14 additions and 0 deletions

View File

@ -11,6 +11,17 @@ import (
"syscall"
)
// Setup networking
func setupNetworking(gw string) {
if gw == "" {
return
}
cmd := exec.Command("/sbin/route", "add", "default", "gw", gw)
if err := cmd.Run(); err != nil {
log.Fatalf("Unable to set up networking: %v", err)
}
}
// Takes care of dropping privileges to the desired user
func changeUser(u string) {
if u == "" {
@ -62,8 +73,11 @@ func SysInit() {
os.Exit(1)
}
var u = flag.String("u", "", "username or uid")
var gw = flag.String("g", "", "gateway address")
flag.Parse()
setupNetworking(*gw)
changeUser(*u)
executeProgram(flag.Arg(0), flag.Args())
}