Package: golang-coreos-log / 0.0~git20140508-5

remove-osext Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
Author: Jelmer Vernooij <jelmer@debian.org>
Description: Remove dependency on bitbucket.org/kardianos/osext
  osext is not packaged in Debian.

diff --git a/log/logger.go b/log/logger.go
index 2089a11..82eacb1 100644
--- a/log/logger.go
+++ b/log/logger.go
@@ -17,12 +17,34 @@ package log
 // based on previous package by: Cong Ding <dinggnu@gmail.com>
 
 import (
-	"bitbucket.org/kardianos/osext"
+	"errors"
 	"os"
 	"path"
+	"path/filepath"
+	"runtime"
 	"time"
 )
 
+func executable() (string, error) {
+	switch runtime.GOOS {
+	case "linux":
+		return os.Readlink("/proc/self/exe")
+	case "netbsd":
+		return os.Readlink("/proc/curproc/exe")
+	case "openbsd":
+		return os.Readlink("/proc/curproc/file")
+	}
+	return "", errors.New("ExecPath not implemented for " + runtime.GOOS)
+}
+
+// Executable returns an absolute path that can be used to
+// re-invoke the current program.
+// It may not be valid after the current program exits.
+func Executable() (string, error) {
+	p, err := executable()
+	return filepath.Clean(p), err
+}
+
 // Logger is user-immutable immutable struct which can log to several outputs
 type Logger struct {
 	sinks   []Sink // the sinks this logger will log to
@@ -52,7 +74,7 @@ func New(prefix string, verbose bool, sinks ...Sink) *Logger {
 }
 
 func getExecutableName() string {
-	executablePath, err := osext.Executable()
+	executablePath, err := Executable()
 	if err != nil {
 		return "(UNKNOWN)"
 	} else {