Another golint satisfyer

This commit is contained in:
Marcel Otte 2022-01-07 11:23:51 +01:00
parent d9405890d5
commit e6133848d5
2 changed files with 17 additions and 17 deletions

View File

@ -34,12 +34,12 @@ func defaultCallback(envMap map[string]string) {
if action, ok := envMap["ACTION"]; ok && action == "add" { if action, ok := envMap["ACTION"]; ok && action == "add" {
var dev *backive.Device var dev *backive.Device
var uuid string var uuid string
if fs_uuid, ok := envMap["ID_FS_UUID"]; !ok { fsUUID, ok := envMap["ID_FS_UUID"]
if !ok {
log.Println("ID_FS_UUID not available ?!") log.Println("ID_FS_UUID not available ?!")
return return
} else {
uuid = fs_uuid
} }
uuid = fsUUID
log.Println("Device connected.") log.Println("Device connected.")
var uuidFound bool var uuidFound bool
// Check the devices if the UUID is in the config // Check the devices if the UUID is in the config
@ -88,39 +88,39 @@ func defaultCallback(envMap map[string]string) {
func main() { func main() {
setupLogging() setupLogging()
signal_chan := make(chan os.Signal, 1) signalChan := make(chan os.Signal, 1)
signal.Notify(signal_chan, signal.Notify(signalChan,
syscall.SIGHUP, syscall.SIGHUP,
syscall.SIGINT, syscall.SIGINT,
syscall.SIGTERM, syscall.SIGTERM,
syscall.SIGQUIT, syscall.SIGQUIT,
) )
exit_chan := make(chan int) exitChan := make(chan int)
go func() { go func() {
for { for {
s := <-signal_chan s := <-signalChan
switch s { switch s {
case syscall.SIGHUP: case syscall.SIGHUP:
log.Println("hungup") log.Println("hungup")
case syscall.SIGINT: case syscall.SIGINT:
log.Println("Ctrl+C, quitting.") log.Println("Ctrl+C, quitting.")
exit_chan <- 0 exitChan <- 0
case syscall.SIGTERM: case syscall.SIGTERM:
log.Println("Terminating.") log.Println("Terminating.")
exit_chan <- 0 exitChan <- 0
case syscall.SIGQUIT: case syscall.SIGQUIT:
log.Println("Quitting") log.Println("Quitting")
exit_chan <- 0 exitChan <- 0
default: default:
log.Println("Unknown signal.") log.Println("Unknown signal.")
exit_chan <- 1 exitChan <- 1
} }
} }
}() }()
go func() { go func() {
// exit function only does something when the exit_chan has an item // exit function only does something when the exit_chan has an item
// cleaning up stuff // cleaning up stuff
code := <-exit_chan code := <-exitChan
database.Save() database.Save()
log.Printf("Received exit code (%d), shutting down.", code) log.Printf("Received exit code (%d), shutting down.", code)
os.Exit(code) os.Exit(code)

View File

@ -11,14 +11,14 @@ import (
// main Simple main function for the udev callback executable, registered with the udev service. // main Simple main function for the udev callback executable, registered with the udev service.
func main() { func main() {
udev_logdir := "/var/log/backive" udevLogdir := "/var/log/backive"
udev_logname := "/var/log/backive/udev.log" udevLogname := "/var/log/backive/udev.log"
if _, err := os.Stat(udev_logdir); err == nil { if _, err := os.Stat(udevLogdir); err == nil {
//ignore //ignore
} else if os.IsNotExist(err) { } else if os.IsNotExist(err) {
os.MkdirAll(udev_logdir, 0755) os.MkdirAll(udevLogdir, 0755)
} }
f, err := os.OpenFile(udev_logname, os.O_APPEND|os.O_CREATE|os.O_RDWR, 0666) f, err := os.OpenFile(udevLogname, os.O_APPEND|os.O_CREATE|os.O_RDWR, 0666)
if err != nil { if err != nil {
fmt.Println("Error creating logfile!") fmt.Println("Error creating logfile!")
panic("no logfile no info") panic("no logfile no info")