本文整理汇总了Golang中github.com/r3boot/rlib/sys.Run函数的典型用法代码示例。如果您正苦于以下问题:Golang Run函数的具体用法?Golang Run怎么用?Golang Run使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Run函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: GetOffer
func (d Dhcpcd) GetOffer() (ip net.IP, network net.IPNet, err error) {
if err = d.RemoveLeaseFile(); err != nil {
err = errors.New("Failed to remove lease file: " + err.Error())
return
}
stdout, _, err := sys.Run(d.CmdDhcpcd, "-4T", d.Interface)
if err != nil {
return
}
var raw_ip, cidr_mask string
for _, line := range stdout {
t := strings.Split(line, "=")
if t[0] == "new_ip_address" {
raw_ip = t[1]
} else if t[0] == "new_subnet_cidr" {
cidr_mask = t[1]
}
}
if len(raw_ip) == 0 {
err = errors.New("Failed to obtain ip address")
return
} else if len(cidr_mask) == 0 {
err = errors.New("Failed to obtain cidr mask")
return
}
i, n, err := net.ParseCIDR(raw_ip + "/" + cidr_mask)
if err == nil {
ip = i
network = *n
}
return
}
开发者ID:r3boot,项目名称:rlib,代码行数:38,代码来源:dhcpcd.go
示例17: IsRunning
func (s Systemd) IsRunning(name string) (result bool, err error) {
stdout, _, err := sys.Run(CmdSystemd, "status", name)
if err != nil {
result = false
err = nil
return
}
for _, line := range stdout {
if strings.Contains(line, SYSTEMD_SERVICE_RUNNING) {
result = true
break
} else if strings.Contains(line, SYSTEMD_SERVICE_NOT_RUNNING) {
result = false
break
} else if strings.Contains(line, SYSTEMD_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,代码行数:23,代码来源:systemd.go
示例18: Start
/*
* Start dhcpcd on intf. Print an error if anything goes wrong
*/
func (d Dhcpcd) Start() (err error) {
var args []string
args = append(args, "-q")
if !d.UseResolvconf {
args = append(args, "-C")
args = append(args, "resolv.conf")
}
if !d.SetMtu {
args = append(args, "-C")
args = append(args, "mtu")
}
args = append(args, d.Interface)
_, _, err = sys.Run(d.CmdDhcpcd, args...)
if err != nil {
err = errors.New("Failed to start dhcpcd: " + err.Error())
}
return
}
开发者ID:r3boot,项目名称:rlib,代码行数:26,代码来源:dhcpcd.go
示例19: HasCarrier
func (l Link) HasCarrier() (result bool, err error) {
stdout, _, err := sys.Run(l.CmdIfconfig, l.Interface.Name)
if err != nil {
return
}
for _, line := range stdout {
if strings.Contains(line, IFCONFIG_STATUS) {
status := strings.Split(line, " ")[1]
if status == IFCONFIG_CARRIER_ACTIVE {
result = true
return
} else if status == IFCONFIG_CARRIER_ASSOCIATED {
result = true
return
}
}
}
result = false
return
}
开发者ID:r3boot,项目名称:rlib,代码行数:23,代码来源:link_freebsd.go
示例20: Arping
/*
* Send count ARP Request packet(s) to ipaddr using arping. Return true if
* the return code of arping is zero, false otherwise.
*/
func Arping(ipaddr net.IP, intf net.Interface, count int) (up bool, latency float64, err error) {
if ipaddr == nil {
return
}
arping, err := sys.BinaryPrefix("arping")
if err != nil {
return
}
stdout, _, err := sys.Run(arping, "-I", intf.Name, "-c", strconv.Itoa(count), ipaddr.String())
var tot_latency float64 = 0
if err == nil {
up = true
for _, line := range stdout {
if !strings.Contains(line, "bytes from") {
continue
}
raw_latency := strings.Fields(line)[6]
raw_latency = strings.Split(raw_latency, "=")[1]
l, err := strconv.ParseFloat(raw_latency, 64)
if err != nil {
continue
}
tot_latency += (l / 1000)
}
}
latency = (tot_latency / float64(count))
return
}
开发者ID:r3boot,项目名称:rlib,代码行数:41,代码来源:arping_freebsd.go
注:本文中的github.com/r3boot/rlib/sys.Run函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论