func main()

in src/go/cmd/smbwalker/main.go [382:444]


func main() {
	// setup the shared context
	ctx, cancel := context.WithCancel(context.Background())

	targetSMBPaths, walkersPerShare, fileFilter, runForever := InitializeVariables()

	for _, s := range targetSMBPaths {
		Info.Printf("SMB Path: %s", s)
	}
	Info.Printf("fileextension filter: %s", fileFilter)

	// initialize the sync wait group
	syncWaitGroup := sync.WaitGroup{}
	syncWaitGroup.Add(1)
	// start the stats collector
	statsCollector := InitializeStatsCollector()
	go statsCollector.RunStatsPrinter(ctx, &syncWaitGroup)

	walkers := make([]*Walker, 0, len(targetSMBPaths)*walkersPerShare)
	for i := 0; i < walkersPerShare; i++ {
		for _, s := range targetSMBPaths {
			walker := InitializeWalker(statsCollector, s, fileFilter)
			walkers = append(walkers, walker)
			syncWaitGroup.Add(1)
			go walker.RunWalker(ctx, &syncWaitGroup, runForever)
		}
	}

	Info.Printf("wait for finish or ctrl-c")
	// wait on ctrl-c
	sigchan := make(chan os.Signal, 10)
	// catch all signals will cause cancellation when mounted, we need to
	// filter out better
	// signal.Notify(sigchan)
	signal.Notify(sigchan, os.Interrupt)

	lastPrintTime := time.Now().Add(-timeBetweenPrints)
	ticker := time.NewTicker(tick)
	defer ticker.Stop()
	stopped := false
	for !stopped {
		select {
		case <-sigchan:
			Info.Printf("Received ctrl-c, stopping walkers...")
			stopped = true
		case <-ticker.C:
			if time.Since(lastPrintTime) > timeBetweenPrints {
				lastPrintTime = time.Now()
				if statsCollector.GetRunningThreads() == 0 {
					Info.Printf("Threads finished running, stopping...")
					stopped = true
				}
			}
		}
	}
	cancel()

	Info.Printf("Waiting for all processes to finish")
	syncWaitGroup.Wait()

	Info.Printf("complete")
	statsCollector.PrintSummary()
}