Skip to content

Commit ff32e99

Browse files
committed
main: doMount: call Setsid before starting logger
The logger should be in the new background session together with the gocryptfs process. Before: $ xfce4-terminal -x gocryptfs a b $ ps xao pid,ppid,pgid,sid,comm,args PID PPID PGID SID COMMAND COMMAND 192272 1371 192272 192272 gocryptfs /ssd2/jakob.donotbackup/go/bin/gocryptfs -fg -notifypid=192265 a b 192292 192272 192265 192265 logge <defunct> [logger] <defunct> After: $ xfce4-terminal -x gocryptfs a b $ ps xao pid,ppid,pgid,sid,comm,args PID PPID PGID SID COMMAND COMMAND 211714 1371 211714 211714 gocryptfs /ssd2/jakob.donotbackup/go/bin/gocryptfs -fg -notifypid=211708 a b 211776 211714 211714 211714 logger logger -t gocryptfs-211714-logger Fixes #660
1 parent 7ee4c8e commit ff32e99

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

mount.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,18 @@ func doMount(args *argContainer) {
120120
tlog.Info.Println(tlog.ColorGreen + "Filesystem mounted and ready." + tlog.ColorReset)
121121
// We have been forked into the background, as evidenced by the set
122122
// "notifypid".
123+
// Do what daemons should do: https://man7.org/linux/man-pages/man7/daemon.7.html
123124
if args.notifypid > 0 {
124125
// Chdir to the root directory so we don't block unmounting the CWD
125126
os.Chdir("/")
127+
// Disconnect from the controlling terminal by creating a new session.
128+
// This prevents us from getting SIGINT when the user presses Ctrl-C
129+
// to exit a running script that has called gocryptfs, or SIGHUP when
130+
// xfce4-terminal closes itself ( https://github.com/rfjakob/gocryptfs/issues/660 ).
131+
_, err = syscall.Setsid()
132+
if err != nil {
133+
tlog.Warn.Printf("Setsid: %v", err)
134+
}
126135
// Switch to syslog
127136
if !args.nosyslog {
128137
// Switch all of our logs and the generic logger to syslog
@@ -134,13 +143,6 @@ func doMount(args *argContainer) {
134143
// Daemons should redirect stdin, stdout and stderr
135144
redirectStdFds()
136145
}
137-
// Disconnect from the controlling terminal by creating a new session.
138-
// This prevents us from getting SIGINT when the user presses Ctrl-C
139-
// to exit a running script that has called gocryptfs.
140-
_, err = syscall.Setsid()
141-
if err != nil {
142-
tlog.Warn.Printf("Setsid: %v", err)
143-
}
144146
// Send SIGUSR1 to our parent
145147
sendUsr1(args.notifypid)
146148
}

0 commit comments

Comments
 (0)