* Properly expand the tilde in paths, as well as other shell variables.
authorRobert Sesek <rsesek@bluestatic.org>
Sun, 14 Nov 2010 18:41:30 +0000 (13:41 -0500)
committerRobert Sesek <rsesek@bluestatic.org>
Sun, 14 Nov 2010 18:41:30 +0000 (13:41 -0500)
* Do not start the server on an invalid port.

src/main.go

index 2671e1310f929cee6b051ef4873e239148cafa89..2a90f12e9f489dda47268e8bd49ea5e39d692f38 100644 (file)
@@ -12,6 +12,8 @@ package main
 import (
   "flag"
   "fmt"
+  "os"
+  "strings"
   "./config"
   "./paths"
   "./server"
@@ -28,6 +30,8 @@ func main() {
   var configuration = new(config.Configuration)
   fmt.Printf("Reading configuration from %v\n", *configPath)
   if len(*configPath) > 0 {
+    *configPath = strings.Replace(*configPath, "~", "$HOME", 1)
+    *configPath = os.ShellExpand(*configPath)
     error := config.ReadFromFile(*configPath, configuration)
     if error != nil {
       fmt.Printf("Error while reading configuration: %v\n", error)
@@ -42,6 +46,11 @@ func main() {
     configuration.Port = *port
   }
 
+  if configuration.Port == 0 {
+    fmt.Printf("Failed to start server (invalid port)\n")
+    os.Exit(1)
+  }
+
   // Run the server.
   fmt.Printf("Starting Armadillo on port %d with root:\n  %v\n",
       configuration.Port, configuration.JailRoot)