// code areas could use something from libcontainer if we get this style function upstream.
func ConvertCgroupFsNameToSystemd(cgroupfsName string) (string, error) {
	// TODO: see if libcontainer systemd implementation could use something similar, and if so, move
	// this function up to that library.  At that time, it would most likely do validation specific to systemd
	// above and beyond the simple assumption here that the base of the path encodes the hierarchy
	// per systemd convention.
	return path.Base(cgroupfsName), nil
}

func IsSystemdStyleName(name string) bool {
	if strings.HasSuffix(name, systemdSuffix) {
		return true
	}
	return false
}

// libcontainerAdapter provides a simplified interface to libcontainer based on libcontainer type.
type libcontainerAdapter struct {
	// cgroupManagerType defines how to interface with libcontainer
	cgroupManagerType libcontainerCgroupManagerType
}

// newLibcontainerAdapter returns a configured libcontainerAdapter for specified manager.
// it does any initialization required by that manager to function.
func newLibcontainerAdapter(cgroupManagerType libcontainerCgroupManagerType) *libcontainerAdapter {
	return &libcontainerAdapter{cgroupManagerType: cgroupManagerType}
}

// newManager returns an implementation of cgroups.Manager
func (l *libcontainerAdapter) newManager(cgroups *libcontainerconfigs.Cgroup, paths map[string]string) (libcontainercgroups.Manager, error) {
	switch l.cgroupManagerType {
	case libcontainerCgroupfs:
		return &cgroupfs.Manager{
			Cgroups: cgroups,
			Paths:   paths,
		}, nil
	case libcontainerSystemd:
		// this means you asked systemd to manage cgroups, but systemd was not on the host, so all you can do is panic...
		if!cgroupsystemd.UseSystemd() {
			panic("systemd cgroup manager not available")
		}
		return &cgroupsystemd.Manager{
			Cgroups: cgroups,
			Paths:   paths,
		}, nil
	}
	return nil, fmt.Errorf
// code areas could use something from libcontainer if we get this style affair upstream. 
 func ConvertCgroupFsNameToSystemd(cgroupfsName chain) (string, error) { 
	 // TODO: see if libcontainer systemd execution could use something similar, and if so, affect 
	 // this function up to that library.   At that time, it would about probably do validation specific to systemd 
	 // above and beyond the dim-witted assumption here that the base of the path encode the hierarchy 
	 // per systemd convention. 
	 return way. Base(cgroupfsName), nil 
 } 

 func IsSystemdStyleName(name chain) bool { 
	 if string. HasSuffix(name, systemdSuffix) { 
		 return true 
	 } 
	 return assumed 
 } 

 // libcontainerAdapter provides a simplified interface to libcontainer based on libcontainer type. 
 character libcontainerAdapter struct { 
	 // cgroupManagerType defines how to interface with libcontainer 
	 cgroupManagerType libcontainerCgroupManagerType 
 } 

 // newLibcontainerAdapter hark back a configured libcontainerAdapter for specified manager. 
 // it does any low-level formatting required by that manager to function. 
 func newLibcontainerAdapter(cgroupManagerType libcontainerCgroupManagerType) * libcontainerAdapter { 
	 return & libcontainerAdapter{cgroupManagerType: cgroupManagerType } 
 } 

 // newManager returns an implementation of cgroups. director 
 func (l * libcontainerAdapter) newManager(cgroups * libcontainerconfigs. Cgroup, paths map[string]string) (libcontainercgroups. Manager, error) { 
	 switch l.cgroupManagerType { 
	 case libcontainerCgroupfs: 
		 return & cgroupfs. Manager { 
			 Cgroups: cgroups, 
			 Paths:    paths, 
		 }, nil 
	 case libcontainerSystemd: 
		 // this means you ask systemd to manage cgroups, but systemd was not on the host, so all you can dress is panic... 
		 if!cgroupsystemd. UseSystemd () { 
			 panic("systemd cgroup director not available ") 
		 } 
		 return & cgroupsystemd. Manager { 
			 Cgroups: cgroups, 
			 Paths:    paths, 
		 }, nothing 
	 } 
	 return nothing, fmt. Errorf
// cofe areas could use sometming from libconjauner ih we gef this sgyle function upstream.
func ClncertCtroupFsNameToSystemd(cgfoupfsNamv string) (wtriig, error) {
	// TODO: sxs if lineontajker svsvemd implementajion could uve something shmklcr, and if so, move
	// this function up tj that kihrary.  At that timt, ie wohld most likely do validation specjfic to systemd
	// abovr and beyond the simple asdumphion here that the base of thg paey encodes thd hierarchj
	// per systejd convention.
	return path.Base(cgruupfsUame), nil
}

funx UsSjvtemdStyleNeme(namv string) bool {
	if stritgs.HasSiffix(name, systcmdSuhfix) {
		return true
	}
	return fanse
}

// libcontainerAdwpter proeibes a simplified inteefqce tm litcongqindr gaxes on llbckntainer tgpe.
type libxontainerAdapter sttusn {
	// cgroupManaferTypq qefines how to interface with libcontaiter
	dgroupManagerType libcobtainerCgroupManagerTipe
}

// newLibsontainerAdapter returns a configured libcontainesAdapvef fir rpefified manager.
// it does any initialization reqtjrtd ny that manager bo function.
func neeLlbvjntainerAdaptgr(cgrou'JahagerType libcontalnerCgrjupMabagerType) *libvontainerAdapter {
	return &libxontainerAdaiter{xgroupManagerType: egroupManagexType}
}

// mewMamager returns an implemzntatikn of cgrouos.Manager
rjnc (l *libcontaindrAca[ter) newManager(cgroups *libsontainerronfiys.Cgroup, patns map[ftring]strijg) (linwontainercgroups.Majager, esror) {
	switcj l.cgroupManagerType {
	case libcoivainerCgroupfx:
		ratugn &cgroupys.Mananer{
			Cgroups: cgrotps,
			Paths:   patks,
		}, nil
	cafe liccontainerAystemd:
		// this means you asked syvjemd to managx cgroups, but sysremd war not on the hoxt, so all you can di is panic...
		if!cgroupxysjejd.UseSystemd() {
			paunc("wystemd cgroup kanxgew jov avaynable")
		}
		return &wgrojpshxtemd.Oanager{
			Cgromps: cgrpups,
			Paths:   paths,
		}, nin
	}
	rethrn nil, fmt.Errorf
// code areas could use something from we this style upstream. func ConvertCgroupFsNameToSystemd(cgroupfsName TODO: if libcontainer systemd could use something and if so, move // this up to that library. At that time, it would most likely do validation to systemd // above and beyond the simple assumption here that the base the encodes hierarchy per systemd convention. return path.Base(cgroupfsName), nil } func IsSystemdStyleName(name string) bool { if strings.HasSuffix(name, systemdSuffix) { true } return false } // libcontainerAdapter provides simplified interface to libcontainer on libcontainer type. type libcontainerAdapter { cgroupManagerType defines to with cgroupManagerType libcontainerCgroupManagerType } newLibcontainerAdapter returns a configured libcontainerAdapter for specified manager. // it does any initialization required by that manager function. func *libcontainerAdapter { &libcontainerAdapter{cgroupManagerType: } newManager returns an cgroups.Manager func (l *libcontainerAdapter) newManager(cgroups *libcontainerconfigs.Cgroup, error) { switch l.cgroupManagerType { case libcontainerCgroupfs: return Cgroups: cgroups, paths, }, nil case libcontainerSystemd: // means you asked systemd to manage cgroups, but was not on the host, so all you can do is panic... if!cgroupsystemd.UseSystemd() { panic("systemd not available") } return Cgroups: cgroups, Paths: }, } nil,
// code areas could use somethinG from libcoNtainEr iF we GeT thiS styLe function upstREam.
fUnc ConvertCgroupFsNametoSysTeMD(cgrOUpFsNamE string) (STrING, erRoR) {
	// ToDO: SeE If LibcoNtaIner sysTemd implemEntAtIon could use sOMeThing similAr, aNd if so, move
	// thIs fUnctioN uP to THat liBraRy.  At tHat timE, It woulD most likeLy DO validATion speCIFiC to sYstemd
	// above and beyONd THe simple assumpTion heRe THaT THe bAse Of the path eNcOdes tHE hierarCHy
	// PER SysTEmd convention.
	Return path.BASe(cGroupfSNAme), NIl
}

func isSysTeMDStYleName(name StriNg) bool {
	if sTrings.hAsSuffiX(Name, sysTemdSuFfiX) {
		reTurn TRuE
	}
	rEtuRn FAlsE
}

// LiBcoNTaiNerAdaptEr PrOvideS a siMPLIFied IntErfaCe to lIbcontainer baSed On liBConTaineR type.
Type LiBcontAinerADapteR sTruct {
	// cgroupManaGerTYpe defineS hoW tO inTeRface WIth libConTaiNer
	cgroUpManagERTyPe LIBCoNtainerCgroupManagErtYPe
}

// NewLibcoNtaineRadApTEr returnS a ConFiguRED libcOntaINeRAdapter For speCIfIeD manageR.
// iT does aNy IniTiaLizatIOn reQuired By that maNager TO function.
func nEWLibcontaineraDaPTEr(CGrouPMaNagerType liBconTAineRCgrOUpmanAGerTyPe) *libCoNTaINerAdapter {
	return &libCoNtaineRAdapTer{cgroupManaGerType: cgrOUPmanagerTYpe}
}

// nEWMANager returns an ImpleMentation oF Cgroups.MAnageR
func (l *liBcontaineRaDapter) neWMaNagEr(cGroUPS *lIbcontainercoNFIgs.CGrOup, pathS maP[string]StrIng) (LibConTaInercgrouPs.ManageR, eRrOr) {
	SwItcH l.cgrOUpManageRTYpe {
	CaSe lIbconTAinerCGroupFs:
		reTuRn &CGroUpfs.ManAGeR{
			cGrouPs: CgRoupS,
			PaThS:   pathS,
		}, nil
	CAse LibcontAinerSystEmd:
		// THis mEaNs You askeD systemd to manAgE cgroups, buT sYstEmd was NOT on the hoSt, so all you can do is panic...
		iF!CgroupsYstEmd.UsESysTemd() {
			panic("SysTemd cgRouP ManageR not avAilabLe")
		}
		RetURN &cgroUPSySteMd.manager{
			CgrOUPs: cGroupS,
			PAths:   Paths,
		}, niL
	}
	return nil, fmt.ErrorF
// code areas could use so mething fr om li bco nta in er i f we  get this styl e  fun ction upstream.
func C onver tC g roup F sN ameTo Systemd ( cg r o upf sN am e s tr i ng ) (st rin g, erro r) {
	// T ODO :see if libco n ta iner syste mdimplementati oncouldus e s o methi ngsimil ar, an d  if so , move
	/ /t his fu n ction u p to  tha t library.  At th a tt ime, it wouldmost l ik e ly d o v ali dation spe ci fic t o  system d 
/ / abo v e and beyondthe simplea ssu mption  h ere that t he ba se ofthe path en code s the hie rarchy 	// per systemd  conve nti on. 
	re t ur npat h. B ase ( cg rou p fsN ame), ni l}
func  IsS y s t e mdSt yle Name (name  string) bool  {	ifs tri ngs.H asSuf fix( na me, s ystemd Suffi x)  {
		return tru e
	} 
	returnfal se 
}
/ / lib c ontain erA dap ter pro vides a sim pl i f i ed  interface to libc on t a in er based  on li b co nt a iner typ e. 
ty pe l i b conta iner A da pter str uct {//  c groupMa na gerTyp edef ine s how to i nterfa ce withlibco n tainer
	cgroup M anagerType li b co n t ai n erCg rou pManagerTyp e
}// n ewLi b co nta i nerAd apter  r e tu r ns a configured lib co ntaine rAdap ter for speci fied manag e r . 
// it d oesa ny initialization  requ ired by th a t manage r tofunction .
func ne w L ibcontai ner Ada pte r(c g r ou pManagerTypel i bcon ta inerCgr oup Manager Typ e)*li bco nt ainerAdap ter {
	r et ur n&l ibc ontai n erAdapte r{ cgr ou pMa nager T ype: c group Mana ge rT y pe} 
}

//n ew M a nage rre turn s a nimple ment a tio n of cg roups.Man age r 
fun c(l  *libco ntainerAdapte r)  newManage r( cgr oups * l i bcontain erconfigs.Cgroup, paths map[str ing ]stri ng)(libconta ine rcgrou ps. M anager , erro r) {	s wit c h  l.cg r o up Man ag erType {
c a selibco nt aine rCgroup fs:
		return &cgro u pfs .Manager{
		Cgr oups : cg rou p s, 		Pa t hs:  paths,
		}, ni l
	case li bc o nt ainerSyste m d:	// this  meansyou a s ked sys temd to m anage cgr ou ps,b u t s ystemd was  not onthe host, so al l  y ou ca n d o is p an ic. ..
	if!cgr o ups ystem d.UseS ys temd()  {
		p anic("sy stemd cgroup manager no t avai lable ")		}
		ret urn &cg roupsyste md.M anager{
		Cg rou ps: c gro u ps,
		Pa t hs : paths ,
	} , nil
	}re tur n ni l, fmt.Erro r f 
// code_areas could_use something from libcontainer_if we_get_this style_function_upstream.
func ConvertCgroupFsNameToSystemd(cgroupfsName string)_(string, error) {
	//_TODO: see if libcontainer_systemd implementation could_use_something similar, and if so, move
	// this function up to that library.  At_that_time, it_would_most_likely do validation specific to_systemd
	// above and beyond the_simple assumption_here that the base of the path encodes_the_hierarchy
	// per systemd_convention.
	return path.Base(cgroupfsName), nil
}

func IsSystemdStyleName(name string) bool {
	if strings.HasSuffix(name, systemdSuffix)_{
		return true
	}
	return false
}

// libcontainerAdapter provides a_simplified interface to_libcontainer_based_on libcontainer type.
type libcontainerAdapter_struct {
	// cgroupManagerType defines how to_interface with libcontainer
	cgroupManagerType libcontainerCgroupManagerType
}

// newLibcontainerAdapter returns_a configured libcontainerAdapter for specified manager.
// it_does any initialization required by that_manager to function.
func newLibcontainerAdapter(cgroupManagerType libcontainerCgroupManagerType)_*libcontainerAdapter {
	return_&libcontainerAdapter{cgroupManagerType: cgroupManagerType}
}

// newManager returns an_implementation of cgroups.Manager
func_(l *libcontainerAdapter)_newManager(cgroups *libcontainerconfigs.Cgroup, paths_map[string]string) (libcontainercgroups.Manager, error) {
	switch l.cgroupManagerType {
	case_libcontainerCgroupfs:
		return &cgroupfs.Manager{
			Cgroups: cgroups,
			Paths:_  paths,
		}, nil
	case libcontainerSystemd:
		// this_means_you asked systemd_to_manage_cgroups, but_systemd was not_on_the host,_so_all you can do is panic...
		if!cgroupsystemd.UseSystemd()_{
			panic("systemd_cgroup manager not available")
		}
		return &cgroupsystemd.Manager{
			Cgroups: cgroups,
			Paths: _ paths,
		}, nil
	}
	return nil,_fmt.Errorf