| 1 | // Copyright © 2013, 2014, The Go-LXC Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a LGPLv2.1 |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
| 5 | //go:build linux && cgo |
| 6 | // +build linux,cgo |
| 7 | |
| 8 | package mainscip-go gomod github.com/lxc/go-lxc . `github.com/lxc/go-lxc/examples/attach`/ |
| 9 | |
| 10 | import ( |
| 11 | "flagscip-go gomod github.com/golang/go/src go1.20 flag/" |
| 12 | "logscip-go gomod github.com/golang/go/src go1.20 log/" |
| 13 | |
| 14 | "github.com/lxc/go-lxcscip-go gomod github.com/lxc/go-lxc . `github.com/lxc/go-lxc`/" |
| 15 | ) |
| 16 | |
| 17 | var ( |
| 18 | lxcpathscip-go gomod github.com/lxc/go-lxc . `github.com/lxc/go-lxc/examples/attach`/lxcpath. string |
| 19 | namescip-go gomod github.com/lxc/go-lxc . `github.com/lxc/go-lxc/examples/attach`/name. string |
| 20 | clearscip-go gomod github.com/lxc/go-lxc . `github.com/lxc/go-lxc/examples/attach`/clear. bool |
| 21 | x86scip-go gomod github.com/lxc/go-lxc . `github.com/lxc/go-lxc/examples/attach`/x86. bool |
| 22 | regularscip-go gomod github.com/lxc/go-lxc . `github.com/lxc/go-lxc/examples/attach`/regular. bool |
| 23 | ) |
| 24 | |
| 25 | func initscip-go gomod github.com/lxc/go-lxc . `github.com/lxc/go-lxc/examples/attach`/init().() { |
| 26 | flagscip-go gomod github.com/golang/go/src go1.20 flag/.StringVarscip-go gomod github.com/golang/go/src go1.20 flag/StringVar().(&lxcpathscip-go gomod github.com/lxc/go-lxc . `github.com/lxc/go-lxc/examples/attach`/lxcpath., "lxcpath", lxcscip-go gomod github.com/lxc/go-lxc . `github.com/lxc/go-lxc`/.DefaultConfigPathscip-go gomod github.com/lxc/go-lxc . `github.com/lxc/go-lxc`/DefaultConfigPath().(), "Use specified container path") |
| 27 | flagscip-go gomod github.com/golang/go/src go1.20 flag/.StringVarscip-go gomod github.com/golang/go/src go1.20 flag/StringVar().(&namescip-go gomod github.com/lxc/go-lxc . `github.com/lxc/go-lxc/examples/attach`/name., "name", "rubik", "Name of the original container") |
| 28 | flagscip-go gomod github.com/golang/go/src go1.20 flag/.BoolVarscip-go gomod github.com/golang/go/src go1.20 flag/BoolVar().(&clearscip-go gomod github.com/lxc/go-lxc . `github.com/lxc/go-lxc/examples/attach`/clear., "clear", false, "Attach with clear environment") |
| 29 | flagscip-go gomod github.com/golang/go/src go1.20 flag/.BoolVarscip-go gomod github.com/golang/go/src go1.20 flag/BoolVar().(&x86scip-go gomod github.com/lxc/go-lxc . `github.com/lxc/go-lxc/examples/attach`/x86., "x86", false, "Attach using x86 personality") |
| 30 | flagscip-go gomod github.com/golang/go/src go1.20 flag/.BoolVarscip-go gomod github.com/golang/go/src go1.20 flag/BoolVar().(®ularscip-go gomod github.com/lxc/go-lxc . `github.com/lxc/go-lxc/examples/attach`/regular., "regular", false, "Attach using a regular user") |
| 31 | flagscip-go gomod github.com/golang/go/src go1.20 flag/.Parsescip-go gomod github.com/golang/go/src go1.20 flag/Parse().() |
| 32 | } |
| 33 | |
| 34 | func mainscip-go gomod github.com/lxc/go-lxc . `github.com/lxc/go-lxc/examples/attach`/main().() { |
| 35 | c, err := lxcscip-go gomod github.com/lxc/go-lxc . `github.com/lxc/go-lxc`/.NewContainerscip-go gomod github.com/lxc/go-lxc . `github.com/lxc/go-lxc`/NewContainer().(namescip-go gomod github.com/lxc/go-lxc . `github.com/lxc/go-lxc/examples/attach`/name., lxcpathscip-go gomod github.com/lxc/go-lxc . `github.com/lxc/go-lxc/examples/attach`/lxcpath.) |
| 36 | if err != nil { |
| 37 | logscip-go gomod github.com/golang/go/src go1.20 log/.Fatalfscip-go gomod github.com/golang/go/src go1.20 log/Fatalf().("ERROR: %s\n", err.Error()) |
| 38 | } |
| 39 | defer c.Releasescip-go gomod github.com/lxc/go-lxc . `github.com/lxc/go-lxc`/Container#Release().() |
| 40 | |
| 41 | options := lxcscip-go gomod github.com/lxc/go-lxc . `github.com/lxc/go-lxc`/.DefaultAttachOptionsscip-go gomod github.com/lxc/go-lxc . `github.com/lxc/go-lxc`/DefaultAttachOptions. |
| 42 | options.ClearEnvscip-go gomod github.com/lxc/go-lxc . `github.com/lxc/go-lxc`/AttachOptions#ClearEnv. = false |
| 43 | if clearscip-go gomod github.com/lxc/go-lxc . `github.com/lxc/go-lxc/examples/attach`/clear. { |
| 44 | options.ClearEnvscip-go gomod github.com/lxc/go-lxc . `github.com/lxc/go-lxc`/AttachOptions#ClearEnv. = true |
| 45 | } |
| 46 | if x86scip-go gomod github.com/lxc/go-lxc . `github.com/lxc/go-lxc/examples/attach`/x86. { |
| 47 | options.Archscip-go gomod github.com/lxc/go-lxc . `github.com/lxc/go-lxc`/AttachOptions#Arch. = lxcscip-go gomod github.com/lxc/go-lxc . `github.com/lxc/go-lxc`/.X86scip-go gomod github.com/lxc/go-lxc . `github.com/lxc/go-lxc`/X86. |
| 48 | } |
| 49 | if regularscip-go gomod github.com/lxc/go-lxc . `github.com/lxc/go-lxc/examples/attach`/regular. { |
| 50 | options.UIDscip-go gomod github.com/lxc/go-lxc . `github.com/lxc/go-lxc`/AttachOptions#UID. = 1000 |
| 51 | options.GIDscip-go gomod github.com/lxc/go-lxc . `github.com/lxc/go-lxc`/AttachOptions#GID. = 1000 |
| 52 | } |
| 53 | logscip-go gomod github.com/golang/go/src go1.20 log/.Printfscip-go gomod github.com/golang/go/src go1.20 log/Printf().("AttachShell\n") |
| 54 | err = c.AttachShellscip-go gomod github.com/lxc/go-lxc . `github.com/lxc/go-lxc`/Container#AttachShell().(options) |
| 55 | if err != nil { |
| 56 | logscip-go gomod github.com/golang/go/src go1.20 log/.Fatalfscip-go gomod github.com/golang/go/src go1.20 log/Fatalf().("ERROR: %s\n", err.Error()) |
| 57 | } |
| 58 | |
| 59 | logscip-go gomod github.com/golang/go/src go1.20 log/.Printfscip-go gomod github.com/golang/go/src go1.20 log/Printf().("RunCommand\n") |
| 60 | _, err = c.RunCommandscip-go gomod github.com/lxc/go-lxc . `github.com/lxc/go-lxc`/Container#RunCommand().([]string{"id"}, options) |
| 61 | if err != nil { |
| 62 | logscip-go gomod github.com/golang/go/src go1.20 log/.Fatalfscip-go gomod github.com/golang/go/src go1.20 log/Fatalf().("ERROR: %s\n", err.Error()) |
| 63 | } |
| 64 | } |