當前位置: 首頁>>代碼示例>>Golang>>正文


Golang sys.Run函數代碼示例

本文整理匯總了Golang中github.com/r3boot/rlib/sys.Run函數的典型用法代碼示例。如果您正苦於以下問題:Golang Run函數的具體用法?Golang Run怎麽用?Golang Run使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Run函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: GetType

func (link *Link) GetType() (intf_type byte, err error) {
	l := *link

	if !l.HasLink() {
		if err = l.SetLinkStatus(LINK_UP); err != nil {
			err = errors.New("SetLinkStatus failed: " + err.Error())
			return
		}
	}

	stdout, _, err := sys.Run(l.CmdIfconfig, l.Interface.Name)
	if err != nil {
		return
	}

	for _, line := range stdout {
		if strings.Contains(line, IFCONFIG_MEDIA_ETHERNET) {
			intf_type = INTF_TYPE_ETHERNET
			return
		} else if strings.Contains(line, IFCONFIG_MEDIA_WIRELESS) {
			intf_type = INTF_TYPE_WIRELESS
			return
		}
	}

	err = errors.New("Unknown interface type")

	return
}
開發者ID:r3boot,項目名稱:rlib,代碼行數:29,代碼來源:link_freebsd.go

示例2: Stop

/*
 * Stop dhcpcd on intf. Print an error if anything goes wrong
 */
func (d Dhcpcd) Stop() (err error) {
	_, _, err = sys.Run(d.CmdDhcpcd, "-k", d.Interface)
	if err != nil {
		err = errors.New("Failed to stop dhcpcd: " + err.Error())
	}
	return
}
開發者ID:r3boot,項目名稱:rlib,代碼行數:10,代碼來源:dhcpcd.go

示例3: AddAddress

func (i Ip) AddAddress(ip string, af byte) (err error) {
	use_af, err := mkUseAf(af)
	if err != nil {
		return
	}

	sys.Run("/sbin/ip", use_af, "addr", "add", ip, "dev", i.Interface)

	return
}
開發者ID:r3boot,項目名稱:rlib,代碼行數:10,代碼來源:ipaddress_linux.go

示例4: GetMTU

func (l Link) GetMTU() (mtu int, err error) {
	stdout, _, err := sys.Run(l.CmdIfconfig, l.Interface.Name)
	if err != nil {
		return
	}

	raw_mtu := strings.Fields(stdout[0])[5]
	mtu, err = strconv.Atoi(raw_mtu)
	return
}
開發者ID:r3boot,項目名稱:rlib,代碼行數:10,代碼來源:link_freebsd.go

示例5: AddAddress

func (i Ip) AddAddress(ip string, af byte) (err error) {
	use_af, err := mkUseAf(af)
	if err != nil {
		return
	}

	sys.Run("/sbin/ifconfig", i.Interface, use_af, "alias", ip)

	return
}
開發者ID:r3boot,項目名稱:rlib,代碼行數:10,代碼來源:ipaddress_freebsd.go

示例6: RemoveRoute

func (r RIB) RemoveRoute(network net.IPNet) (err error) {
	_, use_af, err := getAfDetails(network)
	if err != nil {
		return
	}

	use_af = "-" + use_af

	_, _, err = sys.Run("/sbin/route", "delete", use_af, network.String())

	return
}
開發者ID:r3boot,項目名稱:rlib,代碼行數:12,代碼來源:rib_freebsd.go

示例7: AddRoute

func (r RIB) AddRoute(network net.IPNet, gateway net.IP) (err error) {
	_, use_af, err := getAfDetails(network)
	if err != nil {
		return
	}

	use_af = "-" + use_af

	_, _, err = sys.Run("/sbin/route", "add", use_af, network.String(), gateway.String())

	return
}
開發者ID:r3boot,項目名稱:rlib,代碼行數:12,代碼來源:rib_freebsd.go

示例8: DisableRA

func (r RA) DisableRA() (err error) {
	enabled, err := r.AcceptsRA()
	if err != nil {
		return
	}

	if enabled {
		_, _, err = sys.Run(r.CmdIfconfig, r.Interface, IFCONFIG_USE_AF_INET6, "-"+IFCONFIG_ENABLE_RTADV)
	}

	return
}
開發者ID:r3boot,項目名稱:rlib,代碼行數:12,代碼來源:ra_freebsd.go

示例9: FlushAddresses

func (i Ip) FlushAddresses(af byte) (err error) {
	use_af, err := mkUseAf(af)
	if err != nil {
		return
	}

	if len(use_af) == 0 {
		return
	}

	sys.Run("/sbin/ip", use_af, "addr", "flush", "dev", i.Interface, "scope", "global")

	return
}
開發者ID:r3boot,項目名稱:rlib,代碼行數:14,代碼來源:ipaddress_linux.go

示例10: SetLinkStatus

func (l Link) SetLinkStatus(link_status byte) (err error) {
	var status string
	if link_status == LINK_UP {
		status = "up"
	} else if link_status == LINK_DOWN {
		status = "down"
	} else {
		err = errors.New("Unknown link status: " + strconv.Itoa(int(link_status)))
		return
	}

	_, _, err = sys.Run(l.CmdIfconfig, l.Interface.Name, status)
	return
}
開發者ID:r3boot,項目名稱:rlib,代碼行數:14,代碼來源:link_freebsd.go

示例11: AcceptsRA

func (r RA) AcceptsRA() (result bool, err error) {
	stdout, _, err := sys.Run(r.CmdIfconfig, r.Interface, IFCONFIG_USE_AF_INET6)
	if err != nil {
		return
	}

	for _, line := range stdout {
		if strings.Contains(line, IFCONFIG_ND6_OPTIONS) {
			result = strings.Contains(line, IFCONFIG_ACCEPT_RTADV)
			return
		}
	}

	return
}
開發者ID:r3boot,項目名稱:rlib,代碼行數:15,代碼來源:ra_freebsd.go

示例12: RemoveConfig

func (rc *ResolvConf) RemoveConfig() {
	r := *rc

	_, _, err := sys.Run(r.CmdResolvconf, "-d", r.Interface)
	if err != nil {
		err = errors.New("Failed to remove config for " + r.Interface + ": " + err.Error())
	}

	if err = r.UpdateResolvConf(); err != nil {
		err = errors.New("Failed to update /etc/resolv.conf: " + err.Error())
		return
	}

	*rc = r
}
開發者ID:r3boot,項目名稱:rlib,代碼行數:15,代碼來源:resolvconf.go

示例13: Start

func (ovpn *OpenVPN) Start() (err error) {
	o := *ovpn

	_, _, err = sys.Run(o.CmdOpenvpn, "--daemon", "--config", o.ConfigFile, "--writepid", o.PidFile)
	if err != nil {
		err = errors.New("Failed to start OpenVPN: " + err.Error())
		return
	}

	var timeout_counter = 0
	for {
		if timeout_counter >= OVPN_STARTUP_MAXWAIT {
			err = errors.New("Connection establishment took too long")
			o.Stop()
			break
		}

		is_connected, e := o.IsConnected()
		if e != nil {
			err = e
			return
		}

		if is_connected {
			break
		}

		time.Sleep(1 * time.Second)
		timeout_counter += 1
	}

	raw_intf, err := net.InterfaceByName(o.InterfaceName)
	intf, err := network.InterfaceFactory(*raw_intf)
	if err != nil {
		return
	}

	o.Interface = intf

	*ovpn = o

	return
}
開發者ID:r3boot,項目名稱:rlib,代碼行數:43,代碼來源:openvpn.go

示例14: IsRunning

func (s Service) IsRunning(name string) (result bool, err error) {
	stdout, stderr, err := sys.Run(CmdService, name, "status")
	log.Print(CmdService)
	log.Print(stdout)
	log.Print(stderr)
	if err != nil {
		return
	}

	if strings.Contains(stdout[0], SERVICE_SERVICE_RUNNING) {
		result = true
	} else if strings.Contains(stdout[0], SERVICE_SERVICE_NOT_RUNNING) {
		result = false
	} else if strings.Contains(stdout[0], SERVICE_SERVICE_NOT_ENABLED) {
		err = errors.New("Service " + name + " is not enabled")
	} else {
		err = errors.New("Unknown error trying to determine service status of " + name)
	}
	return
}
開發者ID:r3boot,項目名稱:rlib,代碼行數:20,代碼來源:service.go

示例15: GetRoute

func (r RIB) GetRoute(network net.IPNet) (result Route, err error) {
	af, use_af, err := getAfDetails(network)
	if err != nil {
		return
	}

	stdout, _, err := sys.Run("/usr/bin/netstat", "-rn", "-f", use_af)
	if err != nil {
		return
	}

	for _, line := range stdout {
		if strings.HasPrefix(line, "Routing") {
			continue
		} else if line == "" {
			continue
		} else if strings.HasPrefix(line, "Internet") {
			continue
		} else if strings.HasPrefix(line, "Destination") {
			continue
		}

		route, e := parseRoutingLine(af, line)
		if e != nil {
			continue
		}

		if (network.IP.Equal(route.Destination.IP)) &&
			(network.Mask.String() == route.Destination.Mask.String()) {
			result = route
			return
		}
	}

	err = errors.New("Failed to find any routes")

	return
}
開發者ID:r3boot,項目名稱:rlib,代碼行數:38,代碼來源:rib_freebsd.go


注:本文中的github.com/r3boot/rlib/sys.Run函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。