当前位置: 首页>>代码示例>>Golang>>正文


Golang os.Getegid函数代码示例

本文整理汇总了Golang中os.Getegid函数的典型用法代码示例。如果您正苦于以下问题:Golang Getegid函数的具体用法?Golang Getegid怎么用?Golang Getegid使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Getegid函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestFSGID

func TestFSGID(t *testing.T) {
	gid, err := getfsgid()
	if err != nil {
		t.Fatal(err)
	}
	if int(gid) != os.Getegid() {
		t.Fatalf("getfsgid() returned unexpected results (%d!=%d)", gid, os.Getegid())
	}
	t.Logf("fsgid = %v\n", gid)
}
开发者ID:jsipprell,项目名称:keyctl,代码行数:10,代码来源:sys_test.go

示例2: lookupGid

// lookupGid resolves a groupname to a numeric id. Current egid is returned on failure.
func lookupGid(groupname string) uint32 {
	g, err := user.Lookup(groupname)
	if err != nil {
		log.Printf("Error resolving gid for %v: %v\n", groupname, err)
		return uint32(os.Getegid())
	}

	gid, err := strconv.ParseUint(g.Gid, 10 /* base */, 32 /* bits */)
	if err != nil {
		log.Printf("Error resolving gid for %v: %v\n", groupname, err)
		return uint32(os.Getegid())
	}

	return uint32(gid)
}
开发者ID:rxacevedo,项目名称:keywhiz-fs,代码行数:16,代码来源:ownership.go

示例3: TestChangingTheUserWihtNobody

func TestChangingTheUserWihtNobody(t *testing.T) {
	t.Parallel()

	//!TODO: find out if this test is possible at all.
	// If not, delete it from here.
	t.Skip("Setting tye UID and GID is not supported for some reason")

	nobody, err := user.Lookup("nobody")

	if err != nil {
		if _, ok := err.(user.UnknownUserError); ok {
			t.Skip("This system does not have the nobody user." +
				" Skipping the test since it requires it")
		} else {
			t.Errorf("Error getting the nobody user: %s", err)
		}
	}

	tempDir, cleanup := testutils.GetTestFolder(t)
	defer cleanup()

	targetPidFile := filepath.Join(tempDir, "pidfile")

	cfg := getCfg(config.System{
		User:    nobody.Name,
		Pidfile: targetPidFile,
	})

	err = SetupEnv(cfg)
	if err != nil {
		t.Errorf("There was an error when setting gid and uit to %s's. %s",
			nobody.Name, err)
	}

	currentEuid := os.Geteuid()
	uidOfNobody, err := strconv.Atoi(nobody.Uid)

	if err != nil {
		t.Errorf("Error converting UID [%s] to int: %s", nobody.Uid, err)
	}

	if uidOfNobody != currentEuid {
		t.Errorf("The current user id was not set to nobody's. "+
			"Expected %d but it was %d",
			uidOfNobody, currentEuid)
	}

	currentEgid := os.Getegid()
	gidOfNobody, err := strconv.Atoi(nobody.Gid)

	if err != nil {
		t.Errorf("Error converting GID [%s] to int: %s", nobody.Gid, err)
	}

	if gidOfNobody != currentEgid {
		t.Errorf("The current group id was not set to nobody's. "+
			"Expected %d but it was %d", gidOfNobody, currentEgid)
	}
	testutils.ShouldntFail(t, os.Remove(targetPidFile))
}
开发者ID:na--,项目名称:nedomi,代码行数:60,代码来源:env_test.go

示例4: main

func main() {
	var err error
	var l *p.Logger

	flag.Parse()
	rsrv.user = p.OsUsers.Uid2User(os.Geteuid())
	rsrv.group = p.OsUsers.Gid2Group(os.Getegid())
	rsrv.blksz = *blksize
	rsrv.blkchan = make(chan []byte, 2048)
	rsrv.zero = make([]byte, rsrv.blksz)

	root := new(RFile)
	err = root.Add(nil, "/", rsrv.user, nil, p.DMDIR|0777, root)
	if err != nil {
		goto error
	}

	l = p.NewLogger(*logsz)
	rsrv.srv = srv.NewFileSrv(&root.File)
	rsrv.srv.Dotu = true
	rsrv.srv.Debuglevel = *debug
	rsrv.srv.Start(rsrv.srv)
	rsrv.srv.Id = "ramfs"
	rsrv.srv.Log = l

	err = rsrv.srv.StartNetListener("tcp", *addr)
	if err != nil {
		goto error
	}
	return

error:
	log.Println(fmt.Sprintf("Error: %s", err))
}
开发者ID:rjkroege,项目名称:go9p,代码行数:34,代码来源:ramfs.go

示例5: CurrentProcessInfo

func CurrentProcessInfo() *ProcessInfo {
	var hasTty bool
	cwd, _ := os.Getwd()
	grp, _ := os.Getgroups()
	// no syscall.Getsid() wrapper on Linux?
	sid, _, _ := syscall.RawSyscall(syscall.SYS_GETSID, 0, 0, 0)

	if fh, err := os.Open("/dev/tty"); err == nil {
		hasTty = true
		fh.Close()
	}

	return &ProcessInfo{
		Ppid:   os.Getppid(),
		Pid:    os.Getpid(),
		Uid:    os.Getuid(),
		Euid:   os.Geteuid(),
		Gid:    os.Getgid(),
		Egid:   os.Getegid(),
		Pgrp:   syscall.Getpgrp(),
		Sid:    int(sid),
		Dir:    cwd,
		Groups: grp,
		Args:   os.Args,
		Env:    os.Environ(),
		HasTty: hasTty,
	}
}
开发者ID:nangong92t,项目名称:go_src,代码行数:28,代码来源:helper.go

示例6: Update

// Expose CPU stats using KVM.
func (c *statCollector) Update(ch chan<- prometheus.Metric) (err error) {
	if os.Geteuid() != 0 && os.Getegid() != 2 {
		return errors.New("caller should be either root user or kmem group to access /dev/mem")
	}

	var errbuf *C.char
	kd := C.kvm_open(nil, nil, nil, C.O_RDONLY, errbuf)
	if errbuf != nil {
		return errors.New("failed to call kvm_open()")
	}
	defer C.kvm_close(kd)

	// The cp_time variable is an array of CPUSTATES long integers -- in
	// the same format as the kern.cp_time sysctl.  According to the
	// comments in sys/kern/kern_clock.c, the frequency of this timer will
	// be stathz (or hz, if stathz is zero).
	clockrate, err := getClockRate()
	if err != nil {
		return err
	}

	ncpus := C.kvm_getncpus(kd)
	for i := 0; i < int(ncpus); i++ {
		pcpu := C.kvm_getpcpu(kd, C.int(i))
		cp_time := ((*C.struct_pcpu)(unsafe.Pointer(pcpu))).pc_cp_time
		c.cpu.With(prometheus.Labels{"cpu": strconv.Itoa(i), "mode": "user"}).Set(float64(cp_time[C.CP_USER]) / clockrate)
		c.cpu.With(prometheus.Labels{"cpu": strconv.Itoa(i), "mode": "nice"}).Set(float64(cp_time[C.CP_NICE]) / clockrate)
		c.cpu.With(prometheus.Labels{"cpu": strconv.Itoa(i), "mode": "system"}).Set(float64(cp_time[C.CP_SYS]) / clockrate)
		c.cpu.With(prometheus.Labels{"cpu": strconv.Itoa(i), "mode": "interrupt"}).Set(float64(cp_time[C.CP_INTR]) / clockrate)
		c.cpu.With(prometheus.Labels{"cpu": strconv.Itoa(i), "mode": "idle"}).Set(float64(cp_time[C.CP_IDLE]) / clockrate)
	}
	c.cpu.Collect(ch)
	return err
}
开发者ID:juergenhoetzel,项目名称:node_exporter,代码行数:35,代码来源:cpu_freebsd.go

示例7: Update

// Expose CPU stats using KVM.
func (c *statCollector) Update(ch chan<- prometheus.Metric) (err error) {
	if os.Geteuid() != 0 && os.Getegid() != 2 {
		return errors.New("caller should be either root user or kmem group to access /dev/mem")
	}

	var errbuf *C.char
	kd := C.kvm_open(nil, nil, nil, C.O_RDONLY, errbuf)
	if errbuf != nil {
		return errors.New("failed to call kvm_open()")
	}
	defer C.kvm_close(kd)

	ncpus := C.kvm_getncpus(kd)
	for i := 0; i < int(ncpus); i++ {
		pcpu := C.kvm_getpcpu(kd, C.int(i))
		cp_time := ((*C.struct_pcpu)(unsafe.Pointer(pcpu))).pc_cp_time
		c.cpu.With(prometheus.Labels{"cpu": strconv.Itoa(i), "mode": "user"}).Set(float64(cp_time[C.CP_USER]))
		c.cpu.With(prometheus.Labels{"cpu": strconv.Itoa(i), "mode": "nice"}).Set(float64(cp_time[C.CP_NICE]))
		c.cpu.With(prometheus.Labels{"cpu": strconv.Itoa(i), "mode": "system"}).Set(float64(cp_time[C.CP_SYS]))
		c.cpu.With(prometheus.Labels{"cpu": strconv.Itoa(i), "mode": "interrupt"}).Set(float64(cp_time[C.CP_INTR]))
		c.cpu.With(prometheus.Labels{"cpu": strconv.Itoa(i), "mode": "idle"}).Set(float64(cp_time[C.CP_IDLE]))
	}
	c.cpu.Collect(ch)
	return err
}
开发者ID:robbiet480,项目名称:node_exporter,代码行数:26,代码来源:cpu_freebsd.go

示例8: main

func main() {
	flagUsername := flag.String("username", "nobody", "username for the unprivileged child")

	isChild, r, w, _, err := privsep.MaybeBecomeChild()
	if err != nil {
		log.Fatalf("MaybeBecomeChild failed: %s", err)
	}

	who := "parent"
	if isChild {
		who = "child"
	}
	log.Printf("%s: pid=%d uid=%d euid=%d gid=%d egid=%d",
		who, os.Getpid(), os.Getuid(), os.Geteuid(), os.Getgid(), os.Getegid())

	if isChild {
		child(r, w)
		return
	}

	if os.Getuid() != 0 {
		log.Print("Warning: this example only works when run as the root user")
	}

	_, r, w, err = privsep.CreateChild(*flagUsername, os.Args[0], nil, nil)
	if err != nil {
		log.Fatalf("CreateChild failed: %s", err)
	}
	parent(r, w)
}
开发者ID:jmptrader,项目名称:go-utils-1,代码行数:30,代码来源:pipe_example.go

示例9: main

func main() {
	flagUsername := flag.String("username", "nobody", "username for the unprivileged child")

	isChild, _, _, files, err := privsep.MaybeBecomeChild()
	if err != nil {
		log.Fatalf("MaybeBecomeChild failed: %s", err)
	}

	who := "parent"
	if isChild {
		who = "child"
	}
	log.Printf("%s: pid=%d uid=%d euid=%d gid=%d egid=%d",
		who, os.Getpid(), os.Getuid(), os.Geteuid(), os.Getgid(), os.Getegid())

	if isChild {
		if len(files) < 1 {
			log.Fatalf("no extra files: %v", files)
		}
		l, err := net.FileListener(files[0])
		if err != nil {
			log.Fatalf("FileListener: %s", err)
		}
		child(l)
		return
	}

	if os.Getuid() != 0 {
		log.Print("Warning: this example only works when run as the root user")
	}

	addr := "localhost:1111"
	laddr, err := net.ResolveTCPAddr("tcp", addr)
	if err != nil {
		log.Fatalf("resolve %s: %s", addr, err)
	}

	l, err := net.ListenTCP("tcp", laddr)
	if err != nil {
		log.Fatalf("listen %s: %s", laddr, err)
	}

	sock, err := l.File()
	if err != nil {
		log.Fatalf("fd: %s", err)
	}

	proc, _, _, err := privsep.CreateChild(*flagUsername, os.Args[0], nil, []*os.File{sock})
	if err != nil {
		log.Fatalf("CreateChild failed: %s", err)
	}

	sock.Close()

	// tidy up so child doesn't run forever
	defer proc.Kill()

	parent(laddr)
}
开发者ID:jmptrader,项目名称:go-utils-1,代码行数:59,代码来源:listener_example.go

示例10: mkroot

func mkroot() (*srv.File, error) {
	root := new(srv.File)
	err := root.Add(nil, "/", p.OsUsers.Uid2User(os.Geteuid()), p.OsUsers.Gid2Group(os.Getegid()), p.DMDIR|0555, nil)
	if err != nil {
		return nil, err
	}
	return root, nil
}
开发者ID:wkharold,项目名称:noeq9p,代码行数:8,代码来源:main.go

示例11: TestGroupName

func TestGroupName(t *testing.T) {
	if _, err := osgroup.GroupName(0); err != nil {
		t.Fatal(err)
	}
	gid := os.Getegid()
	name, err := osgroup.GroupName(gid)
	if err != nil {
		t.Fatal(err)
	}
	t.Logf("Your group's ID is %d, it's name is %q.", gid, name)
}
开发者ID:rdterner,项目名称:go-1,代码行数:11,代码来源:osgroup_test.go

示例12: Permissions

// Returns permissions in symbolic format.
func (i Info) Permissions() string {
	if i.Uid == os.Geteuid() {
		return encodePerms(uint8(i.Perm >> KeyPerm(16)))
	} else {
		fsgid, err := getfsgid()
		if (err == nil && i.Gid == int(fsgid)) || i.Gid == os.Getegid() {
			return encodePerms(uint8(i.Perm >> KeyPerm(8)))
		}
	}
	return encodePerms(uint8(i.Perm))
}
开发者ID:jsipprell,项目名称:keyctl,代码行数:12,代码来源:ref.go

示例13: StartCPUProfile

func StartCPUProfile() {
	filename := "cpu-" + strconv.Itoa(os.Getegid()) + ".pprof"
	f, err := os.Create(filename)
	if err != nil {
		glog.Fatal("record cpu profile failed: ", err)
	}
	pprof.StartCPUProfile(f)
	//time.Sleep(time.Duration(sec) * time.Second)

	fmt.Printf("create cpu profile %s \n", filename)
}
开发者ID:uileyar,项目名称:helloworld,代码行数:11,代码来源:glogtest.go

示例14: setupElfAuxv

func setupElfAuxv(u models.Usercorn) ([]Elf64Auxv, error) {
	// set up AT_RANDOM
	var tmp [16]byte
	if _, err := rand.Read(tmp[:]); err != nil {
		return nil, err
	}
	randAddr, err := u.PushBytes(tmp[:])
	if err != nil {
		return nil, err
	}
	// insert platform string
	platformAddr, err := u.PushBytes([]byte(u.Loader().Arch() + "\x00"))
	if err != nil {
		return nil, err
	}
	// main auxv table
	auxv := []Elf64Auxv{
		// TODO: set/track a page size somewhere - on Arch.OS?
		{ELF_AT_PAGESZ, 4096},
		{ELF_AT_BASE, u.InterpBase()},
		{ELF_AT_FLAGS, 0},
		{ELF_AT_ENTRY, uint64(u.BinEntry())},
		{ELF_AT_UID, uint64(os.Getuid())},
		{ELF_AT_EUID, uint64(os.Geteuid())},
		{ELF_AT_GID, uint64(os.Getgid())},
		{ELF_AT_EGID, uint64(os.Getegid())},
		{ELF_AT_PLATFORM, platformAddr},
		{ELF_AT_CLKTCK, 100}, // 100hz, totally fake
		{ELF_AT_RANDOM, randAddr},
		{ELF_AT_NULL, 0},
	}
	// add phdr information if present in binary
	phdrOff, _, phdrCount := u.Loader().Header()
	segments, _ := u.Loader().Segments()
	for _, s := range segments {
		if s.ContainsPhys(phdrOff) {
			phdrOff += s.Addr
			break
		}
	}
	phdrEnt := 56
	if u.Bits() == 32 {
		phdrEnt = 56 // FIXME
	}
	if phdrOff > 0 {
		auxv = append(auxv, []Elf64Auxv{
			{ELF_AT_PHDR, phdrOff},
			{ELF_AT_PHENT, uint64(phdrEnt)},
			{ELF_AT_PHNUM, uint64(phdrCount)},
		}...)
	}
	return auxv, nil
}
开发者ID:x56,项目名称:usercorn,代码行数:53,代码来源:elf_auxv.go

示例15: main

func main() {
	var err error

	flag.Parse()
	rsrv.user = p.OsUsers.Uid2User(os.Geteuid())
	rsrv.group = p.OsUsers.Gid2Group(os.Getegid())
	rsrv.blksz = *blksize
	rsrv.blkchan = make(chan []byte, 2048)
	rsrv.zero = make([]byte, rsrv.blksz)

	root := new(RFile)
	err = root.Add(nil, "/", rsrv.user, nil, p.DMDIR|0777, root)
	if err != nil {
		log.Println(fmt.Sprintf("Error: %s", err))
		return
	}

	l := p.NewLogger(*logsz)
	rsrv.srv = srv.NewFileSrv(&root.File)
	rsrv.srv.Dotu = true
	rsrv.srv.Debuglevel = *debug
	rsrv.srv.Start(rsrv.srv)
	rsrv.srv.Id = "ramfs"
	rsrv.srv.Log = l

	cert := make([]tls.Certificate, 1)
	cert[0].Certificate = [][]byte{testCertificate}
	cert[0].PrivateKey = testPrivateKey

	ls, oerr := tls.Listen("tcp", *addr, &tls.Config{
		Rand:               rand.Reader,
		Certificates:       cert,
		CipherSuites:       []uint16{tls.TLS_ECDHE_RSA_WITH_RC4_128_SHA},
		InsecureSkipVerify: true,
	})
	if oerr != nil {
		log.Println("can't listen:", oerr)
		return
	}

	err = rsrv.srv.StartListener(ls)
	if err != nil {
		log.Println(fmt.Sprintf("Error: %s", err))
		return
	}
	return
}
开发者ID:KevinMGranger,项目名称:go9p,代码行数:47,代码来源:tlsramfs.go


注:本文中的os.Getegid函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。