github.com/rkt/rkt@v1.30.1-0.20200224141603-171c416fac02/stage1/enter_kvm/enter_kvm.go (about) 1 // Copyright 2015 The rkt Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package main 16 17 import ( 18 "flag" 19 "fmt" 20 "io/ioutil" 21 "os" 22 "os/user" 23 24 rktlog "github.com/rkt/rkt/pkg/log" 25 "github.com/rkt/rkt/stage1/common/ssh" 26 ) 27 28 var ( 29 debug bool 30 podPid string 31 appName string 32 u, _ = user.Current() 33 log *rktlog.Logger 34 diag *rktlog.Logger 35 ) 36 37 func init() { 38 flag.BoolVar(&debug, "debug", false, "Run in debug mode") 39 flag.StringVar(&podPid, "pid", "", "podPID") 40 flag.StringVar(&appName, "appname", "", "application to use") 41 42 log, diag, _ = rktlog.NewLogSet("kvm", false) 43 } 44 45 func getAppexecArgs() []string { 46 // Documentation/devel/stage1-implementors-guide.md#arguments-1 47 // also from ../enter/enter.c 48 if appName == "" { 49 return flag.Args() 50 } 51 args := []string{ 52 "/enterexec", 53 fmt.Sprintf("/opt/stage2/%s/rootfs", appName), 54 "/", // as in ../enter/enter.c - this should be app.WorkingDirectory 55 fmt.Sprintf("/rkt/env/%s", appName), 56 u.Uid, 57 u.Gid, 58 "-e", /* entering phase */ 59 "--", 60 } 61 return append(args, flag.Args()...) 62 } 63 64 func main() { 65 flag.Parse() 66 67 log.SetDebug(debug) 68 diag.SetDebug(debug) 69 70 if !debug { 71 diag.SetOutput(ioutil.Discard) 72 } 73 74 // ExecSSH() should return only with error 75 log.Error(ssh.ExecSSH(getAppexecArgs())) 76 77 os.Exit(254) 78 }