func initialize() *daemonState { sigs := make(chan os.Signal) signal.Notify(sigs, syscall.SIGHUP, syscall.SIGUSR2) d := &daemonState{} d.initializeLogging() config, err := d.loadConfig() if err != nil { d.log.Error("Could not load configuration: %s", oz.DefaultConfigPath, err) os.Exit(1) } d.config = config ps, err := d.loadProfiles(d.config.ProfileDir) if err != nil { d.log.Fatalf("Failed to load profiles: %v", err) os.Exit(1) } d.profiles = ps if err := d.cacheSystemGroups(); err != nil { d.log.Fatalf("Unable to cache list of system groups: %v", err) } oz.ReapChildProcs(d.log, d.handleChildExit) d.nextSboxId = 1 d.nextDisplay = 100 bridgeNeeded := false staticBytes := []uint{} for _, pp := range d.profiles { if pp.Networking.Nettype == network.TYPE_BRIDGE { bridgeNeeded = true if pp.Networking.IpByte > 0 { staticBytes = append(staticBytes, pp.Networking.IpByte) } } } if bridgeNeeded { d.log.Info("Initializing bridge networking") htn, err := network.BridgeInit(d.config.BridgeMACAddr, d.config.NMIgnoreFile, d.log) if err != nil { d.log.Fatalf("Failed to initialize bridge networking: %+v", err) return nil } d.network = htn d.network.IpBytes = staticBytes //network.NetPrint(d.log) } sockets := path.Join(config.SandboxPath, "sockets") if err := os.MkdirAll(sockets, 0755); err != nil { d.log.Fatalf("Failed to create sockets directory: %v", err) } os.Clearenv() go d.processSignals(sigs) return d }
func initialize() *daemonState { sigs := make(chan os.Signal) signal.Notify(sigs, syscall.SIGHUP, syscall.SIGUSR1) d := &daemonState{} d.initializeLogging() config, err := d.loadConfig() if err != nil { d.log.Error("Could not load configuration: %s", oz.DefaultConfigPath, err) os.Exit(1) } d.config = config ps, err := d.loadProfiles(d.config.ProfileDir) if err != nil { d.log.Fatalf("Failed to load profiles: %v", err) os.Exit(1) } d.profiles = ps oz.ReapChildProcs(d.log, d.handleChildExit) d.nextSboxId = 1 d.nextDisplay = 100 for _, pp := range d.profiles { if pp.Networking.Nettype == network.TYPE_BRIDGE { d.log.Info("Initializing bridge networking") htn, err := network.BridgeInit(d.config.BridgeMACAddr, d.config.NMIgnoreFile, d.log) if err != nil { d.log.Fatalf("Failed to initialize bridge networking: %+v", err) return nil } d.network = htn network.NetPrint(d.log) break } } sockets := path.Join(config.SandboxPath, "sockets") if err := os.MkdirAll(sockets, 0755); err != nil { d.log.Fatalf("Failed to create sockets directory: %v", err) } go d.processSignals(sigs) return d }