1
0

[main.go] listWatchedProcesses -> print... . Moving it and version to bottom.

Use os.Exit(0) instead of just return from main.
StoreConfiguration moved out Add/RemoveProcess methods.
This commit is contained in:
Alexander Andreev 2022-01-06 03:24:57 +04:00
parent 316c932ac2
commit 7c72851554
Signed by: Arav
GPG Key ID: 1327FE8A374CC86F

52
main.go
View File

@ -9,22 +9,6 @@ import (
"syscall" "syscall"
) )
// listWatchedProcesses prints a list of processes being watched.
func listWatchedProcesses(processes *[]string) {
for _, v := range *processes {
fmt.Printf("%s, ", v)
}
fmt.Println()
}
// version prints information about program.
func version() {
fmt.Println("httpprocwatchd ver. 1.3.2")
fmt.Println("Copyright (c) 2021,2022 Alexander \"Arav\" Andreev <me@arav.top>")
fmt.Println("This program is licensed under terms of MIT+NIGGER license a copy")
fmt.Println("of wich is located in /usr/share/licenses/httpprocwatchd/LICENSE.")
}
func main() { func main() {
var oConfigPath string var oConfigPath string
var oShowVersion bool var oShowVersion bool
@ -54,7 +38,7 @@ func main() {
if oShowVersion { if oShowVersion {
version() version()
return os.Exit(0)
} }
conf, err := LoadConfiguration(oConfigPath) conf, err := LoadConfiguration(oConfigPath)
@ -63,27 +47,32 @@ func main() {
} }
if oListProcesses { if oListProcesses {
listWatchedProcesses(&conf.Processes) printWatchedProcesses(&conf.Processes)
return os.Exit(0)
} }
if oAddProcess != "" { if oAddProcess != "" {
err := conf.AddProcessToList(oAddProcess, oConfigPath) err := conf.AddProcess(oAddProcess, oConfigPath)
if err != nil { if err != nil {
log.Fatalf("Cannot add process: %s\n", err) log.Fatalf("Cannot add process: %s\n", err)
} }
} }
if oRemoveProcess != "" { if oRemoveProcess != "" {
err := conf.RemoveProcessFromList(oRemoveProcess, oConfigPath) err := conf.RemoveProcess(oRemoveProcess, oConfigPath)
if err != nil { if err != nil {
log.Fatalf("Cannot remove process: %s\n", err) log.Fatalf("Cannot remove process: %s\n", err)
} }
} }
// If we modified a list then let's look for a running program and // If we modified a list then let's look for a running program and
// send SIGHUP for it to reload a list. // send SIGHUP to it to reload a list. Here we assume that there
// is only one process running, so we just filter our PID.
if oAddProcess != "" || oRemoveProcess != "" { if oAddProcess != "" || oRemoveProcess != "" {
if err := conf.StoreConfiguration(oConfigPath); err != nil {
log.Fatalf("Cannot write configuration. Error: %s\n", err)
}
pids, _ := GetProcessPIDs("httpprocwatchd") pids, _ := GetProcessPIDs("httpprocwatchd")
if pids != nil && len(pids) > 1 { if pids != nil && len(pids) > 1 {
var trgt_pid int var trgt_pid int
@ -97,7 +86,8 @@ func main() {
proc.Signal(syscall.SIGHUP) proc.Signal(syscall.SIGHUP)
} }
} }
return
os.Exit(0)
} }
srv := CreateAndStartHTTPServer(conf) srv := CreateAndStartHTTPServer(conf)
@ -126,3 +116,19 @@ func main() {
} }
} }
} }
// printWatchedProcesses prints a list of processes being watched.
func printWatchedProcesses(processes *[]string) {
for _, v := range *processes {
fmt.Printf("%s, ", v)
}
fmt.Println()
}
// version prints information about program.
func version() {
fmt.Println("httpprocwatchd ver. 1.3.2")
fmt.Println("Copyright (c) 2021,2022 Alexander \"Arav\" Andreev <me@arav.top>")
fmt.Println("This program is licensed under terms of MIT+NIGGER license a copy")
fmt.Println("of wich is located in /usr/share/licenses/httpprocwatchd/LICENSE.")
}