3636
3737const backgroundReadyTimeout = 15 * time .Second
3838
39+ func debugLogPath (mountpoint string ) string {
40+ dir , err := mountfs .StateFilePath (mountpoint )
41+ if err != nil || strings .TrimSpace (dir ) == "" {
42+ return ""
43+ }
44+ return strings .TrimSuffix (dir , filepath .Ext (dir )) + ".debug.log"
45+ }
46+
3947func Lsshfs () (app * cli.App ) {
4048 defConf := common .GetDefaultConfigPath ()
4149
@@ -235,6 +243,13 @@ func spawnBackgroundProcess(selectedHost string, appendHostFlag bool) error {
235243
236244 cmd := exec .Command (exe , args ... )
237245 cmd .Env = append (os .Environ (), "_LSSHFS_DAEMON=1" )
246+ if os .Getenv ("LSSHFS_DEBUG" ) == "1" {
247+ if len (args ) > 0 {
248+ if logPath := debugLogPath (args [len (args )- 1 ]); logPath != "" {
249+ cmd .Env = append (cmd .Env , "LSSHFS_DEBUG_LOG=" + logPath , "GO_SSHLIB_DEBUG_LOG=" + logPath )
250+ }
251+ }
252+ }
238253 if readyPath != "" {
239254 cmd .Env = append (cmd .Env , "_LSSHFS_READY_FILE=" + readyPath )
240255 }
@@ -268,6 +283,11 @@ func spawnBackgroundProcess(selectedHost string, appendHostFlag bool) error {
268283 _ = rpipe .Close ()
269284 if n > 0 {
270285 fmt .Fprintf (os .Stderr , "Mounted in background (pid %d)\n " , pid )
286+ if os .Getenv ("LSSHFS_DEBUG" ) == "1" && len (args ) > 0 {
287+ if logPath := debugLogPath (args [len (args )- 1 ]); logPath != "" {
288+ fmt .Fprintf (os .Stderr , "Debug log: %s\n " , logPath )
289+ }
290+ }
271291 os .Exit (0 )
272292 }
273293 return fmt .Errorf ("background start failed" )
@@ -278,6 +298,11 @@ func spawnBackgroundProcess(selectedHost string, appendHostFlag bool) error {
278298 }
279299
280300 fmt .Fprintf (os .Stderr , "Mounted in background (pid %d)\n " , pid )
301+ if os .Getenv ("LSSHFS_DEBUG" ) == "1" && len (args ) > 0 {
302+ if logPath := debugLogPath (args [len (args )- 1 ]); logPath != "" {
303+ fmt .Fprintf (os .Stderr , "Debug log: %s\n " , logPath )
304+ }
305+ }
281306 os .Exit (0 )
282307 return nil
283308}
0 commit comments