Exemplo n.º 1
0
func ExpandPath(path string) string {
	var p EXPAND_PATH
	if !p.Parse(path) {
		log4go.Error("Failed to parse expand_path expression. Input data: %s, Error: %s, Parsed tree: %s", path, p.Error(), p.RootNode())
		return path
	}
	return eval(p.RootNode())
}
Exemplo n.º 2
0
func (d *Daemon) handleConn(conn net.Conn) {
	s := time.Now()
	conn.SetDeadline(time.Time{})
	codec := jsonrpc.NewServerCodec(conn)
	defer func() {
		codec.Close()
		if r := recover(); r != nil {
			log4go.Error("Recovered from panic: %v, stack: %s", r, string(debug.Stack()))
		}
		log4go.Debug("Serviced in %f milliseconds", time.Since(s).Seconds()*1000)
	}()
	for {
		if err := d.server.ServeRequest(codec); err != nil {
			log4go.Error("Error handling request: %v", err)
			break
		}
	}
}
Exemplo n.º 3
0
func installHooks() error {
	for i, ed := range editor.List() {
		if *instArgs[i] {
			if err := ed.Install(); err != nil {
				return log4go.Error("Failed to install editor plugin for %s: %s", ed.Description(), err)
			}
		}
	}
	return nil
}
Exemplo n.º 4
0
func (c *Cache) watchthread() {
	for {
		select {
		case ev := <-c.watch.Event:
			c.load <- loadreq{ev.Name, true}
		case err := <-c.watch.Error:
			log4go.Error("error:", err)
		}
	}
}
Exemplo n.º 5
0
func (d *Daemon) serverloop() error {
	errorcount := 0
	sigchan := make(chan os.Signal)
	conchan := make(chan net.Conn)
	errchan := make(chan error)
	signal.Notify(sigchan, os.Interrupt, os.Kill)
	go func() {
		for {
			if conn, err := d.l.Accept(); err != nil {
				if d.quit {
					return
				}
				errchan <- log4go.Error("Error accepting connection: %s", err)
			} else {
				conchan <- conn
			}
		}
	}()
outer:
	for {
		select {
		case s := <-sigchan:
			log4go.Debug("Exiting due to signal: %s", s)
			d.quit = true
			break outer
		case conn := <-conchan:
			go d.handleConn(conn)
		case <-errchan:
			errorcount++
			if errorcount > 10 {
				return log4go.Error("Too many errors, shutting server down")
			}
		}
	}
	return nil
}
Exemplo n.º 6
0
func (c *Cache) watchthread() {
	for {
		select {
		case ev := <-c.watch.Events:
			if ev.Op == fsnotify.Remove {
				// File no longer exists so we wont get events for it anymore
				// with the old add. Thus need to re-add it like this so that
				// we get events for the new file once it is created.
				if err := c.watch.Add(ev.Name); err != nil {
					log4go.Warn("Failed to re-watch for removed file %s: %s", ev.Name, err)
				}
			}

			c.load <- loadreq{ev.Name, true}
		case err := <-c.watch.Errors:
			log4go.Error("error:", err)
		}
	}
}