Commit 1e0c4ef9 authored by Patrick J Cherry's avatar Patrick J Cherry
Browse files

Merge branch 'jessie' of gitlab.bytemark.co.uk:bytemark/symbiosis into jessie

parents cdeb64a8 312826eb
......@@ -55,12 +55,19 @@ import (
//
var handles = make(map[string]*os.File)
//
// The number of files we'll keep open at any one time.
//
// This may be changed by a command-line flag.
//
var files_count = 100
//
// Are we running verbosely?
//
// This may be changed by a command-line flag.
//
var verbose = false
//
// Setup a handler for SIGHUP which will close all of our
......@@ -125,7 +132,6 @@ func close_logfiles() {
//
func safeOpen(path string) *os.File {
//
// If we have too many open files then close them all.
//
......@@ -141,7 +147,9 @@ func safeOpen(path string) *os.File {
//
handle, err := os.OpenFile(path, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644)
if err != nil {
fmt.Fprintln(os.Stderr, "Failed to open file:", path)
if verbose {
fmt.Fprintln(os.Stderr, "Failed to open file:", path)
}
return nil
}
......@@ -153,7 +161,10 @@ func safeOpen(path string) *os.File {
//
fi, serr := os.Lstat(path)
if serr != nil {
fmt.Println("Failed to stat the file", path, serr)
if verbose {
fmt.Println("Failed to stat the file", path, serr)
}
handle.Close()
return nil
}
......@@ -231,7 +242,7 @@ func main() {
// Handle the possible short/long alternatives.
//
sync_flag := *sync_long || *sync_short
verbose_flag := *verbose_long || *verbose_short
verbose = *verbose_long || *verbose_short
files_count = (*files_long + *files_short)
//
......@@ -270,9 +281,9 @@ func main() {
// If being verbose then dump state of the parsed-flags to
// the screen. Most of these are ignored ..
//
if verbose_flag {
if verbose {
fmt.Fprintln(os.Stderr, "sync:", sync_flag)
fmt.Fprintln(os.Stderr, "verbose:", verbose_flag)
fmt.Fprintln(os.Stderr, "verbose:", verbose)
fmt.Fprintln(os.Stderr, "files:", files_count)
fmt.Fprintln(os.Stderr, "uid:", *g_uid)
fmt.Fprintln(os.Stderr, "gid:", *g_gid)
......@@ -335,7 +346,7 @@ func main() {
//
if handles[default_file] != nil {
handles[default_file].WriteString(log + "\n")
}
}
//
// The line will contain the vhost-name as the initial
......@@ -348,7 +359,10 @@ func main() {
//
match := re.FindStringSubmatch(log)
if match == nil {
fmt.Fprintln(os.Stderr, "Received malformed request-line:", log)
if verbose {
fmt.Fprintln(os.Stderr, "Received malformed request-line:", log)
}
continue
}
......@@ -365,7 +379,10 @@ func main() {
//
stat, err := os.Stat(logfile)
if err != nil {
fmt.Fprintln(os.Stderr, "Received request for vhost that doesn't exist:", err)
if verbose {
fmt.Fprintln(os.Stderr, "Received request for vhost that doesn't exist:", err)
}
continue
}
sys := stat.Sys()
......@@ -415,7 +432,9 @@ func main() {
// Ensure the UID/GID of the logfile match that on the
// virtual-hosts' directory
os.Chown(logfile, int(uid), int(gid))
if h != nil {
h.Chown(int(uid), int(gid))
}
}
//
......@@ -424,19 +443,22 @@ func main() {
//
if h != nil {
h.WriteString(rest + "\n")
}
}
}
// Check for errors during `Scan`. End of file is
// expected and not reported by `Scan` as an error.
if err := scanner.Err(); err != nil {
fmt.Fprintln(os.Stderr, "error:", err)
if verbose {
fmt.Fprintln(os.Stderr, "error:", err)
}
os.Exit(1)
}
//
// Close all our open handles.
//
close_logfiles()
close_logfiles()
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