Protect devfs last ruleset acquiring with mutex
This commit is contained in:
parent
812c77790a
commit
5eed121f0b
@ -1,11 +1,12 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
|
"fmt"
|
||||||
|
"sync"
|
||||||
"strings"
|
"strings"
|
||||||
|
"io/ioutil"
|
||||||
|
"encoding/json"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
@ -55,6 +56,7 @@ var (
|
|||||||
gFetchIntoDS string
|
gFetchIntoDS string
|
||||||
gFetchFrom string
|
gFetchFrom string
|
||||||
|
|
||||||
|
gMdevfs sync.Mutex
|
||||||
|
|
||||||
rootCmd = &cobra.Command{
|
rootCmd = &cobra.Command{
|
||||||
Use: "gocage",
|
Use: "gocage",
|
||||||
|
13
cmd/start.go
13
cmd/start.go
@ -476,12 +476,17 @@ func genNatIpv4(jail *Jail) ([]string, error) {
|
|||||||
return ippair, nil
|
return ippair, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildDevfsRuleSet(jail *Jail) (error, int) {
|
// FIXME : Must lock this function so parallel start do not
|
||||||
|
func buildDevfsRuleSet(jail *Jail, m *sync.Mutex) (error, int) {
|
||||||
rulesets := []int{}
|
rulesets := []int{}
|
||||||
|
|
||||||
|
m.Lock()
|
||||||
|
//defer m.Unlock()
|
||||||
|
|
||||||
// Get known rulesets
|
// Get known rulesets
|
||||||
out, err := executeCommand("devfs rule showsets")
|
out, err := executeCommand("devfs rule showsets")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
m.Unlock()
|
||||||
return errors.New(fmt.Sprintf("Error executing command \"devfs rule showsets\": %v; command returned: %s\n", err, out)), 0
|
return errors.New(fmt.Sprintf("Error executing command \"devfs rule showsets\": %v; command returned: %s\n", err, out)), 0
|
||||||
}
|
}
|
||||||
srs := strings.Split(out, "\n")
|
srs := strings.Split(out, "\n")
|
||||||
@ -509,19 +514,23 @@ func buildDevfsRuleSet(jail *Jail) (error, int) {
|
|||||||
// UPDATE: We don't need this as every jail have a default Devfs_ruleset value
|
// UPDATE: We don't need this as every jail have a default Devfs_ruleset value
|
||||||
/*ds, err := getDatastoreFromArray(jail.Datastore, gDatastores)
|
/*ds, err := getDatastoreFromArray(jail.Datastore, gDatastores)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
m.Unlock()
|
||||||
return errors.New(fmt.Sprintf("Error getting datastore %s for jail %s", jail.Datastore, jail.Name)), 0
|
return errors.New(fmt.Sprintf("Error getting datastore %s for jail %s", jail.Datastore, jail.Name)), 0
|
||||||
}
|
}
|
||||||
defaultrs, err := strconv.ParseInt(ds.DefaultJailConfig.Devfs_ruleset, 10, 64)
|
defaultrs, err := strconv.ParseInt(ds.DefaultJailConfig.Devfs_ruleset, 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
m.Unlock()
|
||||||
return errors.New(fmt.Sprintf("Error parsing default devfs_ruleset for datastore %s", jail.Datastore)), 0
|
return errors.New(fmt.Sprintf("Error parsing default devfs_ruleset for datastore %s", jail.Datastore)), 0
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
// Clone configured devfs_ruleset to a dynamic ruleset
|
// Clone configured devfs_ruleset to a dynamic ruleset
|
||||||
if false == isStringInArray(srs, jail.Config.Devfs_ruleset) {
|
if false == isStringInArray(srs, jail.Config.Devfs_ruleset) {
|
||||||
|
m.Unlock()
|
||||||
return errors.New(fmt.Sprintf("Unknown ruleset: %s", jail.Config.Devfs_ruleset)), 0
|
return errors.New(fmt.Sprintf("Unknown ruleset: %s", jail.Config.Devfs_ruleset)), 0
|
||||||
}
|
}
|
||||||
rs, _ := strconv.Atoi(jail.Config.Devfs_ruleset)
|
rs, _ := strconv.Atoi(jail.Config.Devfs_ruleset)
|
||||||
err = copyDevfsRuleset(ruleset, rs)
|
err = copyDevfsRuleset(ruleset, rs)
|
||||||
|
m.Unlock()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err, 0
|
return err, 0
|
||||||
}
|
}
|
||||||
@ -1343,7 +1352,7 @@ func StartJail(args []string) {
|
|||||||
net = append(net, strings.Split(cj.Config.Vnet_interfaces, " ")...)
|
net = append(net, strings.Split(cj.Config.Vnet_interfaces, " ")...)
|
||||||
}
|
}
|
||||||
|
|
||||||
err, dynrs := buildDevfsRuleSet(cj)
|
err, dynrs := buildDevfsRuleSet(cj, &gMdevfs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("%s\n", err.Error())
|
fmt.Printf("%s\n", err.Error())
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user