aboutsummaryrefslogtreecommitdiff
path: root/daemonize.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2016-01-20 22:31:15 +0100
committerJakob Unterwurzacher2016-01-20 22:31:15 +0100
commit9bab220a1b5a10c00c314b15f4c9f879f1473707 (patch)
tree14ca1e3ed4bfd33d3721db79065d64f418219aa3 /daemonize.go
parent17f0eb13396ad31083e786ed64aef368646c2aa6 (diff)
Switch to syslog when running in the background
Diffstat (limited to 'daemonize.go')
-rw-r--r--daemonize.go17
1 files changed, 15 insertions, 2 deletions
diff --git a/daemonize.go b/daemonize.go
index a65bd11..7d00288 100644
--- a/daemonize.go
+++ b/daemonize.go
@@ -2,10 +2,14 @@ package main
import (
"fmt"
+ "log"
+ "log/syslog"
"os"
"os/exec"
"os/signal"
"syscall"
+
+ "github.com/rfjakob/gocryptfs/cryptfs"
)
// The child sends us USR1 if the mount was successful
@@ -22,8 +26,7 @@ func exitOnUsr1() {
func forkChild() {
go exitOnUsr1()
name := os.Args[0]
- notifyArg := fmt.Sprintf("-notifypid=%d", os.Getpid())
- newArgs := []string{"-f", notifyArg}
+ newArgs := []string{"-f", fmt.Sprintf("-notifypid=%d", os.Getpid())}
newArgs = append(newArgs, os.Args[1:]...)
c := exec.Command(name, newArgs...)
c.Stdout = os.Stdout
@@ -47,3 +50,13 @@ func forkChild() {
// The child exited with 0 - let's do the same.
os.Exit(0)
}
+
+// Switch one Logger to syslog
+func switchToSyslog(l *log.Logger, p syslog.Priority) {
+ w, err := syslog.New(p, PROGRAM_NAME)
+ if err != nil {
+ cryptfs.Warn.Printf("Cannot switch 0x%02x to syslog: %v", p, err)
+ } else {
+ l.SetOutput(w)
+ }
+}