Exemple #1
0
// CleanupEnv has to be called on application shutdown. Will remove the pidfile.
func CleanupEnv(cfg *config.Config) error {
	if !utils.FileExists(cfg.System.Pidfile) {
		return fmt.Errorf("Pidfile %s does not exists.", cfg.System.Pidfile)
	}
	var b, err = ioutil.ReadFile(cfg.System.Pidfile)
	if err != nil {
		return err
	}
	var pid int
	pid, err = strconv.Atoi(string(b))
	if err != nil {
		return err
	}
	if pid != os.Getpid() {
		return fmt.Errorf("File had different pid: %d", pid)
	}

	return os.Remove(cfg.System.Pidfile)
}
Exemple #2
0
// CleanupEnv has to be called on application shutdown. Will remove the pidfile.
func CleanupEnv(cfg *config.Config) error {
	if !utils.FileExists(cfg.System.Pidfile) {
		return fmt.Errorf("Pidfile %s does not exists.", cfg.System.Pidfile)
	}
	fh, err := os.Open(cfg.System.Pidfile)
	if err != nil {
		return err
	}
	var pid int
	_, err = fmt.Fscanf(fh, "%d", &pid)
	fh.Close()
	if err != nil {
		return err
	}
	if pid != os.Getpid() {
		return fmt.Errorf("File had different pid: %d", pid)
	}

	return os.Remove(cfg.System.Pidfile)
}
Exemple #3
0
func TestWithFullFilesystem(t *testing.T) {

	targetPidFile := "/dev/full"

	// We will run this test only on operating sytems which has the
	// /dev/full device
	if !utils.FileExists(targetPidFile) {
		t.Skip("This OS does not support /dev/full")
	}

	cfg := getCfg(config.SystemSection{Pidfile: targetPidFile})
	err := SetupEnv(cfg)

	if err == nil {
		t.Error("There was no error with pidfile in full filesystem")
	}

	if pathErr, ok := err.(*os.PathError); !ok || pathErr.Op != "write" {
		t.Errorf("Error was for creating the file. Not for writing in it: `%s`", err)
	}

}