// GetInitSystem returns an InitSystem for the current system, or nil
// if we cannot detect a supported init system for pre-flight checks.
// This indicates we will skip init system checks, not an error.
509068
func GetInitSystem() (InitSystem, error) {
	// Assume existence of systemctl in path implies this is a systemd system:
	_, err := exec.LookPath("systemctl")
	if err == nil {
		return &SystemdInitSystem{}, nil
	}
	_, err = exec.LookPath("wininit.exe")
	if err == nil {
		return &WindowsInitSystem{}, nil
	}
	return nil, fmt.Errorf("no supported init system detected, skipping checking for services")
}
1236631
func (a *QuotaAdmission) ValidateInitialization() error {
	if a.quotaAccessor == nil {
		return fmt.Errorf("missing quotaAccessor")
	}
	if a.quotaAccessor.client == nil {
		return fmt.Errorf("missing quotaAccessor.client")
	}
	if a.quotaAccessor.lister == nil {
		return fmt.Errorf("missing quotaAccessor.lister")
	}
	if a.quotaConfiguration == nil {
		return fmt.Errorf("missing quotaConfiguration")
	}
	if a.evaluator == nil {
		return fmt.Errorf("missing evaluator")
	}
	return nil
}
53201
func (f *Facade) getInstance(ctx datastore.Context, hst host.Host, svc service.Service, imageUUID string, state zkservice.State) (*service.Instance, error) {
	logger := plog.WithFields(log.Fields{
		"hostid":     state.HostID,
		"serviceid":  state.ServiceID,
		"instanceid": state.InstanceID,
	})

	// get the current state
	var curState service.InstanceCurrentState
	curState = service.InstanceCurrentState(state.CurrentStateContainer.Status)

	if svc.EmergencyShutdown {
		if curState == service.StateStopped {
			curState = service.StateEmergencyStopped
		} else if curState == service.StateStopping {
			curState = service.StateEmergencyStopping
		}
	}

	logger.Debug("Calulated service status")

	svch := service.BuildServiceHealth(svc)

	inst := &service.Instance{
		InstanceID:    state.InstanceID,
		HostID:        hst.ID,
		HostName:      hst.Name,
		ServiceID:     svc.ID,
		ServiceName:   svc.Name,
		ContainerID:   state.ContainerID,
		ImageSynced:   imageUUID == state.ImageUUID,
		DesiredState:  state.DesiredState,
		CurrentState:  curState,
		HealthStatus:  f.getInstanceHealth(svch, state.InstanceID),
		RAMCommitment: int64(svc.RAMCommitment.Value),
		Scheduled:     state.Scheduled,
		Started:       state.Started,
		Terminated:    state.Terminated,
	}
	logger.Debug("Loaded service instance")

	return inst, nil
}
164193
func (s *serviceAccount) ValidateInitialization() error {
	if s.client == nil {
		return fmt.Errorf("missing client")
	}
	if s.secretLister == nil {
		return fmt.Errorf("missing secretLister")
	}
	if s.serviceAccountLister == nil {
		return fmt.Errorf("missing serviceAccountLister")
	}
	return nil
}
78713
func init() {
	// We need set systemTZ when it is in testing process.
	if systemTZ == "" {
		systemTZ = "System"
	}
	locCa = &locCache{}
	locCa.locMap = make(map[string]*time.Location)
}
355151
func GetSessionSystemVar(s *SessionVars, key string) (string, error) {
	key = strings.ToLower(key)
	gVal, ok, err := GetSessionOnlySysVars(s, key)
	if err != nil || ok {
		return gVal, err
	}
	gVal, err = s.GlobalVarsAccessor.GetGlobalSysVar(key)
	if err != nil {
		return "", err
	}
	s.systems[key] = gVal
	return gVal, nil
}
1161357
func GetOperatingSystem() (string, error) {

	// Default return value
	ret := "Unknown Operating System"

	k, err := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\Microsoft\Windows NT\CurrentVersion`, registry.QUERY_VALUE)
	if err != nil {
		return ret, err
	}
	defer k.Close()

	pn, _, err := k.GetStringValue("ProductName")
	if err != nil {
		return ret, err
	}
	ret = pn

	ri, _, err := k.GetStringValue("ReleaseId")
	if err != nil {
		return ret, err
	}
	ret = fmt.Sprintf("%s Version %s", ret, ri)

	cbn, _, err := k.GetStringValue("CurrentBuildNumber")
	if err != nil {
		return ret, err
	}

	ubr, _, err := k.GetIntegerValue("UBR")
	if err != nil {
		return ret, err
	}
	ret = fmt.Sprintf("%s (OS Build %s.%d)", ret, cbn, ubr)

	return ret, nil
}
614263
func (ci *ClusterID) getOrInitialize() error {
	if ci.store == nil {
		return errors.New("Cloud.ClusterID is not ready. Call Initialize() before using")
	}

	if ci.clusterID != nil {
		return nil
	}

	exists, err := ci.getConfigMap()
	if err != nil {
		return err
	} else if exists {
		return nil
	}

	// The configmap does not exist - let's try creating one.
	newID, err := makeUID()
	if err != nil {
		return err
	}

	klog.V(4).Infof("Creating clusteriD: %v", newID)
	cfg := &v1.ConfigMap{
		ObjectMeta: metav1.ObjectMeta{
			Name:      UIDConfigMapName,
			Namespace: UIDNamespace,
		},
	}
	cfg.Data = map[string]string{
		UIDCluster:  newID,
		UIDProvider: newID,
	}

	if _, err := ci.client.CoreV1().ConfigMaps(UIDNamespace).Create(cfg); err != nil {
		klog.Errorf("GCE cloud provider failed to create %v config map to store cluster id: %v", ci.cfgMapKey, err)
		return err
	}

	klog.V(2).Infof("Created a config map containing clusteriD: %v", newID)
	ci.update(cfg)
	return nil
}
673574
func GetOperatingSystem() (string, error) {
	cmd := exec.Command("uname", "-s")
	osName, err := cmd.Output()
	if err != nil {
		return "", err
	}
	return string(osName), nil
}
218722
func (d *MasterDaemon) InitServices() {
	if d.ClusterMode == "kubernetes" {
		isLeader := func() bool {
			return d.currState == "leader"
		}
		networkpolicy.InitK8SServiceWatch(d.ControlURL, isLeader)
	}
}
309388
func (s *Server) GetSystemUser(unused struct{}, systemUser *user.User) error {
	result, err := s.f.GetSystemUser(s.context())
	if err != nil {
		return err
	}
	*systemUser = result
	return nil
}
315743
func (r *Repository) GetAutoInit() bool {
	if r == nil || r.AutoInit == nil {
		return false
	}
	return *r.AutoInit
}
1339226
func (q *TagQuery) getInitialIds() (chan schema.MKey, chan struct{}) {
	idCh := make(chan schema.MKey, 1000)
	stopCh := make(chan struct{})
	q.wg.Add(1)

	switch q.startWith {
	case EQUAL:
		query := q.equal[0]
		q.equal = q.equal[1:]
		go q.getInitialByEqual(query, idCh, stopCh)
	case PREFIX:
		query := q.prefix[0]
		q.prefix = q.prefix[1:]
		go q.getInitialByPrefix(query, idCh, stopCh)
	case MATCH:
		query := q.match[0]
		q.match = q.match[1:]
		go q.getInitialByMatch(query, idCh, stopCh)
	case PREFIX_TAG:
		go q.getInitialByTagPrefix(idCh, stopCh)
	case MATCH_TAG:
		go q.getInitialByTagMatch(idCh, stopCh)
	}

	return idCh, stopCh
}
188325
func IsKnownSystemPriorityClass(pc *PriorityClass) (bool, error) {
	for _, spc := range systemPriorityClasses {
		if spc.Name == pc.Name {
			if spc.Value != pc.Value {
				return false, fmt.Errorf("value of %v PriorityClass must be %v", spc.Name, spc.Value)
			}
			if spc.GlobalDefault != pc.GlobalDefault {
				return false, fmt.Errorf("globalDefault of %v PriorityClass must be %v", spc.Name, spc.GlobalDefault)
			}
			return true, nil
		}
	}
	return false, fmt.Errorf("%v is not a known system priority class", pc.Name)
}
1241106
func (l *LinuxFactory) StartInitialization() (err error) {
	var (
		pipefd, fifofd int
		consoleSocket  *os.File
		envInitPipe    = os.Getenv("_LIBCONTAINER_INITPIPE")
		envFifoFd      = os.Getenv("_LIBCONTAINER_FIFOFD")
		envConsole     = os.Getenv("_LIBCONTAINER_CONSOLE")
	)

	// Get the INITPIPE.
	pipefd, err = strconv.Atoi(envInitPipe)
	if err != nil {
		return fmt.Errorf("unable to convert _LIBCONTAINER_INITPIPE=%s to int: %s", envInitPipe, err)
	}

	var (
		pipe = os.NewFile(uintptr(pipefd), "pipe")
		it   = initType(os.Getenv("_LIBCONTAINER_INITTYPE"))
	)
	defer pipe.Close()

	// Only init processes have FIFOFD.
	fifofd = -1
	if it == initStandard {
		if fifofd, err = strconv.Atoi(envFifoFd); err != nil {
			return fmt.Errorf("unable to convert _LIBCONTAINER_FIFOFD=%s to int: %s", envFifoFd, err)
		}
	}

	if envConsole != "" {
		console, err := strconv.Atoi(envConsole)
		if err != nil {
			return fmt.Errorf("unable to convert _LIBCONTAINER_CONSOLE=%s to int: %s", envConsole, err)
		}
		consoleSocket = os.NewFile(uintptr(console), "console-socket")
		defer consoleSocket.Close()
	}

	// clear the current process's environment to clean any libcontainer
	// specific env vars.
	os.Clearenv()

	defer func() {
		// We have an error during the initialization of the container's init,
		// send it back to the parent process in the form of an initError.
		if werr := utils.WriteJSON(pipe, syncT{procError}); werr != nil {
			fmt.Fprintln(os.Stderr, err)
			return
		}
		if werr := utils.WriteJSON(pipe, newSystemError(err)); werr != nil {
			fmt.Fprintln(os.Stderr, err)
			return
		}
	}()
	defer func() {
		if e := recover(); e != nil {
			err = fmt.Errorf("panic from initialization: %v, %v", e, string(debug.Stack()))
		}
	}()

	i, err := newContainerInit(it, pipe, consoleSocket, fifofd)
	if err != nil {
		return err
	}

	// If Init succeeds, syscall.Exec will not return, hence none of the defers will be called.
	return i.Init()
}
295561
func (f *FSM) AddInitialState(state *FSMState) {
	f.AddState(state)
	f.initialState = state
}
711824
func init() {
	// 1. Check if hardware and kernel support Intel RDT sub-features
	// "cat_l3" flag for CAT and "mba" flag for MBA
	isCatFlagSet, isMbaFlagSet, err := parseCpuInfoFile("/proc/cpuinfo")
	if err != nil {
		return
	}

	// 2. Check if Intel RDT "resource control" filesystem is mounted
	// The user guarantees to mount the filesystem
	if !isIntelRdtMounted() {
		return
	}

	// 3. Double check if Intel RDT sub-features are available in
	// "resource control" filesystem. Intel RDT sub-features can be
	// selectively disabled or enabled by kernel command line
	// (e.g., rdt=!l3cat,mba) in 4.14 and newer kernel
	if isCatFlagSet {
		if _, err := os.Stat(filepath.Join(intelRdtRoot, "info", "L3")); err == nil {
			isCatEnabled = true
		}
	}
	if isMbaScEnabled {
		// We confirm MBA Software Controller is enabled in step 2,
		// MBA should be enabled because MBA Software Controller
		// depends on MBA
		isMbaEnabled = true
	} else if isMbaFlagSet {
		if _, err := os.Stat(filepath.Join(intelRdtRoot, "info", "MB")); err == nil {
			isMbaEnabled = true
		}
	}
}