<commit_before>package main

import (
	"flag"
	"fmt"
	"log"
	"os"

	"github.com/VividCortex/godaemon"
	"github.com/gsora/tfanc/config"
	"github.com/gsora/tfanc/tpmodule"
)

// The fan controller itself
var cFan tpmodule.Fan

func main() {
	// program parameters
	benchmark := flag.Bool("benchmark", false, "run all the possible fan levels, 10 seconds at time")
	foreground := flag.Bool("foreground", false, "don't fork in background, useful for debug purposes")
	flag.Parse()

	conf := securityChecks()

	if *foreground == false && *benchmark == false {
		godaemon.MakeDaemon(&godaemon.DaemonAttr{})
	} else if *foreground == false && *benchmark == true {
		fmt.Println("Cannot fork to background while running in benchmark mode.")
	}

	// if -benchmark passed, run it
	if *benchmark == true {
		tpmodule.Benchmark(cFan)
		return
	}

	// calm down, golint.
	cFan.Update()
	fmt.Println(cFan.Status)
	fmt.Println(conf.Targets)
}

func securityChecks() config.Configuration {
	// check if user running this is root
	if os.Getuid() != 0 {
		fmt.Println("This program have to be executed with root rights.")
		os.Exit(1)
	}

	// then check if the kernel module is loaded with fan_control=1, else exit
	if err := tpmodule.IsModuleLoaded(); err != nil {
		log.Fatal(err)
	}

	conf, err := config.LoadConfig()
	if err != nil {
		log.Fatal(err)
	}

	return conf
}<commit_msg>comments!<commit_after>package main

import (
	"flag"
	"fmt"
	"log"
	"os"

	"github.com/VividCortex/godaemon"
	"github.com/gsora/tfanc/config"
	"github.com/gsora/tfanc/tpmodule"
)

// The fan controller itself
var cFan tpmodule.Fan

func main() {
	// program parameters
	benchmark := flag.Bool("benchmark", false, "run all the possible fan levels, 10 seconds at time")
	foreground := flag.Bool("foreground", false, "don't fork in background, useful for debug purposes")
	flag.Parse()

	// Make some security checks and (hopefully) return a config.Configuration
	conf := securityChecks()

	// If the user didn't want to run in benchmark mode, or in foreground mode,
	// fork into background.
	//
	// Otherwise, if he wanted to benchmark, run it.
	if *foreground == false && *benchmark == false {
		godaemon.MakeDaemon(&godaemon.DaemonAttr{})
	} else if *foreground == false && *benchmark == true {
		fmt.Println("Cannot fork to background while running in benchmark mode.")
	}

	// if -benchmark passed, run it
	if *benchmark == true {
		tpmodule.Benchmark(cFan)
		return
	}

	// calm down, golint.
	cFan.Update()
	fmt.Println(cFan.Status)
	fmt.Println(conf.Targets)
}

func securityChecks() config.Configuration {
	// check if user running this is root
	if os.Getuid() != 0 {
		fmt.Println("This program have to be executed with root rights.")
		os.Exit(1)
	}

	// then check if the kernel module is loaded with fan_control=1, else exit
	if err := tpmodule.IsModuleLoaded(); err != nil {
		log.Fatal(err)
	}

	// Load the config file
	conf, err := config.LoadConfig()
	if err != nil {
		log.Fatal(err)
	}

	return conf
}
{'fraction_non_alphanumeric': 0.13094440723375753, 'fraction_numerical': 0.003348961821835231, 'mean_word_length': 3.7563694267515926, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1123989', 'n_tokens_mistral': 1069, 'n_tokens_neox': 1008, 'n_words': 308}