diff --git a/cmd/dwelling-upload/main.go b/cmd/dwelling-upload/main.go index 8659d31..be19c88 100644 --- a/cmd/dwelling-upload/main.go +++ b/cmd/dwelling-upload/main.go @@ -10,6 +10,8 @@ import ( "net/http" "os" "os/signal" + "os/user" + "strconv" "syscall" ) @@ -23,19 +25,36 @@ func main() { 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 { log.Fatalln("failed to open error logger:", err) } defer logErr.Close() - logUpload, err := logging.NewLogger(config.LogDir + "/upload.log") + logUpload, err := logging.NewLogger(config.Log.Upload) if err != nil { log.Fatalln("failed to open upload logger:", err) } defer logUpload.Close() - logDownload, err := logging.NewLogger(config.LogDir + "/download.log") + logDownload, err := logging.NewLogger(config.Log.Download) if err != nil { log.Fatalln("failed to open download logger:", err) }