github.com/cloudfoundry-attic/garden-linux@v0.333.2-candidate/containerizer/system/pivotter/main.go (about)

     1  package main
     2  
     3  /*
     4  #include <stdlib.h>
     5  #include <string.h>
     6  #include <stdio.h>
     7  #include <errno.h>
     8  #include <fcntl.h>
     9  #include <sys/param.h>
    10  #include <sys/stat.h>
    11  #include <sys/types.h>
    12  #include <unistd.h>
    13  #include <linux/sched.h>
    14  
    15  int setns(int fd, int nstype);
    16  
    17  int enterns() {
    18    int rv;
    19    int mntnsfd;
    20  
    21    char mntnspath[PATH_MAX];
    22    rv = snprintf(mntnspath, sizeof(mntnspath), "/proc/%s/ns/mnt", getenv("TARGET_NS_PID"));
    23    if(rv == -1) {
    24      perror("snprintf ns mnt path");
    25      return 1;
    26    }
    27  
    28    mntnsfd = open(mntnspath, O_RDONLY);
    29    if(mntnsfd == -1) {
    30      perror("open mnt namespace");
    31      return 1;
    32    }
    33  
    34    rv = setns(mntnsfd, CLONE_NEWNS);
    35    if(rv == -1) {
    36      perror("setns");
    37      return 1;
    38    }
    39    close(mntnsfd);
    40  
    41    return 0;
    42  }
    43  
    44  __attribute__((constructor)) void init(void) {
    45  	enterns();
    46  }
    47  */
    48  import "C"
    49  
    50  import (
    51  	"flag"
    52  
    53  	"github.com/cloudfoundry-incubator/garden-linux/containerizer/system"
    54  )
    55  
    56  func main() {
    57  	rootfs := flag.String("rootfs", "", "path to pivot into")
    58  	flag.Parse()
    59  
    60  	rootfsEnterer := &system.RootFS{*rootfs}
    61  	if err := rootfsEnterer.Enter(); err != nil {
    62  		panic(err)
    63  	}
    64  }