Example #1
0
func setupListener(c *Config, m Matcher, watcher *fsnotify.Watcher) error {
	if len(m.Dirs) == 0 {
		m.Dirs = []string{""}
	}

	for _, d := range m.Dirs {
		dir := c.BaseDir + "/" + d
		if err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
			if err != nil {
				return fmt.Errorf("Walk directories failed: %v", err)
			}
			if m.excludeDirMap[filepath.Base(path)] {
				log.VV("Skipping directory %v as it has been excluded", path)
				return filepath.SkipDir
			}
			if info.IsDir() {
				log.VV("Add watch for directory %v", path)
				c.configsMap[filepath.Clean(path)] = &m
				watcher.Add(path)
			}
			return nil
		}); err != nil {
			return err
		}
	}
	return nil
}
Example #2
0
// Interrupt sends Ctrl-Break to the task's process group.
func (t *Task) Interrupt() error {
	log.VV("Requested Ctrl-Break on task")
	r, _, err := procGenerateConsoleCtrlEvent.Call(syscall.CTRL_BREAK_EVENT, uintptr(t.pgid))
	if r != 0 {
		return fmt.Errorf("r = %v err: %v", r, err)
	}
	return nil
}
Example #3
0
// killProcess terminates a given pid using TerminateProcess.
func killProcess(pid uint32) error {
	handle, err := syscall.OpenProcess(syscall.PROCESS_TERMINATE, false /* inheritHandle */, pid)
	if err != nil {
		return err
	}
	defer syscall.CloseHandle(handle)

	log.VV("TerminateProcess(%v) with handle %v", pid, handle)
	return syscall.TerminateProcess(handle, 1)
}
Example #4
0
// IsMatch checks whether an event on the given path should cause a reload.
func IsMatch(c *Config, path string) bool {
	dir, file := filepath.Split(path)
	if len(dir) == 0 {
		dir = "./"
	}
	dc := c.configsMap[filepath.Clean(dir)]
	if dc == nil {
		return false
	}
	log.VV("Found updated file (%v) in watched directory, config: %+v", path, dc)

	// If there are no patterns, then we treat it as a wildcard matching everything.
	if len(dc.Patterns) == 0 {
		return true
	}
	for _, p := range dc.Patterns {
		if match, err := filepath.Match(p, file); err == nil && match {
			return true
		}
	}
	return false
}
Example #5
0
// Interrupt sends the same signal as a Ctrl-C to the task.
func (t *Task) Interrupt() error {
	log.VV("Requested Ctrl-C on task")
	return syscall.Kill(-t.pgid, syscall.SIGINT)
}