Now program must try to run as a user set in a config file.
init loggers from new config options.
This commit is contained in:
parent
96512808a8
commit
43c52dd754
@ -10,6 +10,8 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
"os/user"
|
||||||
|
"strconv"
|
||||||
"syscall"
|
"syscall"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -23,19 +25,36 @@ func main() {
|
|||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
logErr, err := logging.NewLogger(config.LogDir + "/error.log")
|
// Substitute user to the one in config
|
||||||
|
dwu, err := user.Lookup(config.User)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalln(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
dwuid, err := strconv.Atoi(dwu.Uid)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalln(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if os.Getuid() != dwuid {
|
||||||
|
if err := syscall.Setuid(dwuid); err != nil {
|
||||||
|
log.Fatalln(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
logErr, err := logging.NewLogger(config.Log.Error)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln("failed to open error logger:", err)
|
log.Fatalln("failed to open error logger:", err)
|
||||||
}
|
}
|
||||||
defer logErr.Close()
|
defer logErr.Close()
|
||||||
|
|
||||||
logUpload, err := logging.NewLogger(config.LogDir + "/upload.log")
|
logUpload, err := logging.NewLogger(config.Log.Upload)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln("failed to open upload logger:", err)
|
log.Fatalln("failed to open upload logger:", err)
|
||||||
}
|
}
|
||||||
defer logUpload.Close()
|
defer logUpload.Close()
|
||||||
|
|
||||||
logDownload, err := logging.NewLogger(config.LogDir + "/download.log")
|
logDownload, err := logging.NewLogger(config.Log.Download)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln("failed to open download logger:", err)
|
log.Fatalln("failed to open download logger:", err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user