Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
Merge pull request #279 from jcvenegas/dont-call-rand
Browse files Browse the repository at this point in the history
namespace: do not create path using rand.
  • Loading branch information
Sebastien Boeuf authored Jun 27, 2018
2 parents b2c3f0b + 57bf4e6 commit 994ac9c
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
package main

import (
"crypto/rand"
"fmt"
"os"
"path/filepath"
Expand All @@ -17,7 +16,7 @@ import (
"golang.org/x/sys/unix"
)

var persistentNsDir = "/var/run"
var persistentNsDir = "/var/run/sandbox-ns"

// nsType defines a namespace type.
type nsType string
Expand Down Expand Up @@ -48,19 +47,15 @@ func getCurrentThreadNSPath(nType nsType) string {
// setupPersistentNs creates persistent namespace without switchin to it.
// Note, pid namespaces cannot be persisted.
func setupPersistentNs(namespaceType nsType) (*namespace, error) {
b := make([]byte, 8)
_, err := rand.Reader.Read(b)
if err != nil {
return nil, fmt.Errorf("failed to generate random netns name: %v", err)
}

err = os.MkdirAll(persistentNsDir, 0755)
err := os.MkdirAll(persistentNsDir, 0755)
if err != nil {
return nil, err
}

// Create an empty file at the mount point.
nsPath := filepath.Join(persistentNsDir, fmt.Sprintf("%x", b))
nsPath := filepath.Join(persistentNsDir, string(namespaceType))

mountFd, err := os.Create(nsPath)
if err != nil {
return nil, err
Expand Down

0 comments on commit 994ac9c

Please sign in to comment.