Commit 7741f22c authored by Steve Kemp's avatar Steve Kemp
Browse files

Change the UID/GID of a logfile via filehandle.

This is better than using a path.
parent fca3639e
...@@ -55,13 +55,11 @@ import ( ...@@ -55,13 +55,11 @@ import (
// //
var handles = make(map[string]*os.File) var handles = make(map[string]*os.File)
// //
// The number of files we'll keep open at any one time. // The number of files we'll keep open at any one time.
// //
var files_count = 100 var files_count = 100
// //
// Setup a handler for SIGHUP which will close all of our // Setup a handler for SIGHUP which will close all of our
// open files. // open files.
...@@ -125,7 +123,6 @@ func close_logfiles() { ...@@ -125,7 +123,6 @@ func close_logfiles() {
// //
func safeOpen(path string) *os.File { func safeOpen(path string) *os.File {
// //
// If we have too many open files then close them all. // If we have too many open files then close them all.
// //
...@@ -335,7 +332,7 @@ func main() { ...@@ -335,7 +332,7 @@ func main() {
// //
if handles[default_file] != nil { if handles[default_file] != nil {
handles[default_file].WriteString(log + "\n") handles[default_file].WriteString(log + "\n")
} }
// //
// The line will contain the vhost-name as the initial // The line will contain the vhost-name as the initial
...@@ -415,7 +412,9 @@ func main() { ...@@ -415,7 +412,9 @@ func main() {
// Ensure the UID/GID of the logfile match that on the // Ensure the UID/GID of the logfile match that on the
// virtual-hosts' directory // virtual-hosts' directory
os.Chown(logfile, int(uid), int(gid)) if h != nil {
h.Chown(int(uid), int(gid))
}
} }
// //
...@@ -424,7 +423,7 @@ func main() { ...@@ -424,7 +423,7 @@ func main() {
// //
if h != nil { if h != nil {
h.WriteString(rest + "\n") h.WriteString(rest + "\n")
} }
} }
// Check for errors during `Scan`. End of file is // Check for errors during `Scan`. End of file is
...@@ -437,6 +436,6 @@ func main() { ...@@ -437,6 +436,6 @@ func main() {
// //
// Close all our open handles. // Close all our open handles.
// //
close_logfiles() close_logfiles()
os.Exit(0) os.Exit(0)
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment