Skip to content

cmd/syncthing: Use os.executable in monitor, only fallback to PATH - #8502

Merged
calmh merged 3 commits into
syncthing:mainfrom
imsodin:cmd/syncthing/executable
Aug 17, 2022
Merged

calmh merged 3 commits into
syncthing:mainfrom
imsodin:cmd/syncthing/executable

Conversation

@imsodin

@imsodin imsodin commented Aug 14, 2022

Copy link
Copy Markdown
Member

Use os.Executable regardless of OS and only fall back to PATH lookups if that fails (not sure why it ever would).

Followup for #8500 to be delayed until the next release as it's a behaviour change that warrants a full RC phase of testing (thus draft).

@tomasz1986

Copy link
Copy Markdown
Member

Not sure of the current state, but the compiled binary fails to run at all.

R:\syncthing\bin>syncthing.exe --home=test --no-browser --no-upgrade
[monitor] 2022/08/14 22:08:39 INFO: Log output saved to file "R:\syncthing\bin\test\syncthing.log"
[monitor] 2022/08/14 22:08:39 WARNING: Error starting the main Syncthing process: <nil>
panic: Error starting the main Syncthing process

goroutine 1 [running]:
main.monitorMain({{{0x0}, {0x0, 0x0}, {0xc000273ce0, 0x4}, 0x0, 0x0}, 0x0, 0x0, {0x0, ...}, ...})
        github.com/syncthing/syncthing/cmd/syncthing/monitor.go:89 +0x57c
main.serveOptions.Run({{{0x0}, {0x0, 0x0}, {0xc000273ce0, 0x4}, 0x0, 0x0}, 0x0, 0x0, {0x0, ...}, ...})
        github.com/syncthing/syncthing/cmd/syncthing/main.go:413 +0x8d8
reflect.Value.call({0xfff560?, 0x19bd8c0?, 0xe3251a?}, {0x100d687, 0x4}, {0xc000213b80, 0x0, 0x535948?})
        reflect/value.go:584 +0x8c5
reflect.Value.Call({0xfff560?, 0x19bd8c0?, 0xefe0a0?}, {0xc000213b80?, 0xe9d3c0?, 0x19bd982?})
        reflect/value.go:368 +0xbc
github.com/alecthomas/kong.callMethod({0x100d087, 0x3}, {0xfff560?, 0x19bd8c0?, 0x3?}, {0xfff560?, 0x19bd8c0?, 0x0?}, 0x0?)
        github.com/alecthomas/[email protected]/callbacks.go:95 +0x549
github.com/alecthomas/kong.(*Context).RunNode(0xc000112d80, 0xc0002422d0, {0x0, 0x0, 0x0})
        github.com/alecthomas/[email protected]/context.go:734 +0x5f7
github.com/alecthomas/kong.(*Context).Run(0xe8e540?, {0x0?, 0x0?, 0x0?})
        github.com/alecthomas/[email protected]/context.go:759 +0x14e
main.main()
        github.com/syncthing/syncthing/cmd/syncthing/main.go:255 +0x3a5

goroutine 19 [chan receive]:
github.com/syncthing/notify.(*recursiveTree).dispatch(0xc0000e2780)
        github.com/syncthing/[email protected]/tree_recursive.go:125 +0x48
created by github.com/syncthing/notify.newRecursiveTree
        github.com/syncthing/[email protected]/tree_recursive.go:119 +0x165

goroutine 20 [sleep]:
time.Sleep(0x1dcd6500)
        runtime/time.go:195 +0x13c
github.com/syncthing/syncthing/lib/dialer.init.0.func2()
        github.com/syncthing/syncthing/lib/dialer/internal.go:43 +0x1e
created by github.com/syncthing/syncthing/lib/dialer.init.0
        github.com/syncthing/syncthing/lib/dialer/internal.go:42 +0xbe

goroutine 21 [select]:
main.(*autoclosedFile).closerLoop(0xc0002a8000)
        github.com/syncthing/syncthing/cmd/syncthing/monitor.go:546 +0x71
created by main.newAutoclosedFile
        github.com/syncthing/syncthing/cmd/syncthing/monitor.go:486 +0x1e5

Comment thread cmd/syncthing/monitor.go Resolved
Comment thread cmd/syncthing/monitor.go Outdated
// name (like e.g. "syncthing")
if !strings.ContainsRune(args0, os.PathSeparator) {
// Check if it's in PATH
e = "." + string(os.PathSeparator) + args0

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think we should skip this entire thing, os.Executable() + exec.LookPath() should cover the reasonable scenarios imho. At least I don't see the scenario where it would be required or useful to also look separately in pwd, so despite not seeing how this would cause a problem by itself I don't think we should do it...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, done. My thinking was that os.Executable should anyway work all the time, but we want to try everything we can to get an executable. I guess we could even get rid of the LookupPath and just do os.Executable and fail if it returns an error?

@calmh

calmh commented Aug 15, 2022

Copy link
Copy Markdown
Member

@tomasz1986 there was a merge error or something which I fixed

@calmh calmh left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks reasonable to me; I've done zero testing of it. :)

@tomasz1986

Copy link
Copy Markdown
Member

It seems to run fine on Windows 👍.

@calmh
calmh marked this pull request as ready for review August 17, 2022 06:57
@calmh
calmh merged commit 6dedffe into syncthing:main Aug 17, 2022
calmh added a commit to calmh/syncthing that referenced this pull request Aug 17, 2022
* main:
  cmd/syncthing: Use os.executable in monitor, only fallback to PATH (syncthing#8502)
  all: Modernize error wrapping (syncthing#8491)
  gui, man, authors: Update docs, translations, and contributors
  cmd/syncthing: Work around binary in current dir restriction (fixes syncthing#8499) (syncthing#8500)
  lib/fs: Cache user lookups (syncthing#8496)
  all: Make scanning ownership opt-in (syncthing#8497)
@imsodin
imsodin deleted the cmd/syncthing/executable branch August 17, 2022 12:22
calmh added a commit to calmh/syncthing that referenced this pull request Aug 18, 2022
* main: (256 commits)
  cmd/syncthing: Use os.executable in monitor, only fallback to PATH (syncthing#8502)
  all: Modernize error wrapping (syncthing#8491)
  gui, man, authors: Update docs, translations, and contributors
  cmd/syncthing: Work around binary in current dir restriction (fixes syncthing#8499) (syncthing#8500)
  lib/fs: Cache user lookups (syncthing#8496)
  all: Make scanning ownership opt-in (syncthing#8497)
  lib/model: Skip paused folders in aggregated completion loop (fixes syncthing#8219) (syncthing#8220)
  gui: Remove unused strings from translations (syncthing#8288)
  gui, api: Show internal config and state paths (fixes syncthing#8323) (syncthing#8324)
  build(deps): bump github.com/go-ldap/ldap/v3 from 3.4.1 to 3.4.4 (syncthing#8475)
  build: bump actions/setup-go from 2.2.0 to 3.2.1 (syncthing#8492)
  build: Let dependabot suggest updates to GitHub actions (syncthing#8490)
  update: Go version in update-docs-translations action (syncthing#8489)
  gui, man, authors: Update docs, translations, and contributors
  cmd/syncthing: Refactor CLI code to allow passing CLI arguments via function parameter (syncthing#8485)
  build: Update quic-go for Go 1.19 (syncthing#8483)
  lib/ur: Properly initialize map in failure data (fixes syncthing#8479) (syncthing#8480)
  lib/ur: Properly initialize map in failure data (fixes syncthing#8479)
  gui, man, authors: Update docs, translations, and contributors
  docs: Clarify docker network mode limitations (syncthing#8472)
  ...
@calmh calmh added this to the v1.22.0 milestone Sep 14, 2022
@st-review st-review added the frozen-due-to-age Issues closed and untouched for a long time, together with being locked for discussion label Aug 17, 2023
@syncthing syncthing locked and limited conversation to collaborators Aug 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

frozen-due-to-age Issues closed and untouched for a long time, together with being locked for discussion

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants