当前位置: 首页>>代码示例>>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;未经允许,请勿转载。