From 1a380ac436d47020819bf2398705f7528515844a Mon Sep 17 00:00:00 2001
From: Andrey Vagin <avagin@openvz.org>
Date: Tue, 23 Dec 2014 01:05:56 +0300
Subject: [PATCH] nsinit: remove ticks around nsenter

If we really need these command, we need to expand API.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
---
 nsinit/exec.go    | 14 --------
 nsinit/main.go    | 28 ----------------
 nsinit/nsenter.go | 84 -----------------------------------------------
 3 files changed, 126 deletions(-)
 delete mode 100644 nsinit/nsenter.go

diff --git a/nsinit/exec.go b/nsinit/exec.go
index 266f5935..6c98c0f3 100644
--- a/nsinit/exec.go
+++ b/nsinit/exec.go
@@ -6,7 +6,6 @@ import (
 	"log"
 	"os"
 	"syscall"
-	"text/tabwriter"
 
 	"github.com/codegangsta/cli"
 	"github.com/docker/libcontainer"
@@ -30,19 +29,6 @@ var execCommand = cli.Command{
 }
 
 func execAction(context *cli.Context) {
-	if context.Bool("list") {
-		w := tabwriter.NewWriter(os.Stdout, 10, 1, 3, ' ', 0)
-		fmt.Fprint(w, "NAME\tUSAGE\n")
-
-		for k, f := range argvs {
-			fmt.Fprintf(w, "%s\t%s\n", k, f.Usage)
-		}
-
-		w.Flush()
-
-		return
-	}
-
 	var exitCode int
 
 	process := &libcontainer.ProcessConfig{
diff --git a/nsinit/main.go b/nsinit/main.go
index 561ce3a9..d1e4bf1e 100644
--- a/nsinit/main.go
+++ b/nsinit/main.go
@@ -3,43 +3,15 @@ package main
 import (
 	"log"
 	"os"
-	"strings"
 
 	"github.com/codegangsta/cli"
 )
 
 var (
 	logPath = os.Getenv("log")
-	argvs   = make(map[string]*rFunc)
 )
 
-func init() {
-	argvs["exec"] = &rFunc{
-		Usage:  "execute a process inside an existing container",
-		Action: nsenterExec,
-	}
-
-	argvs["mknod"] = &rFunc{
-		Usage:  "mknod a device inside an existing container",
-		Action: nsenterMknod,
-	}
-
-	argvs["ip"] = &rFunc{
-		Usage:  "display the container's network interfaces",
-		Action: nsenterIp,
-	}
-}
-
 func main() {
-	// we need to check our argv 0 for any registred functions to run instead of the
-	// normal cli code path
-	f, exists := argvs[strings.TrimPrefix(os.Args[0], "nsenter-")]
-	if exists {
-		runFunc(f)
-
-		return
-	}
-
 	app := cli.NewApp()
 
 	app.Name = "nsinit"
diff --git a/nsinit/nsenter.go b/nsinit/nsenter.go
deleted file mode 100644
index 8365215e..00000000
--- a/nsinit/nsenter.go
+++ /dev/null
@@ -1,84 +0,0 @@
-package main
-
-import (
-	"fmt"
-	"log"
-	"net"
-	"os"
-	"strconv"
-	"strings"
-	"text/tabwriter"
-
-	"github.com/docker/libcontainer/configs"
-	"github.com/docker/libcontainer/devices"
-	"github.com/docker/libcontainer/mount/nodes"
-	"github.com/docker/libcontainer/namespaces"
-	_ "github.com/docker/libcontainer/namespaces/nsenter"
-)
-
-// nsenterExec exec's a process inside an existing container
-func nsenterExec(config *configs.Config, args []string) {
-	if err := namespaces.FinalizeSetns(config, args); err != nil {
-		log.Fatalf("failed to nsenter: %s", err)
-	}
-}
-
-// nsenterMknod runs mknod inside an existing container
-//
-// mknod <path> <type> <major> <minor>
-func nsenterMknod(config *configs.Config, args []string) {
-	if len(args) != 4 {
-		log.Fatalf("expected mknod to have 4 arguments not %d", len(args))
-	}
-
-	t := rune(args[1][0])
-
-	major, err := strconv.Atoi(args[2])
-	if err != nil {
-		log.Fatal(err)
-	}
-
-	minor, err := strconv.Atoi(args[3])
-	if err != nil {
-		log.Fatal(err)
-	}
-
-	n := &devices.Device{
-		Path:        args[0],
-		Type:        t,
-		MajorNumber: int64(major),
-		MinorNumber: int64(minor),
-	}
-
-	if err := nodes.CreateDeviceNode("/", n); err != nil {
-		log.Fatal(err)
-	}
-}
-
-// nsenterIp displays the network interfaces inside a container's net namespace
-func nsenterIp(config *configs.Config, args []string) {
-	interfaces, err := net.Interfaces()
-	if err != nil {
-		log.Fatal(err)
-	}
-
-	w := tabwriter.NewWriter(os.Stdout, 10, 1, 3, ' ', 0)
-	fmt.Fprint(w, "NAME\tMTU\tMAC\tFLAG\tADDRS\n")
-
-	for _, iface := range interfaces {
-		addrs, err := iface.Addrs()
-		if err != nil {
-			log.Fatal(err)
-		}
-
-		o := []string{}
-
-		for _, a := range addrs {
-			o = append(o, a.String())
-		}
-
-		fmt.Fprintf(w, "%s\t%d\t%s\t%s\t%s\n", iface.Name, iface.MTU, iface.HardwareAddr, iface.Flags, strings.Join(o, ","))
-	}
-
-	w.Flush()
-}