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


Golang minilog.Errorln函数代码示例

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


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

示例1: getDuration

// Returns the duration of a given kbrecording file
func getDuration(filename string) time.Duration {
	d := 0

	f, _ := os.Open(filename)
	scanner := bufio.NewScanner(f)
	for scanner.Scan() {
		s := strings.SplitN(scanner.Text(), ":", 2)
		// Ignore comments in the vnc file
		if s[0] == "#" {
			continue
		}
		i, err := strconv.Atoi(s[0])
		if err != nil {
			log.Errorln(err)
			return 0
		}
		d += i
	}

	duration, err := time.ParseDuration(strconv.Itoa(d) + "ns")
	if err != nil {
		log.Errorln(err)
		return 0
	}

	return duration
}
开发者ID:cdshann,项目名称:minimega,代码行数:28,代码来源:vnc_record.go

示例2: handler

// client connection handler and transport. Messages on chan out are sent to
// the ron server. Incoming messages are put on the message queue to be routed
// by the mux. The entry to handler() also creates the tunnel transport.
func (c *Client) handler() {
	log.Debug("ron handler")

	// create a tunnel
	stop := make(chan bool)
	defer func() { stop <- true }()
	go c.handleTunnel(false, stop)

	enc := gob.NewEncoder(c.conn)
	dec := gob.NewDecoder(c.conn)

	// handle client i/o
	go func() {
		for {
			m := <-c.out
			err := enc.Encode(m)
			if err != nil {
				log.Errorln(err)
				return
			}
		}
	}()

	for {
		var m Message
		err := dec.Decode(&m)
		if err != nil {
			log.Errorln(err)
			return
		}
		c.in <- &m
	}
}
开发者ID:jenareljam,项目名称:minimega,代码行数:36,代码来源:client.go

示例3: vncWsHandler

func vncWsHandler(ws *websocket.Conn) {
	// URL should be of the form `/ws/<vm_name>`
	path := strings.Trim(ws.Config().Location.Path, "/")

	fields := strings.Split(path, "/")
	if len(fields) != 2 {
		return
	}
	vmName := fields[1]

	vms := GlobalVMs()
	vm, err := vms.findKvmVM(vmName)
	if err != nil {
		log.Errorln(err)
		return
	}

	// Undocumented "feature" of websocket -- need to set to PayloadType in
	// order for a direct io.Copy to work.
	ws.PayloadType = websocket.BinaryFrame

	// connect to the remote host
	rhost := fmt.Sprintf("%v:%v", vm.Host, vm.VNCPort)
	remote, err := net.Dial("tcp", rhost)
	if err != nil {
		log.Errorln(err)
		return
	}
	defer remote.Close()

	go io.Copy(ws, remote)
	io.Copy(remote, ws)

	log.Info("ws client disconnected from %v", rhost)
}
开发者ID:cdshann,项目名称:minimega,代码行数:35,代码来源:tunnel.go

示例4: sendFile

// return a file to a client requesting it via the clients GetFile() call
func (s *Server) sendFile(m *Message) {
	log.Debug("ron sendFile: %v", m.Filename)

	filename := filepath.Join(s.path, m.Filename)
	info, err := os.Stat(filename)
	if err != nil {
		e := fmt.Errorf("file %v does not exist: %v", filename, err)
		m.Error = e.Error()
		log.Errorln(e)
	} else if info.IsDir() {
		e := fmt.Errorf("file %v is a directory", filename)
		m.Error = e.Error()
		log.Errorln(e)
	} else {
		// read the file
		m.File, err = ioutil.ReadFile(filename)
		if err != nil {
			e := fmt.Errorf("file %v: %v", filename, err)
			m.Error = e.Error()
			log.Errorln(e)
		}
	}

	// route this message ourselves instead of using the mux, because we
	// want the type to still be FILE
	s.clientLock.Lock()
	defer s.clientLock.Unlock()
	if c, ok := s.clients[m.UUID]; ok {
		c.out <- m
	} else {
		log.Error("no such client %v", m.UUID)
	}
}
开发者ID:ITLivLab,项目名称:minimega,代码行数:34,代码来源:server.go

示例5: handleRemote

func (t *Tunnel) handleRemote(m *tunnelMessage) {
	host := m.Host
	port := m.Port
	TID := m.TID

	// attempt to connect to the host/port
	conn, err := net.Dial("tcp", fmt.Sprintf("%v:%v", host, port))
	if err == nil {
		in := t.chans.add(TID)
		go t.transfer(in, conn, TID)
		return
	}

	log.Errorln(err)

	resp := &tunnelMessage{
		Type:  CLOSED,
		TID:   TID,
		Error: err.Error(),
	}

	if err := t.sendMessage(resp); err != nil {
		log.Errorln(err)
	}
}
开发者ID:cdshann,项目名称:minimega,代码行数:25,代码来源:mux.go

示例6: dirHandler

// dirHandler serves a directory listing for the requested path, rooted at basePath.
func dirHandler(w http.ResponseWriter, r *http.Request) {
	if r.URL.Path == "/favicon.ico" {
		http.Error(w, "not found", 404)
		return
	}
	const base = "."
	name := filepath.Join(base, r.URL.Path)

	if isDoc(name) {
		err := renderDoc(w, name)
		if err != nil {
			log.Errorln(err)
			http.Error(w, err.Error(), 500)
		}
		return
	}
	if isDir, err := dirList(w, name); err != nil {
		log.Errorln(err)
		http.Error(w, err.Error(), 500)
		return
	} else if isDir {
		return
	}
	http.FileServer(http.Dir(*f_root)).ServeHTTP(w, r)
}
开发者ID:jenareljam,项目名称:minimega,代码行数:26,代码来源:dir.go

示例7: kill

func kill(pid int) {
	Client.Lock()
	defer Client.Unlock()

	if pid == -1 {
		// Wildcard
		log.Info("killing all processes")
		for _, p := range Client.Processes {
			if err := p.process.Kill(); err != nil {
				log.Errorln(err)
			}
		}

		return
	}

	log.Info("killing PID %v", pid)
	if p, ok := Client.Processes[pid]; ok {
		if err := p.process.Kill(); err != nil {
			log.Errorln(err)
		}

		return
	}

	log.Error("no such process: %v", pid)
}
开发者ID:cdshann,项目名称:minimega,代码行数:27,代码来源:commands.go

示例8: containerFifos

func containerFifos(vmFSPath string, vmInstancePath string, vmFifos int) error {
	err := os.Mkdir(filepath.Join(vmFSPath, "/dev/fifos"), 0755)
	if err != nil {
		log.Errorln(err)
		return nil
	}
	for i := 0; i < vmFifos; i++ {
		src := filepath.Join(vmInstancePath, fmt.Sprintf("fifo%v", i))
		_, err := os.Stat(src)
		if err != nil {
			log.Errorln(err)
			return err
		}

		dst := filepath.Join(vmFSPath, fmt.Sprintf("/dev/fifos/fifo%v", i))

		// dst must exist for bind mounting to work
		f, err := os.Create(dst)
		if err != nil {
			log.Errorln(err)
			return err
		}
		f.Close()
		log.Debug("bind mounting: %v -> %v", src, dst)
		err = syscall.Mount(src, dst, "", syscall.MS_BIND, "")
		if err != nil {
			log.Errorln(err)
			return err
		}
	}
	return nil
}
开发者ID:seedubb,项目名称:minimega,代码行数:32,代码来源:container.go

示例9: connectVNC

func (vm *KvmVM) connectVNC() error {
	l, err := net.Listen("tcp", "")
	if err != nil {
		return err
	}

	// Keep track of shim so that we can close it later
	vm.vncShim = l
	vm.VNCPort = l.Addr().(*net.TCPAddr).Port
	ns := fmt.Sprintf("%v:%v", vm.Namespace, vm.Name)

	go func() {
		defer l.Close()

		for {
			// Sit waiting for new connections
			remote, err := l.Accept()
			if err != nil && strings.Contains(err.Error(), "use of closed network connection") {
				return
			} else if err != nil {
				log.Errorln(err)
				return
			}

			go func() {
				defer remote.Close()

				// Dial domain socket
				local, err := net.Dial("unix", vm.path("vnc"))
				if err != nil {
					log.Error("unable to dial vm vnc: %v", err)
					return
				}
				defer local.Close()

				// copy local -> remote
				go io.Copy(remote, local)

				// Reads will implicitly copy from remote -> local
				tee := io.TeeReader(remote, local)
				for {
					// Read
					msg, err := vnc.ReadClientMessage(tee)
					if err != nil {
						if err == io.EOF || strings.Contains(err.Error(), "closed network") {
							break
						}
						log.Errorln(err)
					}
					if r, ok := vncKBRecording[ns]; ok {
						r.RecordMessage(msg)
					}
				}
			}()
		}
	}()

	return nil
}
开发者ID:cdshann,项目名称:minimega,代码行数:59,代码来源:kvm.go

示例10: recvFiles

// recvFiles retrieves a list of files from the ron server by requesting each
// one individually.
func recvFiles(files []*ron.File) {
	start := time.Now()
	var size int64

	for _, v := range files {
		log.Info("requesting file %v", v)

		dst := filepath.Join(*f_path, "files", v.Name)

		if _, err := os.Stat(dst); err == nil {
			// file exists (TODO: overwrite?)
			log.Info("skipping %v -- already exists")
			continue
		}

		m := &ron.Message{
			Type:     ron.MESSAGE_FILE,
			UUID:     Client.UUID,
			Filename: v.Name,
		}

		if err := sendMessage(m); err != nil {
			log.Error("send failed: %v", err)
			return
		}

		resp := <-Client.fileChan
		if resp.Filename != v.Name {
			log.Error("filename mismatch: %v != %v", resp.Filename, v.Name)
			continue
		}

		if resp.Error != "" {
			log.Error("%v", resp.Error)
			continue
		}

		dir := filepath.Dir(dst)

		if err := os.MkdirAll(dir, os.FileMode(0770)); err != nil {
			log.Errorln(err)
			continue
		}

		if err := ioutil.WriteFile(dst, resp.File, v.Perm); err != nil {
			log.Errorln(err)
			continue
		}

		size += int64(len(resp.File))
	}

	d := time.Since(start)
	rate := (float64(size) / 1024 / d.Seconds())

	log.Debug("received %v bytes in %v (%v KBps)", size, d, rate)

	return
}
开发者ID:cdshann,项目名称:minimega,代码行数:61,代码来源:files.go

示例11: runCommand

func runCommand(command []string, background bool) (string, string) {
	var stdout bytes.Buffer
	var stderr bytes.Buffer

	path, err := exec.LookPath(command[0])
	if err != nil {
		log.Errorln(err)
		return "", err.Error()
	}

	cmd := &exec.Cmd{
		Path:   path,
		Args:   command,
		Stdout: &stdout,
		Stderr: &stderr,
	}
	log.Info("executing: %v", command)

	if background {
		log.Debug("starting in background")
		if err := cmd.Start(); err != nil {
			log.Errorln(err)
			return "", stderr.String()
		}

		pid := cmd.Process.Pid

		Client.Lock()
		defer Client.Unlock()
		Client.Processes[pid] = &Process{
			PID:     pid,
			Command: command,
			process: cmd.Process,
		}

		go func() {
			cmd.Wait()
			log.Info("command exited: %v", command)
			if stdout.Len() > 0 {
				log.Info(stdout.String())
			}
			if stderr.Len() > 0 {
				log.Info(stderr.String())
			}

			Client.Lock()
			defer Client.Unlock()
			delete(Client.Processes, pid)
		}()

		return "", ""
	}

	if err := cmd.Run(); err != nil {
		log.Errorln(err)
	}
	return stdout.String(), stderr.String()
}
开发者ID:cdshann,项目名称:minimega,代码行数:58,代码来源:commands.go

示例12: sshHandleChannel

func sshHandleChannel(conn net.Conn, newChannel ssh.NewChannel) {
	// Channels have a type, depending on the application level protocol
	// intended. In the case of a shell, the type is "session" and ServerShell
	// may be used to present a simple terminal interface.
	if newChannel.ChannelType() != "session" {
		newChannel.Reject(ssh.UnknownChannelType, "unknown channel type")
		return
	}
	channel, requests, err := newChannel.Accept()
	if err != nil {
		log.Errorln(err)
		return
	}

	// Sessions have out-of-band requests such as "shell", "pty-req" and "env".
	// Here we handle only the "shell" request.
	go func(in <-chan *ssh.Request) {
		for req := range in {
			ok := false
			switch req.Type {
			case "shell":
				ok = true
				if len(req.Payload) > 0 {
					// We don't accept any commands, only the default shell.
					ok = false
				}
			case "pty-req":
				ok = true
			}
			req.Reply(ok, nil)
		}
	}(requests)

	term := terminal.NewTerminal(channel, "> ")

	go func() {
		defer channel.Close()

		for {
			line, err := term.ReadLine()
			start := time.Now().UnixNano()
			if err != nil {
				if err != io.EOF {
					log.Errorln(err)
				}
				return
			}
			sshReportChan <- uint64(len(line))
			// just echo the message
			log.Debugln("ssh received: ", line)
			term.Write([]byte(line))
			term.Write([]byte{'\r', '\n'})

			stop := time.Now().UnixNano()
			log.Info("ssh %v %vns", conn.RemoteAddr(), uint64(stop-start))
		}
	}()
}
开发者ID:cdshann,项目名称:minimega,代码行数:58,代码来源:ssh.go

示例13: handle

func (t *Tunnel) handle(in chan *tunnelMessage, conn net.Conn, TID int32) {
	// begin forwarding until an error occurs
	go func() {
		for {
			select {
			case <-t.quit:
				conn.Close()
				return
			case m := <-in:
				if m.Type == CLOSED {
					if m.Error != "" {
						log.Errorln(m.Error)
						conn.Close()
						break
					}
				}
				_, err := conn.Write(m.Data)
				if err != nil {
					log.Errorln(err)
					conn.Close()
					t.out <- &tunnelMessage{
						Type:  CLOSED,
						TID:   TID,
						Error: err.Error(),
					}
					break
				}
			}
		}
	}()

	for {
		var buf = make([]byte, BUFFER_SIZE)
		n, err := conn.Read(buf)
		if err != nil {
			conn.Close()
			closeMessage := &tunnelMessage{
				Type: CLOSED,
				TID:  TID,
			}
			if err != io.EOF && !strings.Contains(err.Error(), errClosing) {
				log.Errorln(err)
				closeMessage.Error = err.Error()
			}
			t.out <- closeMessage
			t.unregisterTID(TID)
			break
		}
		m := &tunnelMessage{
			Type: DATA,
			TID:  TID,
			Data: buf[:n],
		}
		t.out <- m
	}
}
开发者ID:npe9,项目名称:minimega,代码行数:56,代码来源:minitunnel.go

示例14: containerNuke

// aggressively cleanup container cruff, called by the nuke api
func containerNuke() {
	// walk minimega cgroups for tasks, killing each one
	cgroupFreezer := filepath.Join(*f_cgroup, "freezer", "minimega")
	cgroupMemory := filepath.Join(*f_cgroup, "memory", "minimega")
	cgroupDevices := filepath.Join(*f_cgroup, "devices", "minimega")
	cgroups := []string{cgroupFreezer, cgroupMemory, cgroupDevices}

	for _, cgroup := range cgroups {
		if _, err := os.Stat(cgroup); err == nil {
			err := filepath.Walk(cgroup, containerNukeWalker)
			if err != nil {
				log.Errorln(err)
			}
		}
	}

	// Allow udev to sync
	time.Sleep(time.Second * 1)

	// umount megamount_*, this include overlayfs mounts
	d, err := ioutil.ReadFile("/proc/mounts")
	if err != nil {
		log.Errorln(err)
	} else {
		mounts := strings.Split(string(d), "\n")
		for _, m := range mounts {
			if strings.Contains(m, "megamount") {
				mount := strings.Split(m, " ")[1]
				if err := syscall.Unmount(mount, 0); err != nil {
					log.Error("overlay unmount %s: %v", m, err)
				}
			}
		}
	}

	containerCleanCgroupDirs()

	// remove meganet_* from /var/run/netns
	if _, err := os.Stat("/var/run/netns"); err == nil {
		netns, err := ioutil.ReadDir("/var/run/netns")
		if err != nil {
			log.Errorln(err)
		} else {
			for _, n := range netns {
				if strings.Contains(n.Name(), "meganet") {
					err := os.Remove(filepath.Join("/var/run/netns", n.Name()))
					if err != nil {
						log.Errorln(err)
					}
				}
			}
		}
	}
}
开发者ID:cdshann,项目名称:minimega,代码行数:55,代码来源:container.go

示例15: containerTeardown

func containerTeardown() {
	if cgroupInitialized {
		err := os.Remove(CGROUP_PATH)
		if err != nil {
			log.Errorln(err)
		}
		err = syscall.Unmount(CGROUP_ROOT, 0)
		if err != nil {
			log.Errorln(err)
		}
	}
}
开发者ID:seedubb,项目名称:minimega,代码行数:12,代码来源:container.go


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