Best Syzkaller code snippet using ipc.exec
proc.go
Source:proc.go
...11 "syscall"12 "time"13 "strings"14 // "bufio"15 "os/exec"16 "github.com/google/syzkaller/pkg/cover"17 "github.com/google/syzkaller/pkg/hash"18 "github.com/google/syzkaller/pkg/ipc"19 "github.com/google/syzkaller/pkg/log"20 "github.com/google/syzkaller/pkg/rpctype"21 "github.com/google/syzkaller/pkg/signal"22 "github.com/google/syzkaller/prog"23)24// Proc represents a single fuzzing process (executor).25type Proc struct {26 fuzzer *Fuzzer27 pid int28 env *ipc.Env29 rnd *rand.Rand30 execOpts *ipc.ExecOpts31 execOptsCover *ipc.ExecOpts32 execOptsComps *ipc.ExecOpts33 execOptsNoCollide *ipc.ExecOpts34}35func newProc(fuzzer *Fuzzer, pid int) (*Proc, error) {36 env, err := ipc.MakeEnv(fuzzer.config, pid)37 if err != nil {38 return nil, err39 }40 rnd := rand.New(rand.NewSource(time.Now().UnixNano() + int64(pid)*1e12))41 execOptsNoCollide := *fuzzer.execOpts42 execOptsNoCollide.Flags &= ^ipc.FlagCollide43 execOptsCover := execOptsNoCollide44 execOptsCover.Flags |= ipc.FlagCollectCover45 execOptsComps := execOptsNoCollide46 execOptsComps.Flags |= ipc.FlagCollectComps47 proc := &Proc{48 fuzzer: fuzzer,49 pid: pid,50 env: env,51 rnd: rnd,52 execOpts: fuzzer.execOpts,53 execOptsCover: &execOptsCover,54 execOptsComps: &execOptsComps,55 execOptsNoCollide: &execOptsNoCollide,56 }57 return proc, nil58}59func (proc *Proc) loop() {60 generatePeriod := 10061 if proc.fuzzer.config.Flags&ipc.FlagSignal == 0 {62 // If we don't have real coverage signal, generate programs more frequently63 // because fallback signal is weak.64 generatePeriod = 265 }66 for i := 0; ; i++ {67 item := proc.fuzzer.workQueue.dequeue()68 if item != nil {69 switch item := item.(type) {70 case *WorkTriage:71 proc.triageInput(item)72 case *WorkCandidate:73 proc.execute(proc.execOpts, item.p, item.flags, StatCandidate)74 case *WorkSmash:75 proc.smashInput(item)76 default:77 log.Fatalf("unknown work type: %#v", item)78 }79 continue80 }81 ct := proc.fuzzer.choiceTable82 fuzzerSnapshot := proc.fuzzer.snapshot()83 if len(fuzzerSnapshot.corpus) == 0 || i%generatePeriod == 0 {84 // Generate a new prog.85 p := proc.fuzzer.target.Generate(proc.rnd, prog.RecommendedCalls, ct)86 log.Logf(1, "#%v: generated", proc.pid)87 proc.execute(proc.execOpts, p, ProgNormal, StatGenerate)88 } else {89 // Mutate an existing prog.90 p := fuzzerSnapshot.chooseProgram(proc.rnd).Clone()91 p.Mutate(proc.rnd, prog.RecommendedCalls, ct, fuzzerSnapshot.corpus)92 log.Logf(1, "#%v: mutated", proc.pid)93 proc.execute(proc.execOpts, p, ProgNormal, StatFuzz)94 }95 }96}97func (proc *Proc) triageInput(item *WorkTriage) {98 log.Logf(1, "#%v: triaging type=%x", proc.pid, item.flags)99 prio := signalPrio(item.p, &item.info, item.call)100 inputSignal := signal.FromRaw(item.info.Signal, prio)101 newSignal := proc.fuzzer.corpusSignalDiff(inputSignal)102 if newSignal.Empty() {103 return104 }105 callName := ".extra"106 logCallName := "extra"107 if item.call != -1 {108 callName = item.p.Calls[item.call].Meta.Name109 logCallName = fmt.Sprintf("call #%v %v", item.call, callName)110 }111 log.Logf(3, "triaging input for %v (new signal=%v)", logCallName, newSignal.Len())112 var inputCover cover.Cover113 const (114 signalRuns = 3115 minimizeAttempts = 3116 )117 // Compute input coverage and non-flaky signal for minimization.118 notexecuted := 0119 for i := 0; i < signalRuns; i++ {120 info := proc.executeRaw(proc.execOptsCover, item.p, StatTriage)121 if !reexecutionSuccess(info, &item.info, item.call) {122 // The call was not executed or failed.123 notexecuted++124 if notexecuted > signalRuns/2+1 {125 return // if happens too often, give up126 }127 continue128 }129 thisSignal, thisCover := getSignalAndCover(item.p, info, item.call)130 newSignal = newSignal.Intersection(thisSignal)131 // Without !minimized check manager starts losing some considerable amount132 // of coverage after each restart. Mechanics of this are not completely clear.133 if newSignal.Empty() && item.flags&ProgMinimized == 0 {134 return135 }136 inputCover.Merge(thisCover)137 }138 if item.flags&ProgMinimized == 0 {139 item.p, item.call = prog.Minimize(item.p, item.call, false,140 func(p1 *prog.Prog, call1 int) bool {141 for i := 0; i < minimizeAttempts; i++ {142 info := proc.execute(proc.execOptsNoCollide, p1, ProgNormal, StatMinimize)143 if !reexecutionSuccess(info, &item.info, call1) {144 // The call was not executed or failed.145 continue146 }147 thisSignal, _ := getSignalAndCover(p1, info, call1)148 if newSignal.Intersection(thisSignal).Len() == newSignal.Len() {149 return true150 }151 }152 return false153 })154 }155 data := item.p.Serialize()156 sig := hash.Hash(data)157 log.Logf(2, "added new input for %v to corpus:\n%s", logCallName, data)158 proc.fuzzer.sendInputToManager(rpctype.RPCInput{159 Call: callName,160 Prog: data,161 Signal: inputSignal.Serialize(),162 Cover: inputCover.Serialize(),163 })164 proc.fuzzer.addInputToCorpus(item.p, inputSignal, sig)165 if item.flags&ProgSmashed == 0 {166 proc.fuzzer.workQueue.enqueue(&WorkSmash{item.p, item.call})167 }168}169func reexecutionSuccess(info *ipc.ProgInfo, oldInfo *ipc.CallInfo, call int) bool {170 if info == nil || len(info.Calls) == 0 {171 return false172 }173 if call != -1 {174 // Don't minimize calls from successful to unsuccessful.175 // Successful calls are much more valuable.176 if oldInfo.Errno == 0 && info.Calls[call].Errno != 0 {177 return false178 }179 return len(info.Calls[call].Signal) != 0180 }181 return len(info.Extra.Signal) != 0182}183func getSignalAndCover(p *prog.Prog, info *ipc.ProgInfo, call int) (signal.Signal, []uint32) {184 inf := &info.Extra185 if call != -1 {186 inf = &info.Calls[call]187 }188 return signal.FromRaw(inf.Signal, signalPrio(p, inf, call)), inf.Cover189}190func (proc *Proc) smashInput(item *WorkSmash) {191 if proc.fuzzer.faultInjectionEnabled && item.call != -1 {192 proc.failCall(item.p, item.call)193 }194 if proc.fuzzer.comparisonTracingEnabled && item.call != -1 {195 proc.executeHintSeed(item.p, item.call)196 }197 fuzzerSnapshot := proc.fuzzer.snapshot()198 for i := 0; i < 100; i++ {199 p := item.p.Clone()200 p.Mutate(proc.rnd, prog.RecommendedCalls, proc.fuzzer.choiceTable, fuzzerSnapshot.corpus)201 log.Logf(1, "#%v: smash mutated", proc.pid)202 proc.execute(proc.execOpts, p, ProgNormal, StatSmash)203 }204}205func (proc *Proc) failCall(p *prog.Prog, call int) {206 for nth := 0; nth < 100; nth++ {207 log.Logf(1, "#%v: injecting fault into call %v/%v", proc.pid, call, nth)208 opts := *proc.execOpts209 opts.Flags |= ipc.FlagInjectFault210 opts.FaultCall = call211 opts.FaultNth = nth212 info := proc.executeRaw(&opts, p, StatSmash)213 if info != nil && len(info.Calls) > call && info.Calls[call].Flags&ipc.CallFaultInjected == 0 {214 break215 }216 }217}218func (proc *Proc) executeHintSeed(p *prog.Prog, call int) {219 log.Logf(1, "#%v: collecting comparisons", proc.pid)220 // First execute the original program to dump comparisons from KCOV.221 info := proc.execute(proc.execOptsComps, p, ProgNormal, StatSeed)222 if info == nil {223 return224 }225 // Then mutate the initial program for every match between226 // a syscall argument and a comparison operand.227 // Execute each of such mutants to check if it gives new coverage.228 p.MutateWithHints(call, info.Calls[call].Comps, func(p *prog.Prog) {229 log.Logf(1, "#%v: executing comparison hint", proc.pid)230 proc.execute(proc.execOpts, p, ProgNormal, StatHint)231 })232}233func (proc *Proc) execute(execOpts *ipc.ExecOpts, p *prog.Prog, flags ProgTypes, stat Stat) *ipc.ProgInfo {234 info := proc.executeRaw(execOpts, p, stat)235 calls, extra := proc.fuzzer.checkNewSignal(p, info)236 for _, callIndex := range calls {237 proc.enqueueCallTriage(p, flags, callIndex, info.Calls[callIndex])238 }239 if extra {240 proc.enqueueCallTriage(p, flags, -1, info.Extra)241 }242 return info243}244func (proc *Proc) enqueueCallTriage(p *prog.Prog, flags ProgTypes, callIndex int, info ipc.CallInfo) {245 // info.Signal points to the output shmem region, detach it before queueing.246 info.Signal = append([]uint32{}, info.Signal...)247 // None of the caller use Cover, so just nil it instead of detaching.248 // Note: triage input uses executeRaw to get coverage.249 info.Cover = nil250 proc.fuzzer.workQueue.enqueue(&WorkTriage{251 p: p.Clone(),252 call: callIndex,253 info: info,254 flags: flags,255 })256}257func (proc *Proc) executeRaw(opts *ipc.ExecOpts, p *prog.Prog, stat Stat) *ipc.ProgInfo {258 if opts.Flags&ipc.FlagDedupCover == 0 {259 log.Fatalf("dedup cover is not enabled")260 }261 for _, call := range p.Calls {262 if !proc.fuzzer.choiceTable.Enabled(call.Meta.ID) {263 fmt.Printf("executing disabled syscall %v", call.Meta.Name)264 panic("disabled syscall")265 }266 }267 // Limit concurrency window and do leak checking once in a while.268 ticket := proc.fuzzer.gate.Enter()269 defer proc.fuzzer.gate.Leave(ticket)270 proc.logProgram(opts, p)271 for try := 0; ; try++ {272 atomic.AddUint64(&proc.fuzzer.stats[stat], 1)273 output, info, hanged, err := proc.env.Exec(opts, p)274 // ACHYB275 cmd := exec.Command("dmesg", "-c")276 output, err1 := cmd.Output()277 if err1 != nil {278 log.Logf(0, "%v", err1.Error())279 }280 281 ls := strings.Split(string(output), "\n")282 for _, l := range ls {283 if strings.Contains(l, "BUG: achyb") {284 s := strings.Index(l, "BUG: achyb")285 l = l[s:]286 a := &rpctype.TriggerArgs{287 KACV: l,288 }289 r := &rpctype.TriggerRes{}290 // r.Has = true291 if err3 := proc.fuzzer.manager.Call("Manager.Trigger", a, r); err3 != nil {292 log.Fatalf("Manager.Trigger call failed: %v", err3)293 }294 if !r.Has {295 log.Logf(0, "%s", l)296 } 297 }298 }299 if err != nil {300 if try > 10 {301 log.Fatalf("executor %v failed %v times:\n%v", proc.pid, try, err)302 }303 log.Logf(4, "fuzzer detected executor failure='%v', retrying #%d", err, try+1)304 debug.FreeOSMemory()305 time.Sleep(time.Second)306 continue307 }308 log.Logf(2, "result hanged=%v: %s", hanged, output)309 return info310 }311}312func (proc *Proc) logProgram(opts *ipc.ExecOpts, p *prog.Prog) {313 if proc.fuzzer.outputType == OutputNone {314 return315 }316 data := p.Serialize()317 strOpts := ""318 if opts.Flags&ipc.FlagInjectFault != 0 {319 strOpts = fmt.Sprintf(" (fault-call:%v fault-nth:%v)", opts.FaultCall, opts.FaultNth)320 }321 // The following output helps to understand what program crashed kernel.322 // It must not be intermixed.323 switch proc.fuzzer.outputType {324 case OutputStdout:325 now := time.Now()326 proc.fuzzer.logMu.Lock()327 fmt.Printf("%02v:%02v:%02v executing program %v%v:\n%s\n",328 now.Hour(), now.Minute(), now.Second(),329 proc.pid, strOpts, data)330 proc.fuzzer.logMu.Unlock()331 case OutputDmesg:332 fd, err := syscall.Open("/dev/kmsg", syscall.O_WRONLY, 0)333 if err == nil {334 buf := new(bytes.Buffer)335 fmt.Fprintf(buf, "syzkaller: executing program %v%v:\n%s\n",336 proc.pid, strOpts, data)337 syscall.Write(fd, buf.Bytes())338 syscall.Close(fd)339 }340 case OutputFile:341 f, err := os.Create(fmt.Sprintf("%v-%v.prog", proc.fuzzer.name, proc.pid))342 if err == nil {343 if strOpts != "" {344 fmt.Fprintf(f, "#%v\n", strOpts)345 }346 f.Write(data)347 f.Close()348 }349 default:...
execprog.go
Source:execprog.go
1// Copyright 2015 syzkaller project authors. All rights reserved.2// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.3// execprog executes a single program or a set of programs4// and optionally prints information about execution.5package main6import (7 "bytes"8 "flag"9 "fmt"10 "io/ioutil"11 "os"12 "runtime"13 "sync"14 "time"15 "github.com/google/syzkaller/pkg/cover"16 "github.com/google/syzkaller/pkg/csource"17 "github.com/google/syzkaller/pkg/host"18 "github.com/google/syzkaller/pkg/ipc"19 "github.com/google/syzkaller/pkg/ipc/ipcconfig"20 "github.com/google/syzkaller/pkg/log"21 "github.com/google/syzkaller/pkg/osutil"22 "github.com/google/syzkaller/prog"23 _ "github.com/google/syzkaller/sys"24)25var (26 flagOS = flag.String("os", runtime.GOOS, "target os")27 flagArch = flag.String("arch", runtime.GOARCH, "target arch")28 flagCoverFile = flag.String("coverfile", "", "write coverage to the file")29 flagRepeat = flag.Int("repeat", 1, "repeat execution that many times (0 for infinite loop)")30 flagProcs = flag.Int("procs", 1, "number of parallel processes to execute programs")31 flagOutput = flag.Bool("output", false, "write programs and results to stdout")32 flagHints = flag.Bool("hints", false, "do a hints-generation run")33 flagFaultCall = flag.Int("fault_call", -1, "inject fault into this call (0-based)")34 flagFaultNth = flag.Int("fault_nth", 0, "inject fault on n-th operation (0-based)")35 flagEnable = flag.String("enable", "none", "enable only listed additional features")36 flagDisable = flag.String("disable", "none", "enable all additional features except listed")37)38func main() {39 flag.Usage = func() {40 fmt.Fprintf(os.Stderr, "usage: execprog [flags] file-with-programs+\n")41 flag.PrintDefaults()42 csource.PrintAvailableFeaturesFlags()43 }44 flag.Parse()45 if len(flag.Args()) == 0 {46 flag.Usage()47 os.Exit(1)48 }49 featuresFlags, err := csource.ParseFeaturesFlags(*flagEnable, *flagDisable, true)50 if err != nil {51 log.Fatalf("%v", err)52 }53 target, err := prog.GetTarget(*flagOS, *flagArch)54 if err != nil {55 log.Fatalf("%v", err)56 }57 entries := loadPrograms(target, flag.Args())58 if len(entries) == 0 {59 return60 }61 features, err := host.Check(target)62 if err != nil {63 log.Fatalf("%v", err)64 }65 if *flagOutput {66 for _, feat := range features.Supported() {67 log.Logf(0, "%-24v: %v", feat.Name, feat.Reason)68 }69 }70 config, execOpts := createConfig(target, features, featuresFlags)71 if err = host.Setup(target, features, featuresFlags, config.Executor); err != nil {72 log.Fatal(err)73 }74 var gateCallback func()75 if features[host.FeatureLeak].Enabled {76 gateCallback = func() {77 output, err := osutil.RunCmd(10*time.Minute, "", config.Executor, "leak")78 if err != nil {79 os.Stdout.Write(output)80 os.Exit(1)81 }82 }83 }84 ctx := &Context{85 entries: entries,86 config: config,87 execOpts: execOpts,88 gate: ipc.NewGate(2**flagProcs, gateCallback),89 shutdown: make(chan struct{}),90 repeat: *flagRepeat,91 }92 var wg sync.WaitGroup93 wg.Add(*flagProcs)94 for p := 0; p < *flagProcs; p++ {95 pid := p96 go func() {97 defer wg.Done()98 ctx.run(pid)99 }()100 }101 osutil.HandleInterrupts(ctx.shutdown)102 wg.Wait()103}104type Context struct {105 entries []*prog.LogEntry106 config *ipc.Config107 execOpts *ipc.ExecOpts108 gate *ipc.Gate109 shutdown chan struct{}110 logMu sync.Mutex111 posMu sync.Mutex112 repeat int113 pos int114 lastPrint time.Time115}116func (ctx *Context) run(pid int) {117 env, err := ipc.MakeEnv(ctx.config, pid)118 if err != nil {119 log.Fatalf("failed to create ipc env: %v", err)120 }121 defer env.Close()122 for {123 select {124 case <-ctx.shutdown:125 return126 default:127 }128 idx := ctx.getProgramIndex()129 if ctx.repeat > 0 && idx >= len(ctx.entries)*ctx.repeat {130 return131 }132 entry := ctx.entries[idx%len(ctx.entries)]133 ctx.execute(pid, env, entry)134 }135}136func (ctx *Context) execute(pid int, env *ipc.Env, entry *prog.LogEntry) {137 // Limit concurrency window.138 ticket := ctx.gate.Enter()139 defer ctx.gate.Leave(ticket)140 callOpts := ctx.execOpts141 if *flagFaultCall == -1 && entry.Fault {142 newOpts := *ctx.execOpts143 newOpts.Flags |= ipc.FlagInjectFault144 newOpts.FaultCall = entry.FaultCall145 newOpts.FaultNth = entry.FaultNth146 callOpts = &newOpts147 }148 if *flagOutput {149 ctx.logProgram(pid, entry.P, callOpts)150 }151 output, info, hanged, err := env.Exec(callOpts, entry.P)152 if ctx.config.Flags&ipc.FlagDebug != 0 || err != nil {153 log.Logf(0, "result: hanged=%v err=%v\n\n%s", hanged, err, output)154 }155 if info != nil {156 ctx.printCallResults(info)157 if *flagHints {158 ctx.printHints(entry.P, info)159 }160 if *flagCoverFile != "" {161 ctx.dumpCoverage(*flagCoverFile, info)162 }163 } else {164 log.Logf(1, "RESULT: no calls executed")165 }166}167func (ctx *Context) logProgram(pid int, p *prog.Prog, callOpts *ipc.ExecOpts) {168 strOpts := ""169 if callOpts.Flags&ipc.FlagInjectFault != 0 {170 strOpts = fmt.Sprintf(" (fault-call:%v fault-nth:%v)",171 callOpts.FaultCall, callOpts.FaultNth)172 }173 data := p.Serialize()174 ctx.logMu.Lock()175 log.Logf(0, "executing program %v%v:\n%s", pid, strOpts, data)176 ctx.logMu.Unlock()177}178func (ctx *Context) printCallResults(info *ipc.ProgInfo) {179 for i, inf := range info.Calls {180 if inf.Flags&ipc.CallExecuted == 0 {181 continue182 }183 flags := ""184 if inf.Flags&ipc.CallFinished == 0 {185 flags += " unfinished"186 }187 if inf.Flags&ipc.CallBlocked != 0 {188 flags += " blocked"189 }190 if inf.Flags&ipc.CallFaultInjected != 0 {191 flags += " faulted"192 }193 log.Logf(1, "CALL %v: signal %v, coverage %v errno %v%v",194 i, len(inf.Signal), len(inf.Cover), inf.Errno, flags)195 }196}197func (ctx *Context) printHints(p *prog.Prog, info *ipc.ProgInfo) {198 ncomps, ncandidates := 0, 0199 for i := range p.Calls {200 if *flagOutput {201 fmt.Printf("call %v:\n", i)202 }203 comps := info.Calls[i].Comps204 for v, args := range comps {205 ncomps += len(args)206 if *flagOutput {207 fmt.Printf("comp 0x%x:", v)208 for arg := range args {209 fmt.Printf(" 0x%x", arg)210 }211 fmt.Printf("\n")212 }213 }214 p.MutateWithHints(i, comps, func(p *prog.Prog) {215 ncandidates++216 if *flagOutput {217 log.Logf(1, "PROGRAM:\n%s", p.Serialize())218 }219 })220 }221 log.Logf(0, "ncomps=%v ncandidates=%v", ncomps, ncandidates)222}223func (ctx *Context) dumpCallCoverage(coverFile string, info *ipc.CallInfo) {224 if len(info.Cover) == 0 {225 return226 }227 buf := new(bytes.Buffer)228 for _, pc := range info.Cover {229 fmt.Fprintf(buf, "0x%x\n", cover.RestorePC(pc, 0xffffffff))230 }231 err := osutil.WriteFile(coverFile, buf.Bytes())232 if err != nil {233 log.Fatalf("failed to write coverage file: %v", err)234 }235}236func (ctx *Context) dumpCoverage(coverFile string, info *ipc.ProgInfo) {237 for i, inf := range info.Calls {238 log.Logf(0, "call #%v: signal %v, coverage %v", i, len(inf.Signal), len(inf.Cover))239 ctx.dumpCallCoverage(fmt.Sprintf("%v.%v", coverFile, i), &inf)240 }241 log.Logf(0, "extra: signal %v, coverage %v", len(info.Extra.Signal), len(info.Extra.Cover))242 ctx.dumpCallCoverage(fmt.Sprintf("%v.extra", coverFile), &info.Extra)243}244func (ctx *Context) getProgramIndex() int {245 ctx.posMu.Lock()246 idx := ctx.pos247 ctx.pos++248 if idx%len(ctx.entries) == 0 && time.Since(ctx.lastPrint) > 5*time.Second {249 log.Logf(0, "executed programs: %v", idx)250 ctx.lastPrint = time.Now()251 }252 ctx.posMu.Unlock()253 return idx254}255func loadPrograms(target *prog.Target, files []string) []*prog.LogEntry {256 var entries []*prog.LogEntry257 for _, fn := range files {258 data, err := ioutil.ReadFile(fn)259 if err != nil {260 log.Fatalf("failed to read log file: %v", err)261 }262 entries = append(entries, target.ParseLog(data)...)263 }264 log.Logf(0, "parsed %v programs", len(entries))265 return entries266}267func createConfig(target *prog.Target,268 features *host.Features, featuresFlags csource.Features) (269 *ipc.Config, *ipc.ExecOpts) {270 config, execOpts, err := ipcconfig.Default(target)271 if err != nil {272 log.Fatalf("%v", err)273 }274 if config.Flags&ipc.FlagSignal != 0 {275 execOpts.Flags |= ipc.FlagCollectCover276 }277 if *flagCoverFile != "" {278 config.Flags |= ipc.FlagSignal279 execOpts.Flags |= ipc.FlagCollectCover280 execOpts.Flags &^= ipc.FlagDedupCover281 }282 if *flagHints {283 if execOpts.Flags&ipc.FlagCollectCover != 0 {284 execOpts.Flags ^= ipc.FlagCollectCover285 }286 execOpts.Flags |= ipc.FlagCollectComps287 }288 if features[host.FeatureExtraCoverage].Enabled {289 config.Flags |= ipc.FlagExtraCover290 }291 if *flagFaultCall >= 0 {292 execOpts.Flags |= ipc.FlagInjectFault293 execOpts.FaultCall = *flagFaultCall294 execOpts.FaultNth = *flagFaultNth295 }296 if featuresFlags["tun"].Enabled && features[host.FeatureNetInjection].Enabled {297 config.Flags |= ipc.FlagEnableTun298 }299 if featuresFlags["net_dev"].Enabled && features[host.FeatureNetDevices].Enabled {300 config.Flags |= ipc.FlagEnableNetDev301 }302 if featuresFlags["net_reset"].Enabled {303 config.Flags |= ipc.FlagEnableNetReset304 }305 if featuresFlags["cgroups"].Enabled {306 config.Flags |= ipc.FlagEnableCgroups307 }308 if featuresFlags["close_fds"].Enabled {309 config.Flags |= ipc.FlagEnableCloseFds310 }311 if featuresFlags["devlink_pci"].Enabled && features[host.FeatureDevlinkPCI].Enabled {312 config.Flags |= ipc.FlagEnableDevlinkPCI313 }314 return config, execOpts315}...
exec
Using AI Code Generation
1import (2func main() {3 cmd := exec.Command("ls", "-l")4 stdout, err := cmd.Output()5 if err != nil {6 fmt.Println(err.Error())7 }8 fmt.Println(string(stdout))9}
exec
Using AI Code Generation
1import (2func main() {3 fmt.Println("start")4 cmd := exec.Command("ls", "-l")5 stdout, err := cmd.StdoutPipe()6 if err != nil {7 log.Fatal(err)8 }9 if err := cmd.Start(); err != nil {10 log.Fatal(err)11 }12", scanner.Text())13 fmt.Println("end")14}15import (16func main() {17 cmd := exec.Command("ls", "-l")18 stdout, err := cmd.StdoutPipe()19 if err != nil {20 log.Fatal(err)21 }22 if err := cmd.Start(); err != nil {23 log.Fatal(err)24 }25 if scanner.Scan() {26 fmt.Printf("%s27", scanner.Text())28 }29}30import (31func main() {32 cmd := exec.Command("ls", "-l")33 stdout, err := cmd.StdoutPipe()34 if err != nil {35 log.Fatal(err)36 }37 if err := cmd.Start(); err != nil {38 log.Fatal(err)39 }40 if scanner.Scan() {41 fmt.Printf("%s42", scanner.Text())43 }44}
exec
Using AI Code Generation
1import "fmt"2import "os/exec"3import "log"4import "time"5func main() {6 fmt.Println("Go IPC using exec")7 out, err := cmd.Output()8 if err != nil {9 log.Fatal(err)10 }11 time.Sleep(5 * time.Second)12}13import "fmt"14import "os/exec"15import "log"16import "time"17func main() {18 fmt.Println("Go IPC using exec")19 stdin, err := cmd.StdinPipe()20 if err != nil {21 log.Fatal(err)22 }23 go func() {24 defer stdin.Close()25 fmt.Fprintln(stdin, "hello")26 fmt.Fprintln(stdin, "world")27 }()28 out, err := cmd.Output()29 if err != nil {30 log.Fatal(err)31 }32 time.Sleep(5 * time.Second)33}
exec
Using AI Code Generation
1import (2func main() {3 out, err := exec.Command("1.exe", "1", "2").Output()4 if err != nil {5 fmt.Println(err)6 }7 fmt.Println(string(out))8}
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!