Skip to content

Commit bd1f56c

Browse files
committed
Merge pull request #6 from paulhammond/file_args2
File args
2 parents 0922dbb + c66b23a commit bd1f56c

File tree

4 files changed

+30
-4
lines changed

4 files changed

+30
-4
lines changed

config_manager.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ type ConfigFile struct {
3636
}
3737

3838
type ConfigManager struct {
39-
Config ConfigFile
40-
Flags struct {
39+
Config ConfigFile
40+
FlagFiles []string
41+
Flags struct {
4142
Hostname string
4243
DestHost string
4344
DestPort int
@@ -169,6 +170,7 @@ func (cm *ConfigManager) parseFlags() {
169170
pflag.StringVar(&cm.Flags.DebugLogFile, "debug-log-cfg", "", "the debug log file")
170171
pflag.StringVar(&cm.Flags.LogLevels, "log", "<root>=INFO", "\"logging configuration <root>=INFO;first=TRACE\"")
171172
pflag.Parse()
173+
cm.FlagFiles = pflag.Args()
172174
}
173175

174176
func (cm *ConfigManager) readConfig() error {
@@ -276,7 +278,7 @@ func (cm *ConfigManager) Facility() syslog.Priority {
276278
}
277279

278280
func (cm *ConfigManager) Files() []string {
279-
return cm.Config.Files
281+
return append(cm.FlagFiles, cm.Config.Files...)
280282
}
281283

282284
func (cm *ConfigManager) DebugLogFile() string {

remote_syslog.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func globFiles(globs []string, excludedFiles []*regexp.Regexp, excludePatterns [
6868
log.Debugf("Evaluating file globs")
6969
for _, glob := range globs {
7070

71-
files, err := filepath.Glob(glob)
71+
files, err := filepath.Glob(utils.ResolvePath(glob))
7272

7373
if err != nil {
7474
log.Errorf("Failed to glob %s: %s", glob, err)

utils/daemonize.go

+20
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,34 @@ import (
66
"fmt"
77
"io"
88
"os"
9+
"path/filepath"
910

1011
"github.com/VividCortex/godaemon"
1112
"github.com/nightlyone/lockfile"
1213
)
1314

1415
const CanDaemonize = true
1516

17+
func ResolvePath(path string) string {
18+
19+
if filepath.IsAbs(path) {
20+
return path
21+
}
22+
23+
return filepath.Join(os.Getenv("__DAEMON_CWD"), path)
24+
}
25+
1626
func Daemonize(logFilePath, pidFilePath string) {
27+
28+
if os.Getenv("__DAEMON_CWD") == "" {
29+
cwd, err := os.Getwd()
30+
if err != nil {
31+
fmt.Fprintln(os.Stderr, "Cannot determine working directory: %v", err)
32+
os.Exit(1)
33+
}
34+
os.Setenv("__DAEMON_CWD", cwd)
35+
}
36+
1737
logFile, err := os.OpenFile(logFilePath, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0666)
1838
if err != nil {
1939
fmt.Fprintln(os.Stderr, "Could not open local log file: %v", err)

utils/daemonize_windows.go

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ package utils
22

33
const CanDaemonize = false
44

5+
func ResolvePath(path string) string {
6+
return path
7+
}
8+
59
func Daemonize(logFilePath, pidFilePath string) {
610
panic("cannot daemonize on windows")
711
}

0 commit comments

Comments
 (0)