aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--daemonize.go42
-rw-r--r--mount.go43
2 files changed, 42 insertions, 43 deletions
diff --git a/daemonize.go b/daemonize.go
index de09743..886a229 100644
--- a/daemonize.go
+++ b/daemonize.go
@@ -8,6 +8,7 @@ import (
"syscall"
"github.com/rfjakob/gocryptfs/internal/exitcodes"
+ "github.com/rfjakob/gocryptfs/internal/syscallcompat"
"github.com/rfjakob/gocryptfs/internal/tlog"
)
@@ -52,3 +53,44 @@ func forkChild() int {
// The child exited with 0 - let's do the same.
return 0
}
+
+// redirectStdFds redirects stderr and stdout to syslog; stdin to /dev/null
+func redirectStdFds() {
+ // stderr and stdout
+ pr, pw, err := os.Pipe()
+ if err != nil {
+ tlog.Warn.Printf("redirectStdFds: could not create pipe: %v\n", err)
+ return
+ }
+ tag := fmt.Sprintf("gocryptfs-%d-logger", os.Getpid())
+ cmd := exec.Command("logger", "-t", tag)
+ cmd.Stdout = os.Stdout
+ cmd.Stderr = os.Stderr
+ cmd.Stdin = pr
+ err = cmd.Start()
+ if err != nil {
+ tlog.Warn.Printf("redirectStdFds: could not start logger: %v\n", err)
+ }
+ pr.Close()
+ err = syscallcompat.Dup3(int(pw.Fd()), 1, 0)
+ if err != nil {
+ tlog.Warn.Printf("redirectStdFds: stdout dup error: %v\n", err)
+ }
+ syscallcompat.Dup3(int(pw.Fd()), 2, 0)
+ if err != nil {
+ tlog.Warn.Printf("redirectStdFds: stderr dup error: %v\n", err)
+ }
+ pw.Close()
+
+ // stdin
+ nullFd, err := os.Open("/dev/null")
+ if err != nil {
+ tlog.Warn.Printf("redirectStdFds: could not open /dev/null: %v\n", err)
+ return
+ }
+ err = syscallcompat.Dup3(int(nullFd.Fd()), 0, 0)
+ if err != nil {
+ tlog.Warn.Printf("redirectStdFds: stdin dup error: %v\n", err)
+ }
+ nullFd.Close()
+}
diff --git a/mount.go b/mount.go
index eed1b00..b8a7f72 100644
--- a/mount.go
+++ b/mount.go
@@ -2,7 +2,6 @@ package main
import (
"encoding/json"
- "fmt"
"log/syslog"
"net"
"os"
@@ -26,7 +25,6 @@ import (
"github.com/rfjakob/gocryptfs/internal/fusefrontend"
"github.com/rfjakob/gocryptfs/internal/fusefrontend_reverse"
"github.com/rfjakob/gocryptfs/internal/readpassword"
- "github.com/rfjakob/gocryptfs/internal/syscallcompat"
"github.com/rfjakob/gocryptfs/internal/tlog"
)
@@ -146,47 +144,6 @@ func doMount(args *argContainer) int {
return 0
}
-// redirectStdFds redirects stderr and stdout to syslog; stdin to /dev/null
-func redirectStdFds() {
- // stderr and stdout
- pr, pw, err := os.Pipe()
- if err != nil {
- tlog.Warn.Printf("redirectStdFds: could not create pipe: %v\n", err)
- return
- }
- tag := fmt.Sprintf("gocryptfs-%d-logger", os.Getpid())
- cmd := exec.Command("logger", "-t", tag)
- cmd.Stdout = os.Stdout
- cmd.Stderr = os.Stderr
- cmd.Stdin = pr
- err = cmd.Start()
- if err != nil {
- tlog.Warn.Printf("redirectStdFds: could not start logger: %v\n", err)
- }
- pr.Close()
- err = syscallcompat.Dup3(int(pw.Fd()), 1, 0)
- if err != nil {
- tlog.Warn.Printf("redirectStdFds: stdout dup error: %v\n", err)
- }
- syscallcompat.Dup3(int(pw.Fd()), 2, 0)
- if err != nil {
- tlog.Warn.Printf("redirectStdFds: stderr dup error: %v\n", err)
- }
- pw.Close()
-
- // stdin
- nullFd, err := os.Open("/dev/null")
- if err != nil {
- tlog.Warn.Printf("redirectStdFds: could not open /dev/null: %v\n", err)
- return
- }
- err = syscallcompat.Dup3(int(nullFd.Fd()), 0, 0)
- if err != nil {
- tlog.Warn.Printf("redirectStdFds: stdin dup error: %v\n", err)
- }
- nullFd.Close()
-}
-
// setOpenFileLimit tries to increase the open file limit to 4096 (the default hard
// limit on Linux).
func setOpenFileLimit() {