Beispiel #1
0
// these assertions apply to any daemon process
func assertProcessInfo(c *C, process *Process, info *helper.ProcessInfo) {
	selfInfo := helper.CurrentProcessInfo()

	c.Check(selfInfo.Pgrp, Not(Equals), info.Pgrp) // process group will change

	c.Check(selfInfo.Sid, Not(Equals), info.Sid) // session id will change

	c.Check(false, Equals, info.HasTty) // no controling terminal

	sort.Strings(selfInfo.Env)
	sort.Strings(info.Env)
	c.Check(selfInfo.Env, Not(DeepEquals), info.Env) // sanitized env will differ

	// check expected process working directory
	// (and follow symlinks, e.g. darwin)
	ddir, _ := filepath.EvalSymlinks(process.Dir)
	idir, _ := filepath.EvalSymlinks(info.Dir)
	c.Check(ddir, Equals, idir)

	// spawned process argv[] should be the same as the process.Start command
	c.Check(process.Start, Equals, strings.Join(info.Args, " "))

	// check when configured to run as different user and/or group
	if process.Uid == "" {
		c.Check(selfInfo.Uid, Equals, info.Uid)
		c.Check(selfInfo.Euid, Equals, info.Euid)
	} else {
		c.Check(selfInfo.Uid, Not(Equals), info.Uid)
		c.Check(selfInfo.Euid, Not(Equals), info.Euid)
	}

	if process.Gid == "" {
		if process.Uid == "" {
			c.Check(selfInfo.Gid, Equals, info.Gid)
			c.Check(selfInfo.Egid, Equals, info.Egid)
		} else {
			c.Check(selfInfo.Gid, Not(Equals), info.Gid)
			c.Check(selfInfo.Egid, Not(Equals), info.Egid)
		}
	} else {
		c.Check(selfInfo.Gid, Not(Equals), info.Gid)
		c.Check(selfInfo.Egid, Not(Equals), info.Egid)
	}
}
Beispiel #2
0
func saveProcessInfo() {
	file := filepath.Join(*dir, *name+".json")
	info := helper.CurrentProcessInfo()
	info.Restarts = restarts
	helper.WriteData(info, file)
}